aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Accounts
diff options
context:
space:
mode:
authorFaraz Samapoor <f.samapoor@gmail.com>2023-06-24 12:46:40 +0330
committerFaraz Samapoor <fsa@adlas.at>2023-07-01 13:57:46 +0330
commited972439fc40f1ef800e7fbb8ce6e900610850d9 (patch)
treee1d8f892fa0f8c1a078b1d10d6f75da85fccc302 /lib/private/Accounts
parent2584786f31818dc98fc36015efcb16c5ccafcb10 (diff)
downloadnextcloud-server-ed972439fc40f1ef800e7fbb8ce6e900610850d9.tar.gz
nextcloud-server-ed972439fc40f1ef800e7fbb8ce6e900610850d9.zip
Refactors lib/private/Accounts.
Mainly using PHP8's constructor property promotion. Signed-off-by: Faraz Samapoor <fsa@adlas.at>
Diffstat (limited to 'lib/private/Accounts')
-rw-r--r--lib/private/Accounts/Account.php10
-rw-r--r--lib/private/Accounts/AccountManager.php90
-rw-r--r--lib/private/Accounts/AccountProperty.php62
-rw-r--r--lib/private/Accounts/AccountPropertyCollection.php10
-rw-r--r--lib/private/Accounts/Hooks.php12
5 files changed, 46 insertions, 138 deletions
diff --git a/lib/private/Accounts/Account.php b/lib/private/Accounts/Account.php
index d3287b219d0..22bbe3d11a0 100644
--- a/lib/private/Accounts/Account.php
+++ b/lib/private/Accounts/Account.php
@@ -39,13 +39,11 @@ class Account implements IAccount {
use TAccountsHelper;
/** @var IAccountPropertyCollection[]|IAccountProperty[] */
- private $properties = [];
+ private array $properties = [];
- /** @var IUser */
- private $user;
-
- public function __construct(IUser $user) {
- $this->user = $user;
+ public function __construct(
+ private IUser $user,
+ ) {
}
public function setProperty(string $property, string $value, string $scope, string $verified, string $verificationData = ''): IAccount {
diff --git a/lib/private/Accounts/AccountManager.php b/lib/private/Accounts/AccountManager.php
index e3068a7ff25..8d7938e5e2f 100644
--- a/lib/private/Accounts/AccountManager.php
+++ b/lib/private/Accounts/AccountManager.php
@@ -83,40 +83,9 @@ class AccountManager implements IAccountManager {
use TProfileHelper;
- /** @var IDBConnection database connection */
- private $connection;
-
- /** @var IConfig */
- private $config;
-
- /** @var string table name */
- private $table = 'accounts';
-
- /** @var string table name */
- private $dataTable = 'accounts_data';
-
- /** @var EventDispatcherInterface */
- private $eventDispatcher;
-
- /** @var IJobList */
- private $jobList;
-
- /** @var LoggerInterface */
- private $logger;
- /** @var IVerificationToken */
- private $verificationToken;
- /** @var IMailer */
- private $mailer;
- /** @var Defaults */
- private $defaults;
- /** @var IL10N */
- private $l10n;
- /** @var IURLGenerator */
- private $urlGenerator;
- /** @var ICrypto */
- private $crypto;
- /** @var IFactory */
- private $l10nfactory;
+ private string $table = 'accounts';
+ private string $dataTable = 'accounts_data';
+ private IL10N $l10n;
private CappedMemoryCache $internalCache;
/**
@@ -138,35 +107,22 @@ class AccountManager implements IAccountManager {
];
public function __construct(
- IDBConnection $connection,
- IConfig $config,
- EventDispatcherInterface $eventDispatcher,
- IJobList $jobList,
- LoggerInterface $logger,
- IVerificationToken $verificationToken,
- IMailer $mailer,
- Defaults $defaults,
- IFactory $factory,
- IURLGenerator $urlGenerator,
- ICrypto $crypto
+ private IDBConnection $connection,
+ private IConfig $config,
+ private EventDispatcherInterface $eventDispatcher,
+ private IJobList $jobList,
+ private LoggerInterface $logger,
+ private IVerificationToken $verificationToken,
+ private IMailer $mailer,
+ private Defaults $defaults,
+ private IFactory $factory,
+ private IURLGenerator $urlGenerator,
+ private ICrypto $crypto,
) {
- $this->connection = $connection;
- $this->config = $config;
- $this->eventDispatcher = $eventDispatcher;
- $this->jobList = $jobList;
- $this->logger = $logger;
- $this->verificationToken = $verificationToken;
- $this->mailer = $mailer;
- $this->defaults = $defaults;
- $this->urlGenerator = $urlGenerator;
- $this->crypto = $crypto;
- // DIing IL10N results in a dependency loop
- $this->l10nfactory = $factory;
$this->internalCache = new CappedMemoryCache();
}
/**
- * @param string $input
* @return string Provided phone number in E.164 format when it was a valid number
* @throws InvalidArgumentException When the phone number was invalid or no default region is set and the number doesn't start with a country code
*/
@@ -195,9 +151,6 @@ class AccountManager implements IAccountManager {
}
/**
- *
- * @param string $input
- * @return string
* @throws InvalidArgumentException When the website did not have http(s) as protocol or the host name was empty
*/
protected function parseWebsite(string $input): string {
@@ -251,7 +204,7 @@ class AccountManager implements IAccountManager {
}
}
- protected function sanitizePhoneNumberValue(IAccountProperty $property, bool $throwOnData = false) {
+ protected function sanitizePhoneNumberValue(IAccountProperty $property, bool $throwOnData = false): void {
if ($property->getName() !== self::PROPERTY_PHONE) {
if ($throwOnData) {
throw new InvalidArgumentException(sprintf('sanitizePhoneNumberValue can only sanitize phone numbers, %s given', $property->getName()));
@@ -271,7 +224,7 @@ class AccountManager implements IAccountManager {
}
}
- protected function sanitizeWebsite(IAccountProperty $property, bool $throwOnData = false) {
+ protected function sanitizeWebsite(IAccountProperty $property, bool $throwOnData = false): void {
if ($property->getName() !== self::PROPERTY_WEBSITE) {
if ($throwOnData) {
throw new InvalidArgumentException(sprintf('sanitizeWebsite can only sanitize web domains, %s given', $property->getName()));
@@ -313,10 +266,8 @@ class AccountManager implements IAccountManager {
/**
* delete user from accounts table
- *
- * @param IUser $user
*/
- public function deleteUser(IUser $user) {
+ public function deleteUser(IUser $user): void {
$uid = $user->getUID();
$query = $this->connection->getQueryBuilder();
$query->delete($this->table)
@@ -328,8 +279,6 @@ class AccountManager implements IAccountManager {
/**
* delete user from accounts table
- *
- * @param IUser $user
*/
public function deleteUserData(IUser $user): void {
$uid = $user->getUID();
@@ -467,7 +416,7 @@ class AccountManager implements IAccountManager {
]);
if (!$this->l10n) {
- $this->l10n = $this->l10nfactory->get('core');
+ $this->l10n = $this->factory->get('core');
}
$emailTemplate->setSubject($this->l10n->t('%s email verification', [$this->defaults->getName()]));
@@ -552,9 +501,6 @@ class AccountManager implements IAccountManager {
/**
* add new user to accounts table
- *
- * @param IUser $user
- * @param array $data
*/
protected function insertNewUser(IUser $user, array $data): void {
$uid = $user->getUID();
diff --git a/lib/private/Accounts/AccountProperty.php b/lib/private/Accounts/AccountProperty.php
index 2023d185a4b..207dc1d139d 100644
--- a/lib/private/Accounts/AccountProperty.php
+++ b/lib/private/Accounts/AccountProperty.php
@@ -32,25 +32,17 @@ use OCP\Accounts\IAccountManager;
use OCP\Accounts\IAccountProperty;
class AccountProperty implements IAccountProperty {
- /** @var string */
- private $name;
- /** @var string */
- private $value;
- /** @var string */
- private $scope;
- /** @var string */
- private $verified;
- /** @var string */
- private $verificationData;
- /** @var string */
- private $locallyVerified = IAccountManager::NOT_VERIFIED;
-
- public function __construct(string $name, string $value, string $scope, string $verified, string $verificationData) {
- $this->name = $name;
- $this->value = $value;
+ private string $scope;
+ private string $locallyVerified = IAccountManager::NOT_VERIFIED;
+
+ public function __construct(
+ private string $name,
+ private string $value,
+ string $scope,
+ private string $verified,
+ private string $verificationData,
+ ) {
$this->setScope($scope);
- $this->verified = $verified;
- $this->verificationData = $verificationData;
}
public function jsonSerialize(): array {
@@ -67,9 +59,6 @@ class AccountProperty implements IAccountProperty {
* Set the value of a property
*
* @since 15.0.0
- *
- * @param string $value
- * @return IAccountProperty
*/
public function setValue(string $value): IAccountProperty {
$this->value = $value;
@@ -80,9 +69,6 @@ class AccountProperty implements IAccountProperty {
* Set the scope of a property
*
* @since 15.0.0
- *
- * @param string $scope
- * @return IAccountProperty
*/
public function setScope(string $scope): IAccountProperty {
$newScope = $this->mapScopeToV2($scope);
@@ -102,9 +88,6 @@ class AccountProperty implements IAccountProperty {
* Set the verification status of a property
*
* @since 15.0.0
- *
- * @param string $verified
- * @return IAccountProperty
*/
public function setVerified(string $verified): IAccountProperty {
$this->verified = $verified;
@@ -115,8 +98,6 @@ class AccountProperty implements IAccountProperty {
* Get the name of a property
*
* @since 15.0.0
- *
- * @return string
*/
public function getName(): string {
return $this->name;
@@ -126,8 +107,6 @@ class AccountProperty implements IAccountProperty {
* Get the value of a property
*
* @since 15.0.0
- *
- * @return string
*/
public function getValue(): string {
return $this->value;
@@ -137,8 +116,6 @@ class AccountProperty implements IAccountProperty {
* Get the scope of a property
*
* @since 15.0.0
- *
- * @return string
*/
public function getScope(): string {
return $this->scope;
@@ -149,25 +126,18 @@ class AccountProperty implements IAccountProperty {
return $scope;
}
- switch ($scope) {
- case IAccountManager::VISIBILITY_PRIVATE:
- case '':
- return IAccountManager::SCOPE_LOCAL;
- case IAccountManager::VISIBILITY_CONTACTS_ONLY:
- return IAccountManager::SCOPE_FEDERATED;
- case IAccountManager::VISIBILITY_PUBLIC:
- return IAccountManager::SCOPE_PUBLISHED;
- default:
- return $scope;
- }
+ return match ($scope) {
+ IAccountManager::VISIBILITY_PRIVATE, '' => IAccountManager::SCOPE_LOCAL,
+ IAccountManager::VISIBILITY_CONTACTS_ONLY => IAccountManager::SCOPE_FEDERATED,
+ IAccountManager::VISIBILITY_PUBLIC => IAccountManager::SCOPE_PUBLISHED,
+ default => $scope,
+ };
}
/**
* Get the verification status of a property
*
* @since 15.0.0
- *
- * @return string
*/
public function getVerified(): string {
return $this->verified;
diff --git a/lib/private/Accounts/AccountPropertyCollection.php b/lib/private/Accounts/AccountPropertyCollection.php
index 1e5d8a5112a..660a245714d 100644
--- a/lib/private/Accounts/AccountPropertyCollection.php
+++ b/lib/private/Accounts/AccountPropertyCollection.php
@@ -32,14 +32,12 @@ use OCP\Accounts\IAccountProperty;
use OCP\Accounts\IAccountPropertyCollection;
class AccountPropertyCollection implements IAccountPropertyCollection {
- /** @var string */
- protected $collectionName = '';
-
/** @var IAccountProperty[] */
- protected $properties = [];
+ protected array $properties = [];
- public function __construct(string $collectionName) {
- $this->collectionName = $collectionName;
+ public function __construct(
+ protected string $collectionName,
+ ) {
}
public function setProperties(array $properties): IAccountPropertyCollection {
diff --git a/lib/private/Accounts/Hooks.php b/lib/private/Accounts/Hooks.php
index a6c52275d2d..b449c41c1da 100644
--- a/lib/private/Accounts/Hooks.php
+++ b/lib/private/Accounts/Hooks.php
@@ -36,14 +36,10 @@ use Psr\Log\LoggerInterface;
* @template-implements IEventListener<UserChangedEvent>
*/
class Hooks implements IEventListener {
- /** @var IAccountManager */
- private $accountManager;
- /** @var LoggerInterface */
- private $logger;
-
- public function __construct(LoggerInterface $logger, IAccountManager $accountManager) {
- $this->logger = $logger;
- $this->accountManager = $accountManager;
+ public function __construct(
+ private LoggerInterface $logger,
+ private IAccountManager $accountManager,
+ ) {
}
/**