From 84749d53a9d633133bf734946e76c3d178b6c6c2 Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Tue, 11 Jul 2023 10:48:17 +0330 Subject: [PATCH 1/4] Refactor lib/private/App Signed-off-by: Hamid Dehnavi --- lib/private/App/AppManager.php | 31 ++++++------------- lib/private/App/AppStore/Bundles/Bundle.php | 7 ++--- .../App/AppStore/Bundles/BundleFetcher.php | 7 +++-- .../App/AppStore/Fetcher/AppFetcher.php | 5 +-- .../App/AppStore/Fetcher/CategoryFetcher.php | 6 ++-- lib/private/App/AppStore/Fetcher/Fetcher.php | 29 +++++------------ lib/private/App/AppStore/Version/Version.php | 11 +++---- lib/private/App/DependencyAnalyzer.php | 11 +++---- lib/private/App/InfoParser.php | 7 ++--- lib/private/App/Platform.php | 6 ++-- 10 files changed, 43 insertions(+), 77 deletions(-) diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index 60e55a314d6cf..5eeb7ef1fbd31 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -74,14 +74,6 @@ class AppManager implements IAppManager { 'prevent_group_restriction', ]; - private IUserSession $userSession; - private IConfig $config; - private AppConfig $appConfig; - private IGroupManager $groupManager; - private ICacheFactory $memCacheFactory; - private IEventDispatcher $dispatcher; - private LoggerInterface $logger; - /** @var string[] $appId => $enabled */ private array $installedAppsCache = []; @@ -104,20 +96,15 @@ class AppManager implements IAppManager { /** @var array */ private array $loadedApps = []; - public function __construct(IUserSession $userSession, - IConfig $config, - AppConfig $appConfig, - IGroupManager $groupManager, - ICacheFactory $memCacheFactory, - IEventDispatcher $dispatcher, - LoggerInterface $logger) { - $this->userSession = $userSession; - $this->config = $config; - $this->appConfig = $appConfig; - $this->groupManager = $groupManager; - $this->memCacheFactory = $memCacheFactory; - $this->dispatcher = $dispatcher; - $this->logger = $logger; + public function __construct( + private IUserSession $userSession, + private IConfig $config, + private AppConfig $appConfig, + private IGroupManager $groupManager, + private ICacheFactory $memCacheFactory, + private IEventDispatcher $dispatcher, + private LoggerInterface $logger, + ) { } /** diff --git a/lib/private/App/AppStore/Bundles/Bundle.php b/lib/private/App/AppStore/Bundles/Bundle.php index dfc93fdfaa2e4..750ea5a41e3ef 100644 --- a/lib/private/App/AppStore/Bundles/Bundle.php +++ b/lib/private/App/AppStore/Bundles/Bundle.php @@ -26,14 +26,13 @@ use OCP\IL10N; abstract class Bundle { - /** @var IL10N */ - protected $l10n; /** * @param IL10N $l10n */ - public function __construct(IL10N $l10n) { - $this->l10n = $l10n; + public function __construct( + protected IL10N $l10n, + ) { } /** diff --git a/lib/private/App/AppStore/Bundles/BundleFetcher.php b/lib/private/App/AppStore/Bundles/BundleFetcher.php index 0d2bb61495ff8..a2ce89f28af0f 100644 --- a/lib/private/App/AppStore/Bundles/BundleFetcher.php +++ b/lib/private/App/AppStore/Bundles/BundleFetcher.php @@ -27,10 +27,11 @@ use OCP\IL10N; class BundleFetcher { - private IL10N $l10n; - public function __construct(IL10N $l10n) { - $this->l10n = $l10n; + public function __construct + ( + private IL10N $l10n, + ) { } /** diff --git a/lib/private/App/AppStore/Fetcher/AppFetcher.php b/lib/private/App/AppStore/Fetcher/AppFetcher.php index f9fbd05855b8d..7a7d2f2906d2b 100644 --- a/lib/private/App/AppStore/Fetcher/AppFetcher.php +++ b/lib/private/App/AppStore/Fetcher/AppFetcher.php @@ -39,11 +39,9 @@ use Psr\Log\LoggerInterface; class AppFetcher extends Fetcher { - /** @var CompareVersion */ - private $compareVersion; /** @var IRegistry */ - protected $registry; + protected IRegistry $registry; /** @var bool */ private $ignoreMaxVersion; @@ -64,7 +62,6 @@ public function __construct(Factory $appDataFactory, $registry ); - $this->compareVersion = $compareVersion; $this->registry = $registry; $this->fileName = 'apps.json'; diff --git a/lib/private/App/AppStore/Fetcher/CategoryFetcher.php b/lib/private/App/AppStore/Fetcher/CategoryFetcher.php index d1bbe4f7b0434..9b84d2a619667 100644 --- a/lib/private/App/AppStore/Fetcher/CategoryFetcher.php +++ b/lib/private/App/AppStore/Fetcher/CategoryFetcher.php @@ -34,12 +34,14 @@ use Psr\Log\LoggerInterface; class CategoryFetcher extends Fetcher { - public function __construct(Factory $appDataFactory, + public function __construct( + Factory $appDataFactory, IClientService $clientService, ITimeFactory $timeFactory, IConfig $config, LoggerInterface $logger, - IRegistry $registry) { + IRegistry $registry, + ) { parent::__construct( $appDataFactory, $clientService, diff --git a/lib/private/App/AppStore/Fetcher/Fetcher.php b/lib/private/App/AppStore/Fetcher/Fetcher.php index a693804f50fbb..3fc5fd07573ba 100644 --- a/lib/private/App/AppStore/Fetcher/Fetcher.php +++ b/lib/private/App/AppStore/Fetcher/Fetcher.php @@ -47,16 +47,6 @@ abstract class Fetcher { /** @var IAppData */ protected $appData; - /** @var IClientService */ - protected $clientService; - /** @var ITimeFactory */ - protected $timeFactory; - /** @var IConfig */ - protected $config; - /** @var LoggerInterface */ - protected $logger; - /** @var IRegistry */ - protected $registry; /** @var string */ protected $fileName; @@ -67,18 +57,15 @@ abstract class Fetcher { /** @var ?string */ protected $channel = null; - public function __construct(Factory $appDataFactory, - IClientService $clientService, - ITimeFactory $timeFactory, - IConfig $config, - LoggerInterface $logger, - IRegistry $registry) { + public function __construct( + Factory $appDataFactory, + protected IClientService $clientService, + protected ITimeFactory $timeFactory, + protected IConfig $config, + protected LoggerInterface $logger, + protected IRegistry $registry, + ) { $this->appData = $appDataFactory->get('appstore'); - $this->clientService = $clientService; - $this->timeFactory = $timeFactory; - $this->config = $config; - $this->logger = $logger; - $this->registry = $registry; } /** diff --git a/lib/private/App/AppStore/Version/Version.php b/lib/private/App/AppStore/Version/Version.php index d41ca1770f056..bcdae1984cf00 100644 --- a/lib/private/App/AppStore/Version/Version.php +++ b/lib/private/App/AppStore/Version/Version.php @@ -23,18 +23,15 @@ namespace OC\App\AppStore\Version; class Version { - /** @var string */ - private $minVersion; - /** @var string */ - private $maxVersion; /** * @param string $minVersion * @param string $maxVersion */ - public function __construct($minVersion, $maxVersion) { - $this->minVersion = $minVersion; - $this->maxVersion = $maxVersion; + public function __construct( + private string $minVersion, + private string $maxVersion, + ) { } /** diff --git a/lib/private/App/DependencyAnalyzer.php b/lib/private/App/DependencyAnalyzer.php index 3bdc551ea5afa..2974e31dc5d0d 100644 --- a/lib/private/App/DependencyAnalyzer.php +++ b/lib/private/App/DependencyAnalyzer.php @@ -33,10 +33,6 @@ use OCP\IL10N; class DependencyAnalyzer { - /** @var Platform */ - private $platform; - /** @var \OCP\IL10N */ - private $l; /** @var array */ private $appInfo; @@ -44,9 +40,10 @@ class DependencyAnalyzer { * @param Platform $platform * @param \OCP\IL10N $l */ - public function __construct(Platform $platform, IL10N $l) { - $this->platform = $platform; - $this->l = $l; + public function __construct( + private Platform $platform, + private IL10N $l, + ) { } /** diff --git a/lib/private/App/InfoParser.php b/lib/private/App/InfoParser.php index 79d051fd2a1f6..1efb0071bd30e 100644 --- a/lib/private/App/InfoParser.php +++ b/lib/private/App/InfoParser.php @@ -34,14 +34,13 @@ use function simplexml_load_string; class InfoParser { - /** @var \OCP\ICache|null */ - private $cache; /** * @param ICache|null $cache */ - public function __construct(ICache $cache = null) { - $this->cache = $cache; + public function __construct( + private ?ICache $cache = null, + ) { } /** diff --git a/lib/private/App/Platform.php b/lib/private/App/Platform.php index daff247d1bd7d..3631a3d1cb93d 100644 --- a/lib/private/App/Platform.php +++ b/lib/private/App/Platform.php @@ -36,10 +36,10 @@ * @package OC\App */ class Platform { - private IConfig $config; - public function __construct(IConfig $config) { - $this->config = $config; + public function __construct( + private IConfig $config, + ) { } public function getPhpVersion(): string { From 7a8d79b85cd77e77cc9e39a047cb5fd2bd26a32b Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Tue, 11 Jul 2023 11:24:01 +0330 Subject: [PATCH 2/4] Fix code style Signed-off-by: Hamid Dehnavi --- lib/private/App/AppStore/Bundles/Bundle.php | 1 - lib/private/App/AppStore/Bundles/BundleFetcher.php | 4 +--- lib/private/App/AppStore/Fetcher/AppFetcher.php | 1 - lib/private/App/AppStore/Version/Version.php | 1 - lib/private/App/InfoParser.php | 1 - lib/private/App/Platform.php | 1 - 6 files changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/private/App/AppStore/Bundles/Bundle.php b/lib/private/App/AppStore/Bundles/Bundle.php index 750ea5a41e3ef..fb86edff55981 100644 --- a/lib/private/App/AppStore/Bundles/Bundle.php +++ b/lib/private/App/AppStore/Bundles/Bundle.php @@ -26,7 +26,6 @@ use OCP\IL10N; abstract class Bundle { - /** * @param IL10N $l10n */ diff --git a/lib/private/App/AppStore/Bundles/BundleFetcher.php b/lib/private/App/AppStore/Bundles/BundleFetcher.php index a2ce89f28af0f..7ac70591e8aee 100644 --- a/lib/private/App/AppStore/Bundles/BundleFetcher.php +++ b/lib/private/App/AppStore/Bundles/BundleFetcher.php @@ -27,9 +27,7 @@ use OCP\IL10N; class BundleFetcher { - - public function __construct - ( + public function __construct( private IL10N $l10n, ) { } diff --git a/lib/private/App/AppStore/Fetcher/AppFetcher.php b/lib/private/App/AppStore/Fetcher/AppFetcher.php index 7a7d2f2906d2b..7f98617d822c0 100644 --- a/lib/private/App/AppStore/Fetcher/AppFetcher.php +++ b/lib/private/App/AppStore/Fetcher/AppFetcher.php @@ -39,7 +39,6 @@ use Psr\Log\LoggerInterface; class AppFetcher extends Fetcher { - /** @var IRegistry */ protected IRegistry $registry; diff --git a/lib/private/App/AppStore/Version/Version.php b/lib/private/App/AppStore/Version/Version.php index bcdae1984cf00..5bd0226528f33 100644 --- a/lib/private/App/AppStore/Version/Version.php +++ b/lib/private/App/AppStore/Version/Version.php @@ -23,7 +23,6 @@ namespace OC\App\AppStore\Version; class Version { - /** * @param string $minVersion * @param string $maxVersion diff --git a/lib/private/App/InfoParser.php b/lib/private/App/InfoParser.php index 1efb0071bd30e..2461d587bbdf5 100644 --- a/lib/private/App/InfoParser.php +++ b/lib/private/App/InfoParser.php @@ -34,7 +34,6 @@ use function simplexml_load_string; class InfoParser { - /** * @param ICache|null $cache */ diff --git a/lib/private/App/Platform.php b/lib/private/App/Platform.php index 3631a3d1cb93d..c5565e9e0c253 100644 --- a/lib/private/App/Platform.php +++ b/lib/private/App/Platform.php @@ -36,7 +36,6 @@ * @package OC\App */ class Platform { - public function __construct( private IConfig $config, ) { From b6ef67edfc2cb6b69340d96b15a342dfa8b5bd2c Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Tue, 18 Jul 2023 12:05:20 +0330 Subject: [PATCH 3/4] Make adjustments based on the psalm review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hamid Dehnavi Co-authored-by: Julius Härtl Signed-off-by: Hamid Dehnavi --- lib/private/App/AppStore/Fetcher/AppFetcher.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/private/App/AppStore/Fetcher/AppFetcher.php b/lib/private/App/AppStore/Fetcher/AppFetcher.php index 7f98617d822c0..b899954a17500 100644 --- a/lib/private/App/AppStore/Fetcher/AppFetcher.php +++ b/lib/private/App/AppStore/Fetcher/AppFetcher.php @@ -39,9 +39,6 @@ use Psr\Log\LoggerInterface; class AppFetcher extends Fetcher { - /** @var IRegistry */ - protected IRegistry $registry; - /** @var bool */ private $ignoreMaxVersion; @@ -51,7 +48,8 @@ public function __construct(Factory $appDataFactory, IConfig $config, CompareVersion $compareVersion, LoggerInterface $logger, - IRegistry $registry) { + protected IRegistry $registry, + ) { parent::__construct( $appDataFactory, $clientService, @@ -61,8 +59,6 @@ public function __construct(Factory $appDataFactory, $registry ); - $this->registry = $registry; - $this->fileName = 'apps.json'; $this->endpointName = 'apps.json'; $this->ignoreMaxVersion = true; From cf17db2fe620e7105575b08c69b8c09899eba049 Mon Sep 17 00:00:00 2001 From: Hamid Dehnavi Date: Mon, 11 Dec 2023 16:50:55 +0330 Subject: [PATCH 4/4] Fix psalm errors Signed-off-by: Hamid Dehnavi --- lib/private/App/AppStore/Fetcher/AppFetcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/App/AppStore/Fetcher/AppFetcher.php b/lib/private/App/AppStore/Fetcher/AppFetcher.php index b899954a17500..bb1a0e8948488 100644 --- a/lib/private/App/AppStore/Fetcher/AppFetcher.php +++ b/lib/private/App/AppStore/Fetcher/AppFetcher.php @@ -46,7 +46,7 @@ public function __construct(Factory $appDataFactory, IClientService $clientService, ITimeFactory $timeFactory, IConfig $config, - CompareVersion $compareVersion, + private CompareVersion $compareVersion, LoggerInterface $logger, protected IRegistry $registry, ) {