From 2f44c37c36a9077aba5f2cee7ff93fd205bff5cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Bia=C5=82czak?= Date: Fri, 28 Feb 2025 08:13:48 +0100 Subject: [PATCH 1/3] Applied constructor property promotion and type declarations via Rector for better readability and type safety. --- phpstan-baseline.neon | 6 --- rector.php | 8 ++++ src/bundle/Command/SystemInfoDumpCommand.php | 19 ++------ .../Controller/SystemInfoController.php | 15 ++----- .../IbexaSystemInfoExtension.php | 9 ++-- .../EventSubscriber/AddXPoweredByHeader.php | 10 +---- src/bundle/Resources/config/services.yaml | 8 ++-- ...rationSymfonyKernelSystemInfoCollector.php | 39 +++------------- .../EzcHardwareSystemInfoCollector.php | 12 +---- .../Collector/EzcPhpSystemInfoCollector.php | 10 +---- .../Collector/IbexaSystemInfoCollector.php | 34 ++------------ .../JsonComposerLockSystemInfoCollector.php | 39 ++++------------ .../RepositorySystemInfoCollector.php | 24 ++-------- .../Collector/ServicesSystemInfoCollector.php | 7 +-- .../OutputFormat/JsonOutputFormat.php | 2 +- .../SystemInfo/OutputFormatRegistry.php | 15 ++----- .../SystemInfo/Registry/IdentifierBased.php | 26 +++-------- .../SystemInfoCollectorRegistry.php | 19 +++----- .../SystemInfo/Value/ServicesSystemInfo.php | 45 ++++++++----------- src/bundle/View/SystemInfoViewBuilder.php | 32 +++---------- .../Dashboard/EzInfoTwigComponent.php | 31 +++---------- .../ConfigureMainMenuListener.php | 20 ++------- .../SystemInfoTabGroupListener.php | 25 ++--------- src/lib/Service/AggregateServiceProvider.php | 17 +++---- src/lib/Service/HttpCacheServiceInfo.php | 7 +-- .../Service/PersistenceCacheServiceInfo.php | 7 +-- src/lib/Service/SearchEngineServiceInfo.php | 9 ++-- src/lib/Storage/AggregateMetricsProvider.php | 17 +++---- .../Storage/Metrics/DraftsCountMetrics.php | 7 +-- .../RepositoryConnectionAwareMetrics.php | 9 +--- src/lib/Tab/SystemInfo/SystemInfoTab.php | 20 +-------- src/lib/Tab/SystemInfo/TabFactory.php | 29 ++---------- .../Registry/IdentifierBasedTest.php | 2 +- .../SystemInfoTabGroupListenerTest.php | 22 ++++----- 34 files changed, 141 insertions(+), 460 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index fb338b9..9927f3f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -17,9 +17,3 @@ parameters: identifier: argument.type count: 1 path: src/lib/Storage/Metrics/DraftsCountMetrics.php - - - - message: '#^Parameter \#1 \$items of class Ibexa\\Bundle\\SystemInfo\\SystemInfo\\Registry\\IdentifierBased constructor expects array\, array\ given\.$#' - identifier: argument.type - count: 3 - path: tests/bundle/SystemInfo/Registry/IdentifierBasedTest.php diff --git a/rector.php b/rector.php index da984b1..241a482 100644 --- a/rector.php +++ b/rector.php @@ -8,7 +8,10 @@ use Ibexa\Contracts\Rector\Sets\IbexaSetList; use Rector\Config\RectorConfig; +use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; +use Rector\Set\ValueObject\SetList; use Rector\Symfony\Set\SymfonySetList; +use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector; return RectorConfig::configure() ->withPaths([ @@ -16,10 +19,15 @@ __DIR__ . '/tests', ]) ->withSets([ + SetList::TYPE_DECLARATION, IbexaSetList::IBEXA_50->value, SymfonySetList::SYMFONY_60, SymfonySetList::SYMFONY_61, SymfonySetList::SYMFONY_62, SymfonySetList::SYMFONY_63, SymfonySetList::SYMFONY_64, + ]) + ->withRules([ + TypedPropertyFromAssignsRector::class, + ClassPropertyAssignToConstructorPromotionRector::class, ]); diff --git a/src/bundle/Command/SystemInfoDumpCommand.php b/src/bundle/Command/SystemInfoDumpCommand.php index 0a7f02a..d2aa1e6 100644 --- a/src/bundle/Command/SystemInfoDumpCommand.php +++ b/src/bundle/Command/SystemInfoDumpCommand.php @@ -22,15 +22,10 @@ )] final class SystemInfoDumpCommand extends Command { - private SystemInfoCollectorRegistry $systemInfoCollectorRegistry; - - private OutputFormatRegistry $outputFormatRegistry; - - public function __construct(SystemInfoCollectorRegistry $systemInfoCollectorRegistry, OutputFormatRegistry $outputFormatRegistry) - { - $this->systemInfoCollectorRegistry = $systemInfoCollectorRegistry; - $this->outputFormatRegistry = $outputFormatRegistry; - + public function __construct( + private readonly SystemInfoCollectorRegistry $systemInfoCollectorRegistry, + private readonly OutputFormatRegistry $outputFormatRegistry + ) { parent::__construct(); } @@ -65,12 +60,6 @@ protected function configure(): void ; } - /** - * Execute the Command. - * - * @param $input InputInterface - * @param $output OutputInterface - */ protected function execute(InputInterface $input, OutputInterface $output): int { if ($input->getOption('list-info-collectors')) { diff --git a/src/bundle/Controller/SystemInfoController.php b/src/bundle/Controller/SystemInfoController.php index f19f2ac..2d9ec5b 100644 --- a/src/bundle/Controller/SystemInfoController.php +++ b/src/bundle/Controller/SystemInfoController.php @@ -15,15 +15,9 @@ class SystemInfoController extends AdminUiController { - /** @var \Ibexa\Bundle\SystemInfo\SystemInfo\SystemInfoCollectorRegistry */ - protected $collectorRegistry; - - /** - * @param \Ibexa\Bundle\SystemInfo\SystemInfo\SystemInfoCollectorRegistry $collectorRegistry - */ - public function __construct(SystemInfoCollectorRegistry $collectorRegistry) - { - $this->collectorRegistry = $collectorRegistry; + public function __construct( + private readonly SystemInfoCollectorRegistry $collectorRegistry + ) { } public function performAccessCheck(): void @@ -49,9 +43,6 @@ public function viewInfoAction(SystemInfoView $view): SystemInfoView return $view; } - /** - * Renders a PHP info page. - */ public function phpinfoAction(): Response { ob_start(); diff --git a/src/bundle/DependencyInjection/IbexaSystemInfoExtension.php b/src/bundle/DependencyInjection/IbexaSystemInfoExtension.php index 6ecc22b..9861b0b 100644 --- a/src/bundle/DependencyInjection/IbexaSystemInfoExtension.php +++ b/src/bundle/DependencyInjection/IbexaSystemInfoExtension.php @@ -20,9 +20,9 @@ class IbexaSystemInfoExtension extends Extension implements PrependExtensionInterface { - public const EXTENSION_NAME = 'ibexa_system_info'; - public const METRICS_TAG = 'ibexa.system_info.metrics'; - public const SERVICE_TAG = 'ibexa.system_info.service'; + public const string EXTENSION_NAME = 'ibexa_system_info'; + public const string METRICS_TAG = 'ibexa.system_info.metrics'; + public const string SERVICE_TAG = 'ibexa.system_info.service'; public function getAlias(): string { @@ -34,9 +34,6 @@ public function getConfiguration(array $config, ContainerBuilder $container): Co return new Configuration(); } - /** - * {@inheritdoc} - */ public function load(array $configs, ContainerBuilder $container): void { $loader = new Loader\YamlFileLoader( diff --git a/src/bundle/EventSubscriber/AddXPoweredByHeader.php b/src/bundle/EventSubscriber/AddXPoweredByHeader.php index a6fc162..7d59c8b 100644 --- a/src/bundle/EventSubscriber/AddXPoweredByHeader.php +++ b/src/bundle/EventSubscriber/AddXPoweredByHeader.php @@ -15,16 +15,10 @@ /** * Sets X-Powered-By header to promote use of Platform. */ -class AddXPoweredByHeader implements EventSubscriberInterface +readonly class AddXPoweredByHeader implements EventSubscriberInterface { - /** - * @var string If empty, this powered by header is skipped. - */ - private $installationName; - - public function __construct(string $installationName) + public function __construct(private string $installationName) { - $this->installationName = $installationName; } public static function getSubscribedEvents(): array diff --git a/src/bundle/Resources/config/services.yaml b/src/bundle/Resources/config/services.yaml index e414d45..590e22f 100644 --- a/src/bundle/Resources/config/services.yaml +++ b/src/bundle/Resources/config/services.yaml @@ -47,7 +47,7 @@ services: # SystemInfoCollectors Ibexa\Bundle\SystemInfo\SystemInfo\Collector\IbexaSystemInfoCollector: arguments: - $composerCollector: '@Ibexa\Bundle\SystemInfo\SystemInfo\Collector\JsonComposerLockSystemInfoCollector' + $systemInfoCollector: '@Ibexa\Bundle\SystemInfo\SystemInfo\Collector\JsonComposerLockSystemInfoCollector' $kernelProjectDir: '%kernel.project_dir%' tags: - { name: ibexa.system_info.collector, identifier: ibexa } @@ -69,7 +69,7 @@ services: lazy: true autowire: true arguments: - $db: '@ibexa.persistence.connection' + $connection: '@ibexa.persistence.connection' tags: - { name: ibexa.system_info.collector, identifier: repository } @@ -108,7 +108,7 @@ services: Ibexa\SystemInfo\Storage\AggregateMetricsProvider: arguments: - $metrics: !tagged_locator + $metricsLocator: !tagged_locator tag: !php/const \Ibexa\Bundle\SystemInfo\DependencyInjection\IbexaSystemInfoExtension::METRICS_TAG index_by: identifier @@ -158,7 +158,7 @@ services: Ibexa\SystemInfo\Service\AggregateServiceProvider: arguments: - $service: !tagged_locator + $serviceLocator: !tagged_locator tag: !php/const \Ibexa\Bundle\SystemInfo\DependencyInjection\IbexaSystemInfoExtension::SERVICE_TAG index_by: identifier diff --git a/src/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollector.php b/src/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollector.php index fada46e..536c1de 100644 --- a/src/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollector.php @@ -15,42 +15,13 @@ */ class ConfigurationSymfonyKernelSystemInfoCollector implements SystemInfoCollector { - /** - * Symfony kernel. - * - * @var \Symfony\Component\HttpKernel\Kernel - */ - private $kernel; - - /** - * Installed bundles. - * - * A hash containing the active bundles, where the key is the bundle name, and the value is the corresponding namespace. - * - * Example: - * array ( - * 'AppBundle' => 'AppBundle\\AppBundle', - * 'AsseticBundle' => 'Symfony\\Bundle\\AsseticBundle\\AsseticBundle', - * ) - * - * @var array - */ - private $bundles; - - /** - * @param array $bundles - */ - public function __construct(Kernel $kernel, array $bundles) - { - $this->kernel = $kernel; - $this->bundles = $bundles; + public function __construct( + private readonly Kernel $kernel, + /** @var array */ + private array $bundles = [] + ) { } - /** - * Collects information about the Symfony kernel. - * - * @return \Ibexa\Bundle\SystemInfo\SystemInfo\Value\SymfonyKernelSystemInfo - */ public function collect(): SymfonyKernelSystemInfo { ksort($this->bundles, SORT_FLAG_CASE | SORT_STRING); diff --git a/src/bundle/SystemInfo/Collector/EzcHardwareSystemInfoCollector.php b/src/bundle/SystemInfo/Collector/EzcHardwareSystemInfoCollector.php index 6721ef0..679f867 100644 --- a/src/bundle/SystemInfo/Collector/EzcHardwareSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/EzcHardwareSystemInfoCollector.php @@ -13,24 +13,16 @@ /** * Collects hardware system information using zetacomponents/sysinfo. */ -class EzcHardwareSystemInfoCollector implements SystemInfoCollector +readonly class EzcHardwareSystemInfoCollector implements SystemInfoCollector { - /** - * @var \Ibexa\Bundle\SystemInfo\SystemInfo\EzcSystemInfoWrapper - */ - private $ezcSystemInfo; - - public function __construct(EzcSystemInfoWrapper $ezcSystemInfo) + public function __construct(private EzcSystemInfoWrapper $ezcSystemInfo) { - $this->ezcSystemInfo = $ezcSystemInfo; } /** * Collects information about the hardware Ibexa DXP is installed on. * - cpu information * - memory size. - * - * @return \Ibexa\Bundle\SystemInfo\SystemInfo\Value\HardwareSystemInfo */ public function collect(): HardwareSystemInfo { diff --git a/src/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollector.php b/src/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollector.php index b478a0b..93b0ca0 100644 --- a/src/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollector.php @@ -13,16 +13,10 @@ /** * Collects PHP information using zetacomponents/sysinfo. */ -class EzcPhpSystemInfoCollector implements SystemInfoCollector +readonly class EzcPhpSystemInfoCollector implements SystemInfoCollector { - /** - * @var \Ibexa\Bundle\SystemInfo\SystemInfo\EzcSystemInfoWrapper - */ - private $ezcSystemInfo; - - public function __construct(EzcSystemInfoWrapper $ezcSystemInfo) + public function __construct(private EzcSystemInfoWrapper $ezcSystemInfo) { - $this->ezcSystemInfo = $ezcSystemInfo; } /** diff --git a/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php b/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php index 7bc05fd..91f8122 100644 --- a/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php @@ -112,37 +112,14 @@ class IbexaSystemInfoCollector implements SystemInfoCollector 'ibexa/commerce', ]; - /** - * @var \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector - */ - private $systemInfoCollector; + private ?ComposerSystemInfo $composerInfo = null; - /** - * @var \Ibexa\Bundle\SystemInfo\SystemInfo\Value\ComposerSystemInfo|null - */ - private $composerInfo; - - /** @var string */ - private $kernelProjectDir; - - /** - * @param \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\JsonComposerLockSystemInfoCollector|\Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector $composerCollector - */ public function __construct( - SystemInfoCollector $composerCollector, - string $kernelProjectDir, + private readonly SystemInfoCollector $systemInfoCollector, + private readonly string $kernelProjectDir ) { - $this->systemInfoCollector = $composerCollector; - $this->kernelProjectDir = $kernelProjectDir; } - /** - * Collects information about the Ibexa distribution and version. - * - * @throws \Exception - * - * @return \Ibexa\Bundle\SystemInfo\SystemInfo\Value\IbexaSystemInfo - */ public function collect(): IbexaSystemInfo { if ($this->composerInfo === null) { @@ -168,9 +145,6 @@ public function collect(): IbexaSystemInfo return $ibexa; } - /** - * @throws \Exception - */ private function setReleaseInfo(IbexaSystemInfo $ibexa): void { $ibexa->release = Ibexa::VERSION; @@ -247,7 +221,7 @@ private static function getStability(ComposerSystemInfo $composerInfo): string } /** - * @param list $packageNames + * @param string[] $packageNames List of package names to check. */ private static function hasAnyPackage( ComposerSystemInfo $composerInfo, diff --git a/src/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php b/src/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php index 55c73ae..b9a1c28 100644 --- a/src/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php @@ -8,6 +8,7 @@ namespace Ibexa\Bundle\SystemInfo\SystemInfo\Collector; use Composer\InstalledVersions; +use DateTime; use Ibexa\Bundle\SystemInfo\SystemInfo\Exception; use Ibexa\Bundle\SystemInfo\SystemInfo\Value\ComposerPackage; use Ibexa\Bundle\SystemInfo\SystemInfo\Value\ComposerSystemInfo; @@ -19,36 +20,17 @@ */ class JsonComposerLockSystemInfoCollector implements SystemInfoCollector { - public const IBEXA_OSS_PACKAGE = 'ibexa/oss'; + public const string IBEXA_OSS_PACKAGE = 'ibexa/oss'; - private VersionStabilityChecker $versionStabilityChecker; - - private string $lockFile; - - private string $jsonFile; - - /** - * The collected value, cached in case info is collected by other collectors. - */ private ?ComposerSystemInfo $value = null; public function __construct( - VersionStabilityChecker $versionStabilityChecker, - string $lockFile, - string $jsonFile + private readonly VersionStabilityChecker $versionStabilityChecker, + private readonly string $lockFile, + private readonly string $jsonFile ) { - $this->versionStabilityChecker = $versionStabilityChecker; - $this->lockFile = $lockFile; - $this->jsonFile = $jsonFile; } - /** - * Collects information about installed composer packages. - * - * @throws Exception\ComposerLockFileNotFoundException if the composer.lock file was not found. - * @throws Exception\ComposerJsonFileNotFoundException if the composer.json file was not found. - * @throws Exception\ComposerFileValidationException if composer.lock of composer.json are not valid. - */ public function collect(): ComposerSystemInfo { if ($this->value) { @@ -104,10 +86,10 @@ private function extractPackages(array $lockData): array $package = new ComposerPackage([ 'name' => $packageData['name'], 'branch' => $packageData['version'], - 'dateTime' => isset($packageData['time']) ? new \DateTime($packageData['time']) : null, - 'homepage' => isset($packageData['homepage']) ? $packageData['homepage'] : '', + 'dateTime' => isset($packageData['time']) ? new DateTime($packageData['time']) : null, + 'homepage' => $packageData['homepage'] ?? '', 'reference' => isset($packageData['source']) ? $packageData['source']['reference'] : null, - 'license' => isset($packageData['license'][0]) ? $packageData['license'][0] : null, + 'license' => $packageData['license'][0] ?? null, ]); if (isset($lockData['stability-flags'][$package->name])) { @@ -161,12 +143,9 @@ private function extractRepositoryUrls(array $jsonData): array return $repos; } - /** - * @param \Ibexa\Bundle\SystemInfo\SystemInfo\Value\ComposerPackage $package - */ private static function setNormalizedVersion(ComposerPackage $package): void { - $version = $package->alias ? $package->alias : $package->branch; + $version = $package->alias ?: $package->branch; if ($version[0] === 'v') { $version = substr($version, 1); } diff --git a/src/bundle/SystemInfo/Collector/RepositorySystemInfoCollector.php b/src/bundle/SystemInfo/Collector/RepositorySystemInfoCollector.php index bf169aa..9c19f0e 100644 --- a/src/bundle/SystemInfo/Collector/RepositorySystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/RepositorySystemInfoCollector.php @@ -17,24 +17,10 @@ */ class RepositorySystemInfoCollector implements SystemInfoCollector { - /** - * The database connection, only used to retrieve some information on the database itself. - * - * @var \Doctrine\DBAL\Connection - */ - private $connection; - - /** - * The metrics provider needed to populate Repository value object consisting of several metrics. - * - * @var \Ibexa\SystemInfo\Storage\MetricsProvider - */ - private $metricsProvider; - - public function __construct(Connection $db, MetricsProvider $metricsProvider) - { - $this->connection = $db; - $this->metricsProvider = $metricsProvider; + public function __construct( + private readonly Connection $connection, + private readonly MetricsProvider $metricsProvider + ) { } /** @@ -44,8 +30,6 @@ public function __construct(Connection $db, MetricsProvider $metricsProvider) * - host * - username * - repository metrics (containing count of content objects, users, drafts etc.). - * - * @return \Ibexa\Bundle\SystemInfo\SystemInfo\Value\RepositorySystemInfo */ public function collect(): RepositorySystemInfo { diff --git a/src/bundle/SystemInfo/Collector/ServicesSystemInfoCollector.php b/src/bundle/SystemInfo/Collector/ServicesSystemInfoCollector.php index a82deae..ea9fb38 100644 --- a/src/bundle/SystemInfo/Collector/ServicesSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/ServicesSystemInfoCollector.php @@ -13,13 +13,10 @@ /** * Collects information about the services used within the project. */ -final class ServicesSystemInfoCollector implements SystemInfoCollector +final readonly class ServicesSystemInfoCollector implements SystemInfoCollector { - private ServiceProviderInterface $serviceProvider; - - public function __construct(ServiceProviderInterface $serviceProvider) + public function __construct(private ServiceProviderInterface $serviceProvider) { - $this->serviceProvider = $serviceProvider; } public function collect(): ServicesSystemInfo diff --git a/src/bundle/SystemInfo/OutputFormat/JsonOutputFormat.php b/src/bundle/SystemInfo/OutputFormat/JsonOutputFormat.php index 8d40d40..8a5b644 100644 --- a/src/bundle/SystemInfo/OutputFormat/JsonOutputFormat.php +++ b/src/bundle/SystemInfo/OutputFormat/JsonOutputFormat.php @@ -14,7 +14,7 @@ */ class JsonOutputFormat implements SystemInfoOutputFormat { - public function format(array $collectedInfo) + public function format(array $collectedInfo): string { $json = json_encode($collectedInfo, JSON_PRETTY_PRINT); if ($json === false) { diff --git a/src/bundle/SystemInfo/OutputFormatRegistry.php b/src/bundle/SystemInfo/OutputFormatRegistry.php index 514ab61..abdf6b8 100644 --- a/src/bundle/SystemInfo/OutputFormatRegistry.php +++ b/src/bundle/SystemInfo/OutputFormatRegistry.php @@ -12,22 +12,15 @@ /** * A registry of OutputFormats. */ -class OutputFormatRegistry +readonly class OutputFormatRegistry { - /** @var \Ibexa\Bundle\SystemInfo\SystemInfo\OutputFormat[] */ - private array $registry = []; - /** - * @param \Ibexa\Bundle\SystemInfo\SystemInfo\OutputFormat[] $items Hash of OutputFormats, with identifier string as key. + * @param \Ibexa\Bundle\SystemInfo\SystemInfo\OutputFormat[] $registry Hash of OutputFormats, with identifier string as key. */ - public function __construct(array $items = []) + public function __construct(private array $registry = []) { - $this->registry = $items; } - /** - * @throws \Ibexa\Core\Base\Exceptions\NotFoundException If no OutputFormat exists with this identifier - */ public function getItem(string $identifier): OutputFormat { if (isset($this->registry[$identifier])) { @@ -38,8 +31,6 @@ public function getItem(string $identifier): OutputFormat } /** - * Returns the identifiers of all registered OutputFormats. - * * @return string[] Array of identifier strings. */ public function getIdentifiers(): array diff --git a/src/bundle/SystemInfo/Registry/IdentifierBased.php b/src/bundle/SystemInfo/Registry/IdentifierBased.php index 5a421ad..a80ddd1 100644 --- a/src/bundle/SystemInfo/Registry/IdentifierBased.php +++ b/src/bundle/SystemInfo/Registry/IdentifierBased.php @@ -7,35 +7,23 @@ namespace Ibexa\Bundle\SystemInfo\SystemInfo\Registry; +use Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector; use Ibexa\Bundle\SystemInfo\SystemInfo\SystemInfoCollectorRegistry; use Ibexa\Core\Base\Exceptions\NotFoundException; /** * A registry of SystemInfoCollectors that uses an identifier string to identify the collector. */ -class IdentifierBased implements SystemInfoCollectorRegistry +readonly class IdentifierBased implements SystemInfoCollectorRegistry { - /** @var \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector[] */ - private $registry = []; - /** - * @param \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector[] $items Hash of SystemInfoCollectors, with identifier string as key. + * @param \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector[] $registry Hash of SystemInfoCollectors, with identifier string as key. */ - public function __construct(array $items = []) + public function __construct(private array $registry = []) { - $this->registry = $items; } - /** - * Returns the SystemInfoCollector matching the argument. - * - * @param string $identifier An identifier string. - * - * @throws \Ibexa\Core\Base\Exceptions\NotFoundException If no SystemInfoCollector exists with this identifier - * - * @return \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector The SystemInfoCollector given by the identifier. - */ - public function getItem($identifier) + public function getItem(string $identifier): SystemInfoCollector { if (isset($this->registry[$identifier])) { return $this->registry[$identifier]; @@ -45,11 +33,9 @@ public function getItem($identifier) } /** - * Returns the identifiers of all registered SystemInfoCollectors. - * * @return string[] Array of identifier strings. */ - public function getIdentifiers() + public function getIdentifiers(): array { return array_keys($this->registry); } diff --git a/src/bundle/SystemInfo/SystemInfoCollectorRegistry.php b/src/bundle/SystemInfo/SystemInfoCollectorRegistry.php index 32c2bf6..4032088 100644 --- a/src/bundle/SystemInfo/SystemInfoCollectorRegistry.php +++ b/src/bundle/SystemInfo/SystemInfoCollectorRegistry.php @@ -7,6 +7,8 @@ namespace Ibexa\Bundle\SystemInfo\SystemInfo; +use Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector; + /** * A registry of SystemInfoCollectors. */ @@ -17,21 +19,10 @@ interface SystemInfoCollectorRegistry */ public function __construct(array $items = []); - /** - * Returns the SystemInfoCollector matching the argument. - * - * @param string $identifier An identifier string. - * - * @throws \Ibexa\Core\Base\Exceptions\NotFoundException If no SystemInfoCollector exists with this identifier - * - * @return \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector The SystemInfoCollector given by the identifier. - */ - public function getItem($identifier); + public function getItem(string $identifier): SystemInfoCollector; /** - * Returns the identifiers of all registered SystemInfoCollectors. - * - * @return string[] Array of identifier strings. + * @return string[] List of system info identifiers. */ - public function getIdentifiers(); + public function getIdentifiers(): array; } diff --git a/src/bundle/SystemInfo/Value/ServicesSystemInfo.php b/src/bundle/SystemInfo/Value/ServicesSystemInfo.php index 328c8a5..4b2328f 100644 --- a/src/bundle/SystemInfo/Value/ServicesSystemInfo.php +++ b/src/bundle/SystemInfo/Value/ServicesSystemInfo.php @@ -12,35 +12,26 @@ */ final class ServicesSystemInfo implements SystemInfo { - /** - * Search engine. - * - * Example: Solr - */ - private string $searchEngine; - - /** - * Reverse proxy handling HTTP caching. - * - * Example: Fastly - */ - private string $httpCacheProxy; - - /** - * Persistence cache adapter. - * - * Example: Redis - */ - private string $persistenceCacheAdapter; - public function __construct( - string $searchEngine, - string $httpCacheProxy, - string $persistenceCacheAdapter + /** + * Search engine. + * + * Example: Solr + */ + private string $searchEngine, + /** + * Reverse proxy handling HTTP caching. + * + * Example: Fastly + */ + private string $httpCacheProxy, + /** + * Persistence cache adapter. + * + * Example: Redis + */ + private string $persistenceCacheAdapter ) { - $this->searchEngine = $searchEngine; - $this->httpCacheProxy = $httpCacheProxy; - $this->persistenceCacheAdapter = $persistenceCacheAdapter; } public function getSearchEngine(): string diff --git a/src/bundle/View/SystemInfoViewBuilder.php b/src/bundle/View/SystemInfoViewBuilder.php index b365e3a..ff9a44e 100644 --- a/src/bundle/View/SystemInfoViewBuilder.php +++ b/src/bundle/View/SystemInfoViewBuilder.php @@ -13,26 +13,13 @@ use Ibexa\Bundle\SystemInfo\SystemInfo\Value\InvalidSystemInfo; use Ibexa\Core\MVC\Symfony\View\Builder\ViewBuilder; use Ibexa\Core\MVC\Symfony\View\Configurator; -use Ibexa\Core\MVC\Symfony\View\View; -class SystemInfoViewBuilder implements ViewBuilder +readonly class SystemInfoViewBuilder implements ViewBuilder { - /** - * @var \Ibexa\Core\MVC\Symfony\View\Configurator - */ - private $viewConfigurator; - - /** - * System info collector registry. - * - * @var \Ibexa\Bundle\SystemInfo\SystemInfo\SystemInfoCollectorRegistry - */ - private $registry; - - public function __construct(Configurator $viewConfigurator, SystemInfoCollectorRegistry $registry) - { - $this->viewConfigurator = $viewConfigurator; - $this->registry = $registry; + public function __construct( + private Configurator $viewConfigurator, + private SystemInfoCollectorRegistry $registry + ) { } public function matches($argument): bool @@ -41,11 +28,9 @@ public function matches($argument): bool } /** - * @param array $parameters - * - * @return \Ibexa\Bundle\SystemInfo\View\SystemInfoView + * @param array{systemInfoIdentifier: string, viewType: string} $parameters */ - public function buildView(array $parameters): View + public function buildView(array $parameters): SystemInfoView { $collector = $this->getCollector($parameters['systemInfoIdentifier']); $view = new SystemInfoView(null, [], $parameters['viewType']); @@ -63,9 +48,6 @@ public function buildView(array $parameters): View return $view; } - /** - * @param string $identifier A SystemInfo collector identifier (php, hardware...) - */ private function getCollector(string $identifier): SystemInfoCollector { return $this->registry->getItem($identifier); diff --git a/src/lib/Component/Dashboard/EzInfoTwigComponent.php b/src/lib/Component/Dashboard/EzInfoTwigComponent.php index 8158bc8..612b1a6 100644 --- a/src/lib/Component/Dashboard/EzInfoTwigComponent.php +++ b/src/lib/Component/Dashboard/EzInfoTwigComponent.php @@ -12,36 +12,19 @@ use Ibexa\Contracts\AdminUi\Component\Renderable; use Twig\Environment; -class EzInfoTwigComponent implements Renderable +readonly class EzInfoTwigComponent implements Renderable { - protected string $template; - - protected Environment $twig; - - /** @var array */ - protected array $parameters; - - private IbexaSystemInfo $ibexaSystemInfo; - - /** @var array */ - private array $urlList; - /** * @param array $urlList - * @param array $parameters + * @param array $parameters */ public function __construct( - Environment $twig, - string $template, - IbexaSystemInfo $ibexaSystemInfo, - array $urlList, - array $parameters = [] + private Environment $twig, + private string $template, + private IbexaSystemInfo $ibexaSystemInfo, + private array $urlList, + private array $parameters = [] ) { - $this->twig = $twig; - $this->template = $template; - $this->parameters = $parameters; - $this->ibexaSystemInfo = $ibexaSystemInfo; - $this->urlList = $urlList; } /** diff --git a/src/lib/EventListener/ConfigureMainMenuListener.php b/src/lib/EventListener/ConfigureMainMenuListener.php index ad0bf88..a333a86 100644 --- a/src/lib/EventListener/ConfigureMainMenuListener.php +++ b/src/lib/EventListener/ConfigureMainMenuListener.php @@ -18,25 +18,14 @@ class ConfigureMainMenuListener implements EventSubscriberInterface, TranslationContainerInterface { - public const ITEM_ADMIN__SYSTEMINFO = 'main__admin__systeminfo'; - - /** @var \Ibexa\Contracts\AdminUi\Menu\MenuItemFactoryInterface */ - private $menuItemFactory; - - /** @var \Ibexa\Contracts\Core\Repository\PermissionResolver */ - private $permissionResolver; + public const string ITEM_ADMIN__SYSTEMINFO = 'main__admin__systeminfo'; public function __construct( - MenuItemFactoryInterface $menuItemFactory, - PermissionResolver $permissionResolver + private readonly MenuItemFactoryInterface $menuItemFactory, + private readonly PermissionResolver $permissionResolver ) { - $this->menuItemFactory = $menuItemFactory; - $this->permissionResolver = $permissionResolver; } - /** - * @param \Ibexa\AdminUi\Menu\Event\ConfigureMenuEvent $event - */ public function onMenuConfigure(ConfigureMenuEvent $event): void { $menu = $event->getMenu(); @@ -69,9 +58,6 @@ public static function getSubscribedEvents(): array ]; } - /** - * {@inheritdoc} - */ public static function getTranslationMessages(): array { return [ diff --git a/src/lib/EventListener/SystemInfoTabGroupListener.php b/src/lib/EventListener/SystemInfoTabGroupListener.php index 981af91..530fa3c 100644 --- a/src/lib/EventListener/SystemInfoTabGroupListener.php +++ b/src/lib/EventListener/SystemInfoTabGroupListener.php @@ -9,35 +9,16 @@ use Ibexa\AdminUi\Tab\Event\TabEvents; use Ibexa\AdminUi\Tab\Event\TabGroupEvent; -use Ibexa\AdminUi\Tab\TabRegistry; use Ibexa\Bundle\SystemInfo\SystemInfo\SystemInfoCollectorRegistry; use Ibexa\SystemInfo\Tab\SystemInfo\TabFactory; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -class SystemInfoTabGroupListener implements EventSubscriberInterface +readonly class SystemInfoTabGroupListener implements EventSubscriberInterface { - /** @var \Ibexa\AdminUi\Tab\TabRegistry */ - protected $tabRegistry; - - /** @var \Ibexa\SystemInfo\Tab\SystemInfo\TabFactory */ - protected $tabFactory; - - /** @var \Ibexa\Bundle\SystemInfo\SystemInfo\SystemInfoCollectorRegistry */ - protected $systeminfoCollectorRegistry; - - /** - * @param \Ibexa\AdminUi\Tab\TabRegistry $tabRegistry - * @param \Ibexa\SystemInfo\Tab\SystemInfo\TabFactory $tabFactory - * @param \Ibexa\Bundle\SystemInfo\SystemInfo\SystemInfoCollectorRegistry $systeminfoCollectorRegistry - */ public function __construct( - TabRegistry $tabRegistry, - TabFactory $tabFactory, - SystemInfoCollectorRegistry $systeminfoCollectorRegistry + private TabFactory $tabFactory, + private SystemInfoCollectorRegistry $systeminfoCollectorRegistry ) { - $this->tabRegistry = $tabRegistry; - $this->tabFactory = $tabFactory; - $this->systeminfoCollectorRegistry = $systeminfoCollectorRegistry; } public static function getSubscribedEvents(): array diff --git a/src/lib/Service/AggregateServiceProvider.php b/src/lib/Service/AggregateServiceProvider.php index 297b249..316143c 100644 --- a/src/lib/Service/AggregateServiceProvider.php +++ b/src/lib/Service/AggregateServiceProvider.php @@ -15,26 +15,21 @@ /** * @internal */ -final class AggregateServiceProvider implements ServiceProviderInterface +final readonly class AggregateServiceProvider implements ServiceProviderInterface { - /** @var \Symfony\Component\DependencyInjection\ServiceLocator<\Ibexa\SystemInfo\Service\ServiceInfo> */ - private ServiceLocator $serviceLocator; - /** - * @param \Symfony\Component\DependencyInjection\ServiceLocator<\Ibexa\SystemInfo\Service\ServiceInfo> $service + * @param ServiceLocator $serviceLocator */ - public function __construct(ServiceLocator $service) + public function __construct(private ServiceLocator $serviceLocator) { - $this->serviceLocator = $service; } - /** - * @throws \Ibexa\Bundle\SystemInfo\SystemInfo\Exception\SystemInfoServiceNotFoundException - */ public function getServiceType(string $identifier): string { try { - return $this->serviceLocator->get($identifier)->getServiceType(); + $service = $this->serviceLocator->get($identifier); + + return $service->getServiceType($identifier); } catch (ServiceNotFoundException $e) { throw new SystemInfoServiceNotFoundException($identifier, $e); } diff --git a/src/lib/Service/HttpCacheServiceInfo.php b/src/lib/Service/HttpCacheServiceInfo.php index 16375a4..14c9ea9 100644 --- a/src/lib/Service/HttpCacheServiceInfo.php +++ b/src/lib/Service/HttpCacheServiceInfo.php @@ -11,13 +11,10 @@ /** * @internal */ -final class HttpCacheServiceInfo implements ServiceInfo +final readonly class HttpCacheServiceInfo implements ServiceInfo { - private string $purgeType; - - public function __construct(string $purgeType) + public function __construct(private string $purgeType) { - $this->purgeType = $purgeType; } public function getServiceType(): string diff --git a/src/lib/Service/PersistenceCacheServiceInfo.php b/src/lib/Service/PersistenceCacheServiceInfo.php index 7584901..e48be0b 100644 --- a/src/lib/Service/PersistenceCacheServiceInfo.php +++ b/src/lib/Service/PersistenceCacheServiceInfo.php @@ -15,13 +15,10 @@ */ final class PersistenceCacheServiceInfo implements ServiceInfo { - private const PERSISTENCE_CACHE_CONFIG_KEY = 'cache_service_name'; + private const string PERSISTENCE_CACHE_CONFIG_KEY = 'cache_service_name'; - private ConfigResolverInterface $configResolver; - - public function __construct(ConfigResolverInterface $configResolver) + public function __construct(private readonly ConfigResolverInterface $configResolver) { - $this->configResolver = $configResolver; } public function getServiceType(): string diff --git a/src/lib/Service/SearchEngineServiceInfo.php b/src/lib/Service/SearchEngineServiceInfo.php index 835b424..4812eba 100644 --- a/src/lib/Service/SearchEngineServiceInfo.php +++ b/src/lib/Service/SearchEngineServiceInfo.php @@ -15,14 +15,11 @@ */ final class SearchEngineServiceInfo implements ServiceInfo { - private const SEARCH_KEY = 'search'; - private const ENGINE_KEY = 'engine'; + private const string SEARCH_KEY = 'search'; + private const string ENGINE_KEY = 'engine'; - private RepositoryConfigurationProviderInterface $repositoryConfigProvider; - - public function __construct(RepositoryConfigurationProviderInterface $repositoryConfigProvider) + public function __construct(private readonly RepositoryConfigurationProviderInterface $repositoryConfigProvider) { - $this->repositoryConfigProvider = $repositoryConfigProvider; } public function getServiceType(): string diff --git a/src/lib/Storage/AggregateMetricsProvider.php b/src/lib/Storage/AggregateMetricsProvider.php index 03d0d51..5967029 100644 --- a/src/lib/Storage/AggregateMetricsProvider.php +++ b/src/lib/Storage/AggregateMetricsProvider.php @@ -15,26 +15,21 @@ /** * @internal */ -final class AggregateMetricsProvider implements MetricsProvider +final readonly class AggregateMetricsProvider implements MetricsProvider { - /** @var \Symfony\Component\DependencyInjection\ServiceLocator<\Ibexa\SystemInfo\Storage\Metrics> */ - private ServiceLocator $metricsLocator; - /** - * @param \Symfony\Component\DependencyInjection\ServiceLocator<\Ibexa\SystemInfo\Storage\Metrics> $metrics + * @param ServiceLocator $metricsLocator */ - public function __construct(ServiceLocator $metrics) + public function __construct(private ServiceLocator $metricsLocator) { - $this->metricsLocator = $metrics; } - /** - * @throws \Ibexa\Bundle\SystemInfo\SystemInfo\Exception\MetricsNotFoundException - */ public function provideMetrics(string $identifier): Metrics { try { - return $this->metricsLocator->get($identifier); + $metrics = $this->metricsLocator->get($identifier); + + return $metrics; } catch (ServiceNotFoundException $e) { throw new MetricsNotFoundException($identifier, $e); } diff --git a/src/lib/Storage/Metrics/DraftsCountMetrics.php b/src/lib/Storage/Metrics/DraftsCountMetrics.php index 9e75161..6ec5c52 100644 --- a/src/lib/Storage/Metrics/DraftsCountMetrics.php +++ b/src/lib/Storage/Metrics/DraftsCountMetrics.php @@ -16,12 +16,9 @@ */ final class DraftsCountMetrics extends RepositoryConnectionAwareMetrics { - private const CONTENTOBJECT_VERSION_TABLE = 'ezcontentobject_version'; - private const CONTENTOBJECT_TABLE = 'ezcontentobject'; + private const string CONTENTOBJECT_VERSION_TABLE = 'ezcontentobject_version'; + private const string CONTENTOBJECT_TABLE = 'ezcontentobject'; - /** - * @throws \Doctrine\DBAL\Exception - */ public function getValue(): int { $queryBuilder = $this->connection->createQueryBuilder(); diff --git a/src/lib/Storage/Metrics/RepositoryConnectionAwareMetrics.php b/src/lib/Storage/Metrics/RepositoryConnectionAwareMetrics.php index 09cec6c..68bfadc 100644 --- a/src/lib/Storage/Metrics/RepositoryConnectionAwareMetrics.php +++ b/src/lib/Storage/Metrics/RepositoryConnectionAwareMetrics.php @@ -16,19 +16,12 @@ */ abstract class RepositoryConnectionAwareMetrics implements Metrics { - /** @var \Doctrine\DBAL\Connection */ - protected $connection; - abstract public function getValue(): int; - public function __construct(Connection $connection) + public function __construct(protected Connection $connection) { - $this->connection = $connection; } - /** - * @throws \Doctrine\DBAL\Exception - */ protected function getCountExpression(string $columnName): string { return $this->connection->getDatabasePlatform()->getCountExpression($columnName); diff --git a/src/lib/Tab/SystemInfo/SystemInfoTab.php b/src/lib/Tab/SystemInfo/SystemInfoTab.php index 200ba36..4da9f61 100644 --- a/src/lib/Tab/SystemInfo/SystemInfoTab.php +++ b/src/lib/Tab/SystemInfo/SystemInfoTab.php @@ -16,30 +16,14 @@ class SystemInfoTab extends AbstractControllerBasedTab { - /** @var string */ - protected $tabIdentifier; - - /** @var string */ - protected $collectorIdentifier; - - /** - * @param \Twig\Environment $twig - * @param \Symfony\Contracts\Translation\TranslatorInterface $translator - * @param \Symfony\Bridge\Twig\Extension\HttpKernelRuntime $httpKernelRuntime - * @param string $tabIdentifier - * @param string $collectorIdentifier - */ public function __construct( Environment $twig, TranslatorInterface $translator, HttpKernelRuntime $httpKernelRuntime, - string $tabIdentifier, - string $collectorIdentifier + protected string $tabIdentifier, + protected string $collectorIdentifier ) { parent::__construct($twig, $translator, $httpKernelRuntime); - - $this->tabIdentifier = $tabIdentifier; - $this->collectorIdentifier = $collectorIdentifier; } public function getControllerReference(array $parameters): ControllerReference diff --git a/src/lib/Tab/SystemInfo/TabFactory.php b/src/lib/Tab/SystemInfo/TabFactory.php index a80e770..32e9c58 100644 --- a/src/lib/Tab/SystemInfo/TabFactory.php +++ b/src/lib/Tab/SystemInfo/TabFactory.php @@ -14,36 +14,13 @@ class TabFactory { - /** @var \Symfony\Bridge\Twig\Extension\HttpKernelRuntime */ - protected $httpKernelRuntime; - - /** @var \Twig\Environment */ - protected $twig; - - /** @var \Symfony\Contracts\Translation\TranslatorInterface */ - protected $translator; - - /** - * @param \Twig\Environment $twig - * @param \Symfony\Contracts\Translation\TranslatorInterface $translator - * @param \Symfony\Bridge\Twig\Extension\HttpKernelRuntime $httpKernelRuntime - */ public function __construct( - Environment $twig, - TranslatorInterface $translator, - HttpKernelRuntime $httpKernelRuntime + protected Environment $twig, + protected TranslatorInterface $translator, + protected HttpKernelRuntime $httpKernelRuntime ) { - $this->twig = $twig; - $this->translator = $translator; - $this->httpKernelRuntime = $httpKernelRuntime; } - /** - * @param string $collectorIdentifier - * @param string|null $tabIdentifier - * - * @return SystemInfoTab - */ public function createTab(string $collectorIdentifier, ?string $tabIdentifier = null): SystemInfoTab { $tabIdentifier = $tabIdentifier ?? $collectorIdentifier; diff --git a/tests/bundle/SystemInfo/Registry/IdentifierBasedTest.php b/tests/bundle/SystemInfo/Registry/IdentifierBasedTest.php index ff1acb0..0689a58 100644 --- a/tests/bundle/SystemInfo/Registry/IdentifierBasedTest.php +++ b/tests/bundle/SystemInfo/Registry/IdentifierBasedTest.php @@ -17,7 +17,7 @@ class IdentifierBasedTest extends TestCase private IdentifierBased $registry; /** - * @var \PHPUnit\Framework\MockObject\MockObject[]|\Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector[] + * @var array */ private array $testItems; diff --git a/tests/lib/EventListener/SystemInfoTabGroupListenerTest.php b/tests/lib/EventListener/SystemInfoTabGroupListenerTest.php index 3ce3d30..b1c2da2 100644 --- a/tests/lib/EventListener/SystemInfoTabGroupListenerTest.php +++ b/tests/lib/EventListener/SystemInfoTabGroupListenerTest.php @@ -10,7 +10,6 @@ use Ibexa\AdminUi\Tab\Event\TabEvents; use Ibexa\AdminUi\Tab\Event\TabGroupEvent; use Ibexa\AdminUi\Tab\TabGroup; -use Ibexa\AdminUi\Tab\TabRegistry; use Ibexa\Bundle\SystemInfo\SystemInfo\SystemInfoCollectorRegistry; use Ibexa\SystemInfo\EventListener\SystemInfoTabGroupListener; use Ibexa\SystemInfo\Tab\SystemInfo\SystemInfoTab; @@ -19,22 +18,15 @@ class SystemInfoTabGroupListenerTest extends TestCase { - /** @var \Ibexa\AdminUi\Tab\Event\TabGroupEvent */ - private $event; + private TabGroupEvent $event; - /** @var \PHPUnit\Framework\MockObject\MockObject|\Ibexa\AdminUi\Tab\TabRegistry */ - private $tabRegistry; - - /** @var \PHPUnit\Framework\MockObject\MockObject|\Ibexa\SystemInfo\Tab\SystemInfo\TabFactory */ - private $tabFactory; + private TabFactory $tabFactory; protected function setUp(): void { parent::setUp(); - $this->tabRegistry = $this->createMock(TabRegistry::class); $this->tabFactory = $this->createMock(TabFactory::class); - $this->event = new TabGroupEvent(); } @@ -44,7 +36,7 @@ public function testOnTabGroupPreRenderWithNoSystemInfoTabGroup(): void $systemInfoCollectorRegistry->expects(self::never()) ->method('getIdentifiers'); - $systemInfoTabGroupListener = new SystemInfoTabGroupListener($this->tabRegistry, $this->tabFactory, $systemInfoCollectorRegistry); + $systemInfoTabGroupListener = new SystemInfoTabGroupListener($this->tabFactory, $systemInfoCollectorRegistry); $tabGroup = new TabGroup('some_name', []); $this->event->setData($tabGroup); @@ -59,7 +51,9 @@ public function testOnTabGroupPreRenderWithNoSystemInfoTabGroup(): void */ public function testOnTabGroupPreRender(array $identifiers): void { - $this->tabFactory + $tabFactory = $this->createMock(TabFactory::class); + + $tabFactory ->expects(self::exactly(count($identifiers))) ->method('createTab') ->willReturnMap( @@ -75,7 +69,7 @@ public function testOnTabGroupPreRender(array $identifiers): void ->method('getIdentifiers') ->willReturn($identifiers); - $systemInfoTabGroupListener = new SystemInfoTabGroupListener($this->tabRegistry, $this->tabFactory, $systemInfoCollectorRegistry); + $systemInfoTabGroupListener = new SystemInfoTabGroupListener($tabFactory, $systemInfoCollectorRegistry); $tabGroup = new TabGroup('systeminfo', []); $this->event->setData($tabGroup); @@ -86,7 +80,7 @@ public function testOnTabGroupPreRender(array $identifiers): void public function testSubscribedEvents(): void { $systemInfoCollectorRegistry = $this->createMock(SystemInfoCollectorRegistry::class); - $systemInfoTabGroupListener = new SystemInfoTabGroupListener($this->tabRegistry, $this->tabFactory, $systemInfoCollectorRegistry); + $systemInfoTabGroupListener = new SystemInfoTabGroupListener($this->tabFactory, $systemInfoCollectorRegistry); self::assertSame([TabEvents::TAB_GROUP_PRE_RENDER => ['onTabGroupPreRender', 10]], $systemInfoTabGroupListener::getSubscribedEvents()); } From 2ffabef5f168d4fc7f2bc6f1c484a782fa004603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Bia=C5=82czak?= Date: Fri, 28 Feb 2025 09:42:49 +0100 Subject: [PATCH 2/3] Applied Rector rules for improved type safety and interface replacements --- rector.php | 6 ++++ .../EzcHardwareSystemInfoCollectorTest.php | 13 +++------ .../EzcPhpSystemInfoCollectorTest.php | 13 +++------ .../IbexaSystemInfoCollectorTest.php | 4 +-- ...sonComposerLockSystemInfoCollectorTest.php | 4 +-- .../RepositorySystemInfoCollectorTest.php | 28 +++++-------------- .../VersionStabilityCheckerTest.php | 4 +-- 7 files changed, 27 insertions(+), 45 deletions(-) diff --git a/rector.php b/rector.php index 241a482..a6181ed 100644 --- a/rector.php +++ b/rector.php @@ -7,11 +7,14 @@ declare(strict_types=1); use Ibexa\Contracts\Rector\Sets\IbexaSetList; +use Ibexa\Rector\Rule\ReplaceInterfaceRector; use Rector\Config\RectorConfig; use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; use Rector\Set\ValueObject\SetList; use Rector\Symfony\Set\SymfonySetList; +use Rector\TypeDeclaration\Rector\Class_\TypedPropertyFromCreateMockAssignRector; use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector; +use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictSetUpRector; return RectorConfig::configure() ->withPaths([ @@ -29,5 +32,8 @@ ]) ->withRules([ TypedPropertyFromAssignsRector::class, + ReplaceInterfaceRector::class, + TypedPropertyFromStrictSetUpRector::class, + TypedPropertyFromCreateMockAssignRector::class, ClassPropertyAssignToConstructorPromotionRector::class, ]); diff --git a/tests/bundle/SystemInfo/Collector/EzcHardwareSystemInfoCollectorTest.php b/tests/bundle/SystemInfo/Collector/EzcHardwareSystemInfoCollectorTest.php index 90cc6c1..b9b7d66 100644 --- a/tests/bundle/SystemInfo/Collector/EzcHardwareSystemInfoCollectorTest.php +++ b/tests/bundle/SystemInfo/Collector/EzcHardwareSystemInfoCollectorTest.php @@ -10,19 +10,14 @@ use Ibexa\Bundle\SystemInfo\SystemInfo\Collector\EzcHardwareSystemInfoCollector; use Ibexa\Bundle\SystemInfo\SystemInfo\EzcSystemInfoWrapper; use Ibexa\Bundle\SystemInfo\SystemInfo\Value\HardwareSystemInfo; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class EzcHardwareSystemInfoCollectorTest extends TestCase { - /** - * @var \Ibexa\Bundle\SystemInfo\SystemInfo\EzcSystemInfoWrapper|\PHPUnit\Framework\MockObject\MockObject - */ - private $ezcSystemInfoMock; + private EzcSystemInfoWrapper&MockObject $ezcSystemInfoMock; - /** - * @var \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\EzcHardwareSystemInfoCollector - */ - private $ezcHardware; + private EzcHardwareSystemInfoCollector $ezcHardware; protected function setUp(): void { @@ -39,7 +34,7 @@ protected function setUp(): void } /** - * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\EzcHardwareSystemInfoCollector::collect() + * @covers \EzcHardwareSystemInfoCollector::collect */ public function testCollect(): void { diff --git a/tests/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollectorTest.php b/tests/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollectorTest.php index 0c4534f..8276d36 100644 --- a/tests/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollectorTest.php +++ b/tests/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollectorTest.php @@ -11,19 +11,14 @@ use Ibexa\Bundle\SystemInfo\SystemInfo\Collector\EzcPhpSystemInfoCollector; use Ibexa\Bundle\SystemInfo\SystemInfo\EzcSystemInfoWrapper; use Ibexa\Bundle\SystemInfo\SystemInfo\Value\PhpSystemInfo; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class EzcPhpSystemInfoCollectorTest extends TestCase { - /** - * @var \Ibexa\Bundle\SystemInfo\SystemInfo\EzcSystemInfoWrapper|\PHPUnit\Framework\MockObject\MockObject - */ - private $ezcSystemInfoMock; + private EzcSystemInfoWrapper&MockObject $ezcSystemInfoMock; - /** - * @var \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\EzcPhpSystemInfoCollector - */ - private $ezcPhpCollector; + private EzcPhpSystemInfoCollector $ezcPhpCollector; protected function setUp(): void { @@ -50,7 +45,7 @@ protected function setUp(): void } /** - * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\EzcPhpSystemInfoCollector::collect() + * @covers \EzcPhpSystemInfoCollector::collect */ public function testCollect(): void { diff --git a/tests/bundle/SystemInfo/Collector/IbexaSystemInfoCollectorTest.php b/tests/bundle/SystemInfo/Collector/IbexaSystemInfoCollectorTest.php index 73fdef7..8bf3800 100644 --- a/tests/bundle/SystemInfo/Collector/IbexaSystemInfoCollectorTest.php +++ b/tests/bundle/SystemInfo/Collector/IbexaSystemInfoCollectorTest.php @@ -13,12 +13,12 @@ use Ibexa\Bundle\SystemInfo\SystemInfo\Value\IbexaSystemInfo; use Ibexa\Contracts\Core\Ibexa; use Ibexa\SystemInfo\VersionStability\VersionStabilityChecker; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class IbexaSystemInfoCollectorTest extends TestCase { - /** @var \Ibexa\SystemInfo\VersionStability\VersionStabilityChecker|\PHPUnit\Framework\MockObject\MockObject */ - private $versionStabilityChecker; + private VersionStabilityChecker&MockObject $versionStabilityChecker; public function setUp(): void { diff --git a/tests/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollectorTest.php b/tests/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollectorTest.php index 659f255..ee0a693 100644 --- a/tests/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollectorTest.php +++ b/tests/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollectorTest.php @@ -14,12 +14,12 @@ use Ibexa\Bundle\SystemInfo\SystemInfo\Value\ComposerPackage; use Ibexa\Bundle\SystemInfo\SystemInfo\Value\ComposerSystemInfo; use Ibexa\SystemInfo\VersionStability\VersionStabilityChecker; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class JsonComposerLockSystemInfoCollectorTest extends TestCase { - /** @var \Ibexa\SystemInfo\VersionStability\VersionStabilityChecker|\PHPUnit\Framework\MockObject\MockObject */ - private $versionStabilityChecker; + private VersionStabilityChecker&MockObject $versionStabilityChecker; public function setUp(): void { diff --git a/tests/bundle/SystemInfo/Collector/RepositorySystemInfoCollectorTest.php b/tests/bundle/SystemInfo/Collector/RepositorySystemInfoCollectorTest.php index 34ecba3..d96515a 100644 --- a/tests/bundle/SystemInfo/Collector/RepositorySystemInfoCollectorTest.php +++ b/tests/bundle/SystemInfo/Collector/RepositorySystemInfoCollectorTest.php @@ -14,34 +14,20 @@ use Ibexa\Bundle\SystemInfo\SystemInfo\Value\RepositorySystemInfo; use Ibexa\SystemInfo\Storage\Metrics; use Ibexa\SystemInfo\Storage\MetricsProvider; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class RepositorySystemInfoCollectorTest extends TestCase { - /** - * @var \Doctrine\DBAL\Connection|\PHPUnit\Framework\MockObject\MockObject - */ - private $dbalConnectionMock; + private MockObject $dbalConnectionMock; - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform&\PHPUnit\Framework\MockObject\MockObject - */ - private $dbalPlatformMock; + private MockObject $dbalPlatformMock; - /** - * @var \PHPUnit\Framework\MockObject\MockObject - */ - private $metricsProviderMock; + private MockObject $metricsProviderMock; - /** - * @var \PHPUnit\Framework\MockObject\MockObject - */ - private $metricsMock; + private MockObject $metricsMock; - /** - * @var \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\RepositorySystemInfoCollector - */ - private $repositoryCollector; + private RepositorySystemInfoCollector $repositoryCollector; protected function setUp(): void { @@ -57,7 +43,7 @@ protected function setUp(): void } /** - * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\RepositorySystemInfoCollector::collect() + * @covers \RepositorySystemInfoCollector::collect */ public function testCollect(): void { diff --git a/tests/lib/VersionStability/VersionStabilityCheckerTest.php b/tests/lib/VersionStability/VersionStabilityCheckerTest.php index 3453b73..cd1e298 100644 --- a/tests/lib/VersionStability/VersionStabilityCheckerTest.php +++ b/tests/lib/VersionStability/VersionStabilityCheckerTest.php @@ -10,12 +10,12 @@ use Ibexa\SystemInfo\Value\Stability; use Ibexa\SystemInfo\VersionStability\ComposerVersionStabilityChecker; +use Ibexa\SystemInfo\VersionStability\VersionStabilityChecker; use PHPUnit\Framework\TestCase; final class VersionStabilityCheckerTest extends TestCase { - /** @var \Ibexa\SystemInfo\VersionStability\VersionStabilityChecker */ - private $versionStabilityChecker; + private VersionStabilityChecker $versionStabilityChecker; public function setUp(): void { From bd2044a9b228b5eaa4b763d40b8c96f9a2000367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Bia=C5=82czak?= Date: Fri, 28 Feb 2025 10:45:32 +0100 Subject: [PATCH 3/3] Refactored after review --- src/bundle/Resources/config/services.yaml | 2 +- ...rationSymfonyKernelSystemInfoCollector.php | 4 +++- .../Collector/IbexaSystemInfoCollector.php | 20 +++++++++---------- .../SystemInfo/Value/ServicesSystemInfo.php | 17 +--------------- src/lib/Service/AggregateServiceProvider.php | 6 ++---- src/lib/Storage/AggregateMetricsProvider.php | 6 ++---- src/lib/Tab/SystemInfo/SystemInfoTab.php | 4 ++-- .../Registry/IdentifierBasedTest.php | 2 +- 8 files changed, 22 insertions(+), 39 deletions(-) diff --git a/src/bundle/Resources/config/services.yaml b/src/bundle/Resources/config/services.yaml index 590e22f..b88dc21 100644 --- a/src/bundle/Resources/config/services.yaml +++ b/src/bundle/Resources/config/services.yaml @@ -47,7 +47,7 @@ services: # SystemInfoCollectors Ibexa\Bundle\SystemInfo\SystemInfo\Collector\IbexaSystemInfoCollector: arguments: - $systemInfoCollector: '@Ibexa\Bundle\SystemInfo\SystemInfo\Collector\JsonComposerLockSystemInfoCollector' + $composerCollector: '@Ibexa\Bundle\SystemInfo\SystemInfo\Collector\JsonComposerLockSystemInfoCollector' $kernelProjectDir: '%kernel.project_dir%' tags: - { name: ibexa.system_info.collector, identifier: ibexa } diff --git a/src/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollector.php b/src/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollector.php index 536c1de..65a0ae6 100644 --- a/src/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollector.php @@ -15,9 +15,11 @@ */ class ConfigurationSymfonyKernelSystemInfoCollector implements SystemInfoCollector { + /** + * @param array $bundles + */ public function __construct( private readonly Kernel $kernel, - /** @var array */ private array $bundles = [] ) { } diff --git a/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php b/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php index 91f8122..5521ad3 100644 --- a/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php @@ -34,7 +34,7 @@ class IbexaSystemInfoCollector implements SystemInfoCollector * * Mainly for usage for trial to calculate TTL expiry. */ - public const RELEASES = [ + public const array RELEASES = [ '2.5' => '2019-03-29T16:59:59+00:00', '3.0' => '2020-04-02T23:59:59+00:00', '3.1' => '2020-07-15T23:59:59+00:00', @@ -58,7 +58,7 @@ class IbexaSystemInfoCollector implements SystemInfoCollector * * @see: https://support.ibexa.co/Public/Service-Life */ - public const EOM = [ + public const array EOM = [ '2.5' => '2022-03-29T23:59:59+00:00', '3.0' => '2020-07-10T23:59:59+00:00', '3.1' => '2020-11-30T23:59:59+00:00', @@ -77,7 +77,7 @@ class IbexaSystemInfoCollector implements SystemInfoCollector * * @see: https://support.ibexa.co/Public/Service-Life */ - public const EOL = [ + public const array EOL = [ '2.5' => '2024-03-29T23:59:59+00:00', '3.0' => '2020-08-31T23:59:59+00:00', '3.1' => '2021-01-30T23:59:59+00:00', @@ -92,30 +92,30 @@ class IbexaSystemInfoCollector implements SystemInfoCollector /** * Vendors we watch for stability (and potentially more). */ - public const PACKAGE_WATCH_REGEX = '/^(doctrine|ezsystems|silversolutions|symfony)\//'; + public const string PACKAGE_WATCH_REGEX = '/^(doctrine|ezsystems|silversolutions|symfony)\//'; /** * Packages that identify installation as "Headless". */ - public const HEADLESS_PACKAGES = [ + public const array HEADLESS_PACKAGES = [ 'ibexa/headless', ]; - public const EXPERIENCE_PACKAGES = [ + public const array EXPERIENCE_PACKAGES = [ 'ibexa/experience', ]; /** * Packages that identify installation as "Commerce". */ - public const COMMERCE_PACKAGES = [ + public const array COMMERCE_PACKAGES = [ 'ibexa/commerce', ]; private ?ComposerSystemInfo $composerInfo = null; public function __construct( - private readonly SystemInfoCollector $systemInfoCollector, + private readonly SystemInfoCollector $composerCollector, private readonly string $kernelProjectDir ) { } @@ -124,7 +124,7 @@ public function collect(): IbexaSystemInfo { if ($this->composerInfo === null) { try { - $composerInfo = $this->systemInfoCollector->collect(); + $composerInfo = $this->composerCollector->collect(); if ($composerInfo instanceof ComposerSystemInfo) { $this->composerInfo = $composerInfo; } @@ -221,7 +221,7 @@ private static function getStability(ComposerSystemInfo $composerInfo): string } /** - * @param string[] $packageNames List of package names to check. + * @param string[] $packageNames */ private static function hasAnyPackage( ComposerSystemInfo $composerInfo, diff --git a/src/bundle/SystemInfo/Value/ServicesSystemInfo.php b/src/bundle/SystemInfo/Value/ServicesSystemInfo.php index 4b2328f..1e5e951 100644 --- a/src/bundle/SystemInfo/Value/ServicesSystemInfo.php +++ b/src/bundle/SystemInfo/Value/ServicesSystemInfo.php @@ -10,26 +10,11 @@ /** * Value for information about services used within the project. */ -final class ServicesSystemInfo implements SystemInfo +final readonly class ServicesSystemInfo implements SystemInfo { public function __construct( - /** - * Search engine. - * - * Example: Solr - */ private string $searchEngine, - /** - * Reverse proxy handling HTTP caching. - * - * Example: Fastly - */ private string $httpCacheProxy, - /** - * Persistence cache adapter. - * - * Example: Redis - */ private string $persistenceCacheAdapter ) { } diff --git a/src/lib/Service/AggregateServiceProvider.php b/src/lib/Service/AggregateServiceProvider.php index 316143c..983267f 100644 --- a/src/lib/Service/AggregateServiceProvider.php +++ b/src/lib/Service/AggregateServiceProvider.php @@ -18,7 +18,7 @@ final readonly class AggregateServiceProvider implements ServiceProviderInterface { /** - * @param ServiceLocator $serviceLocator + * @param \Symfony\Component\DependencyInjection\ServiceLocator<\Ibexa\SystemInfo\Service\ServiceInfo> $serviceLocator */ public function __construct(private ServiceLocator $serviceLocator) { @@ -27,9 +27,7 @@ public function __construct(private ServiceLocator $serviceLocator) public function getServiceType(string $identifier): string { try { - $service = $this->serviceLocator->get($identifier); - - return $service->getServiceType($identifier); + return $this->serviceLocator->get($identifier)->getServiceType(); } catch (ServiceNotFoundException $e) { throw new SystemInfoServiceNotFoundException($identifier, $e); } diff --git a/src/lib/Storage/AggregateMetricsProvider.php b/src/lib/Storage/AggregateMetricsProvider.php index 5967029..3dc2729 100644 --- a/src/lib/Storage/AggregateMetricsProvider.php +++ b/src/lib/Storage/AggregateMetricsProvider.php @@ -18,7 +18,7 @@ final readonly class AggregateMetricsProvider implements MetricsProvider { /** - * @param ServiceLocator $metricsLocator + * @param \Symfony\Component\DependencyInjection\ServiceLocator<\Ibexa\SystemInfo\Storage\Metrics> $metricsLocator */ public function __construct(private ServiceLocator $metricsLocator) { @@ -27,9 +27,7 @@ public function __construct(private ServiceLocator $metricsLocator) public function provideMetrics(string $identifier): Metrics { try { - $metrics = $this->metricsLocator->get($identifier); - - return $metrics; + return $this->metricsLocator->get($identifier); } catch (ServiceNotFoundException $e) { throw new MetricsNotFoundException($identifier, $e); } diff --git a/src/lib/Tab/SystemInfo/SystemInfoTab.php b/src/lib/Tab/SystemInfo/SystemInfoTab.php index 4da9f61..cda7894 100644 --- a/src/lib/Tab/SystemInfo/SystemInfoTab.php +++ b/src/lib/Tab/SystemInfo/SystemInfoTab.php @@ -20,8 +20,8 @@ public function __construct( Environment $twig, TranslatorInterface $translator, HttpKernelRuntime $httpKernelRuntime, - protected string $tabIdentifier, - protected string $collectorIdentifier + protected readonly string $tabIdentifier, + protected readonly string $collectorIdentifier ) { parent::__construct($twig, $translator, $httpKernelRuntime); } diff --git a/tests/bundle/SystemInfo/Registry/IdentifierBasedTest.php b/tests/bundle/SystemInfo/Registry/IdentifierBasedTest.php index 0689a58..babde3a 100644 --- a/tests/bundle/SystemInfo/Registry/IdentifierBasedTest.php +++ b/tests/bundle/SystemInfo/Registry/IdentifierBasedTest.php @@ -17,7 +17,7 @@ class IdentifierBasedTest extends TestCase private IdentifierBased $registry; /** - * @var array + * @var array */ private array $testItems;