diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index fb338b9..a984055 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,25 +1,7 @@ parameters: ignoreErrors: - - - message: '#^Binary operation "\." between array\|bool\|float\|int\|string\|null and ''/vendor/'' results in an error\.$#' - identifier: binaryOp.invalid - count: 1 - path: src/bundle/DependencyInjection/IbexaSystemInfoExtension.php - - - - message: '#^Method Ibexa\\Bundle\\SystemInfo\\DependencyInjection\\IbexaSystemInfoExtension\:\:getConfiguration\(\) has parameter \$config with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/bundle/DependencyInjection/IbexaSystemInfoExtension.php - - message: '#^Parameter \#4 \$condition of method Doctrine\\DBAL\\Query\\QueryBuilder\:\:innerJoin\(\) expects string\|null, Doctrine\\DBAL\\Query\\Expression\\CompositeExpression given\.$#' 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/src/bundle/Command/SystemInfoDumpCommand.php b/src/bundle/Command/SystemInfoDumpCommand.php index 0a7f02a..f2b0c48 100644 --- a/src/bundle/Command/SystemInfoDumpCommand.php +++ b/src/bundle/Command/SystemInfoDumpCommand.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\Command; @@ -22,15 +23,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(); } @@ -39,10 +35,10 @@ protected function configure(): void $this ->setHelp( <<<'EOD' -By default it dumps information from all available information collectors. -You can specify one or more collectors as arguments, e.g. 'php database hardware'. -To get a list if available collectors, use '--list-info-collectors' -EOD + By default it dumps information from all available information collectors. + You can specify one or more collectors as arguments, e.g. 'php database hardware'. + To get a list if available collectors, use '--list-info-collectors' + EOD ) ->addOption( 'list-info-collectors', @@ -65,16 +61,11 @@ 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')) { $output->writeln('Available info collectors:', OutputInterface::OUTPUT_NORMAL); + foreach ($this->systemInfoCollectorRegistry->getIdentifiers() as $identifier) { $output->writeln(" $identifier", OutputInterface::OUTPUT_NORMAL); } diff --git a/src/bundle/Controller/SystemInfoController.php b/src/bundle/Controller/SystemInfoController.php index c58f857..9df073d 100644 --- a/src/bundle/Controller/SystemInfoController.php +++ b/src/bundle/Controller/SystemInfoController.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\Controller; @@ -13,29 +14,20 @@ use Ibexa\Core\MVC\Symfony\Security\Authorization\Attribute; use Symfony\Component\HttpFoundation\Response; -class SystemInfoController extends AdminUiController +final class SystemInfoController extends AdminUiController { - protected SystemInfoCollectorRegistry $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 { parent::performAccessCheck(); + $this->denyAccessUnlessGranted(new Attribute('setup', 'system_info')); } - /** - * Renders the system information page. - * - * @return \Symfony\Component\HttpFoundation\Response - */ public function infoAction(): Response { return $this->render('@ibexadesign/system_info/info.html.twig', [ @@ -48,9 +40,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/Compiler/OutputFormatPass.php b/src/bundle/DependencyInjection/Compiler/OutputFormatPass.php index 4f6734b..b402266 100644 --- a/src/bundle/DependencyInjection/Compiler/OutputFormatPass.php +++ b/src/bundle/DependencyInjection/Compiler/OutputFormatPass.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\DependencyInjection\Compiler; @@ -12,13 +13,8 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; -class OutputFormatPass implements CompilerPassInterface +final readonly class OutputFormatPass implements CompilerPassInterface { - /** - * Registers the OutputFormat tagged services into the output format registry. - * - * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container - */ public function process(ContainerBuilder $container): void { if (!$container->has(OutputFormatRegistry::class)) { diff --git a/src/bundle/DependencyInjection/Compiler/SystemInfoCollectorPass.php b/src/bundle/DependencyInjection/Compiler/SystemInfoCollectorPass.php index 2b118aa..c313004 100644 --- a/src/bundle/DependencyInjection/Compiler/SystemInfoCollectorPass.php +++ b/src/bundle/DependencyInjection/Compiler/SystemInfoCollectorPass.php @@ -13,7 +13,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; -class SystemInfoCollectorPass implements CompilerPassInterface +final readonly class SystemInfoCollectorPass implements CompilerPassInterface { public function process(ContainerBuilder $container): void { diff --git a/src/bundle/DependencyInjection/Compiler/SystemInfoTabGroupPass.php b/src/bundle/DependencyInjection/Compiler/SystemInfoTabGroupPass.php index 6507435..f1b0248 100644 --- a/src/bundle/DependencyInjection/Compiler/SystemInfoTabGroupPass.php +++ b/src/bundle/DependencyInjection/Compiler/SystemInfoTabGroupPass.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\DependencyInjection\Compiler; @@ -13,10 +14,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; -/** - * {@inheritdoc} - */ -class SystemInfoTabGroupPass implements CompilerPassInterface +final readonly class SystemInfoTabGroupPass implements CompilerPassInterface { /** * @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException diff --git a/src/bundle/DependencyInjection/IbexaSystemInfoExtension.php b/src/bundle/DependencyInjection/IbexaSystemInfoExtension.php index 507c69c..2b8d428 100644 --- a/src/bundle/DependencyInjection/IbexaSystemInfoExtension.php +++ b/src/bundle/DependencyInjection/IbexaSystemInfoExtension.php @@ -18,17 +18,20 @@ use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\DependencyInjection\Loader; -class IbexaSystemInfoExtension extends Extension implements PrependExtensionInterface +final 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 { return self::EXTENSION_NAME; } + /** + * @param array $config + */ public function getConfiguration(array $config, ContainerBuilder $container): Configuration { return new Configuration(); @@ -54,7 +57,6 @@ public function load(array $configs, ContainerBuilder $container): void $container->setParameter( 'ibexa.system_info.powered_by.name', $this->getPoweredByName( - $container, $config['system_info']['powered_by']['release'] ) ); @@ -66,12 +68,10 @@ public function prepend(ContainerBuilder $container): void $this->prependJMSTranslation($container); } - private function getPoweredByName(ContainerBuilder $container, ?string $release): string + private function getPoweredByName(?string $release): string { - $vendor = $container->getParameter('kernel.project_dir') . '/vendor/'; - // Autodetect product name - $name = self::getNameByPackages($vendor); + $name = self::getNameByPackages(); if ($release === 'major') { $name .= ' v' . (int)Ibexa::VERSION; @@ -112,8 +112,10 @@ public static function getEditionByPackages(): string return 'oss'; } - public static function getNameByPackages(string $vendor = null): string + public static function getNameByPackages(): string { - return IbexaSystemInfo::PRODUCT_NAME_VARIANTS[self::getEditionByPackages()]; + return IbexaSystemInfo::PRODUCT_NAME_VARIANTS[ + self::getEditionByPackages() + ]; } } diff --git a/src/bundle/EventSubscriber/AddXPoweredByHeader.php b/src/bundle/EventSubscriber/AddXPoweredByHeader.php index cac4a90..3607dc9 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 +final readonly class AddXPoweredByHeader implements EventSubscriberInterface { - /** - * @var string If empty, this powered by header is skipped. - */ - private string $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/IbexaSystemInfoBundle.php b/src/bundle/IbexaSystemInfoBundle.php index 1426a81..4cddb1a 100644 --- a/src/bundle/IbexaSystemInfoBundle.php +++ b/src/bundle/IbexaSystemInfoBundle.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo; @@ -15,19 +16,17 @@ use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; use Symfony\Component\HttpKernel\Bundle\Bundle; -class IbexaSystemInfoBundle extends Bundle +final class IbexaSystemInfoBundle extends Bundle { public function build(ContainerBuilder $container): void { parent::build($container); + $container->addCompilerPass(new SystemInfoCollectorPass()); $container->addCompilerPass(new OutputFormatPass()); $container->addCompilerPass(new SystemInfoTabGroupPass()); } - /** - * {@inheritdoc} - */ public function getContainerExtension(): ExtensionInterface { return new IbexaSystemInfoExtension(); diff --git a/src/bundle/Resources/config/services.yaml b/src/bundle/Resources/config/services.yaml index e414d45..444d028 100644 --- a/src/bundle/Resources/config/services.yaml +++ b/src/bundle/Resources/config/services.yaml @@ -41,14 +41,13 @@ services: Ibexa\Bundle\SystemInfo\SystemInfo\OutputFormatRegistry: ~ - Ibexa\Bundle\SystemInfo\SystemInfo\EzcSystemInfoWrapper: + Ibexa\Bundle\SystemInfo\SystemInfo\SystemInfoWrapper: lazy: true # SystemInfoCollectors Ibexa\Bundle\SystemInfo\SystemInfo\Collector\IbexaSystemInfoCollector: arguments: - $composerCollector: '@Ibexa\Bundle\SystemInfo\SystemInfo\Collector\JsonComposerLockSystemInfoCollector' - $kernelProjectDir: '%kernel.project_dir%' + $collector: '@Ibexa\Bundle\SystemInfo\SystemInfo\Collector\JsonComposerLockSystemInfoCollector' tags: - { name: ibexa.system_info.collector, identifier: ibexa } @@ -69,19 +68,19 @@ services: lazy: true autowire: true arguments: - $db: '@ibexa.persistence.connection' + $connection: '@ibexa.persistence.connection' tags: - { name: ibexa.system_info.collector, identifier: repository } - Ibexa\Bundle\SystemInfo\SystemInfo\Collector\EzcHardwareSystemInfoCollector: + Ibexa\Bundle\SystemInfo\SystemInfo\Collector\HardwareSystemInfoCollector: arguments: - - '@Ibexa\Bundle\SystemInfo\SystemInfo\EzcSystemInfoWrapper' + - '@Ibexa\Bundle\SystemInfo\SystemInfo\SystemInfoWrapper' tags: - { name: ibexa.system_info.collector, identifier: hardware } - Ibexa\Bundle\SystemInfo\SystemInfo\Collector\EzcPhpSystemInfoCollector: + Ibexa\Bundle\SystemInfo\SystemInfo\Collector\PhpSystemInfoCollector: arguments: - - '@Ibexa\Bundle\SystemInfo\SystemInfo\EzcSystemInfoWrapper' + - '@Ibexa\Bundle\SystemInfo\SystemInfo\SystemInfoWrapper' tags: - { name: ibexa.system_info.collector, identifier: php } @@ -108,7 +107,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 +157,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/Resources/config/view.yaml b/src/bundle/Resources/config/view.yaml index 9a75498..9de297b 100644 --- a/src/bundle/Resources/config/view.yaml +++ b/src/bundle/Resources/config/view.yaml @@ -13,7 +13,6 @@ services: public: true Ibexa\Bundle\SystemInfo\View\SystemInfoViewBuilder: - class: Ibexa\Bundle\SystemInfo\View\SystemInfoViewBuilder arguments: - '@Ibexa\Core\MVC\Symfony\View\Configurator\ViewProvider' - '@Ibexa\Bundle\SystemInfo\SystemInfo\Registry\IdentifierBased' diff --git a/src/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollector.php b/src/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollector.php index a8d319b..2d8c8a6 100644 --- a/src/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollector.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\Collector; @@ -13,13 +14,8 @@ /** * Collects information about the Symfony kernel we are using. */ -class ConfigurationSymfonyKernelSystemInfoCollector implements SystemInfoCollector +final class ConfigurationSymfonyKernelSystemInfoCollector implements SystemInfoCollector { - /** - * Symfony kernel. - */ - private Kernel $kernel; - /** * Installed bundles. * @@ -31,24 +27,14 @@ class ConfigurationSymfonyKernelSystemInfoCollector implements SystemInfoCollect * 'AsseticBundle' => 'Symfony\\Bundle\\AsseticBundle\\AsseticBundle', * ) * - * @var array - */ - private array $bundles; - - /** * @param array $bundles */ - public function __construct(Kernel $kernel, array $bundles) - { - $this->kernel = $kernel; - $this->bundles = $bundles; + public function __construct( + private readonly Kernel $kernel, + 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/HardwareSystemInfoCollector.php similarity index 51% rename from src/bundle/SystemInfo/Collector/EzcHardwareSystemInfoCollector.php rename to src/bundle/SystemInfo/Collector/HardwareSystemInfoCollector.php index 35da758..73689d5 100644 --- a/src/bundle/SystemInfo/Collector/EzcHardwareSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/HardwareSystemInfoCollector.php @@ -4,38 +4,34 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\Collector; -use Ibexa\Bundle\SystemInfo\SystemInfo\EzcSystemInfoWrapper; +use Ibexa\Bundle\SystemInfo\SystemInfo\SystemInfoWrapper; use Ibexa\Bundle\SystemInfo\SystemInfo\Value\HardwareSystemInfo; /** * Collects hardware system information using zetacomponents/sysinfo. */ -class EzcHardwareSystemInfoCollector implements SystemInfoCollector +final readonly class HardwareSystemInfoCollector implements SystemInfoCollector { - private EzcSystemInfoWrapper $ezcSystemInfo; - - public function __construct(EzcSystemInfoWrapper $ezcSystemInfo) + public function __construct(private SystemInfoWrapper $systemInfoWrapper) { - $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 { return new HardwareSystemInfo([ - 'cpuType' => $this->ezcSystemInfo->cpuType, - 'cpuSpeed' => $this->ezcSystemInfo->cpuSpeed, - 'cpuCount' => $this->ezcSystemInfo->cpuCount, - 'memorySize' => $this->ezcSystemInfo->memorySize, + 'cpuType' => $this->systemInfoWrapper->cpuType, + 'cpuSpeed' => $this->systemInfoWrapper->cpuSpeed, + 'cpuCount' => $this->systemInfoWrapper->cpuCount, + 'memorySize' => $this->systemInfoWrapper->memorySize, ]); } } diff --git a/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php b/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php index 66459c3..4e81a14 100644 --- a/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\Collector; @@ -27,14 +28,14 @@ * - Or be able to tell if installation is greatly outdated * - Be able to give heads up when installation is approaching its End of Life. */ -class IbexaSystemInfoCollector implements SystemInfoCollector +final class IbexaSystemInfoCollector implements SystemInfoCollector { /** * Estimated release dates for given releases. * * 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', @@ -61,7 +62,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', @@ -82,7 +83,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', @@ -99,74 +100,53 @@ 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', ]; - /** - * @var \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector - */ - private SystemInfoCollector $systemInfoCollector; - - /** - * @var \Ibexa\Bundle\SystemInfo\SystemInfo\Value\ComposerSystemInfo|null - */ private ?ComposerSystemInfo $composerInfo = null; - private string $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|JsonComposerLockSystemInfoCollector $collector ) { - $this->systemInfoCollector = $composerCollector; - $this->kernelProjectDir = $kernelProjectDir; } /** * Collects information about the Ibexa distribution and version. * - * @throws \Exception - * - * @return \Ibexa\Bundle\SystemInfo\SystemInfo\Value\IbexaSystemInfo + * @throws \Ibexa\Bundle\SystemInfo\SystemInfo\Exception\ComposerJsonFileNotFoundException */ public function collect(): IbexaSystemInfo { if ($this->composerInfo === null) { try { - $composerInfo = $this->systemInfoCollector->collect(); + $composerInfo = $this->collector->collect(); if ($composerInfo instanceof ComposerSystemInfo) { $this->composerInfo = $composerInfo; } - } catch (ComposerLockFileNotFoundException | ComposerFileValidationException $e) { + } catch (ComposerLockFileNotFoundException | ComposerFileValidationException) { // do nothing } } - $vendorDir = sprintf('%s/vendor/', $this->kernelProjectDir); - - $ibexa = new IbexaSystemInfo([ - 'name' => IbexaSystemInfoExtension::getNameByPackages($vendorDir), - ]); + $ibexa = new IbexaSystemInfo(); + $ibexa->name = IbexaSystemInfoExtension::getNameByPackages(); $this->setReleaseInfo($ibexa); $this->extractComposerInfo($ibexa); @@ -207,6 +187,7 @@ private function extractComposerInfo(IbexaSystemInfo $ibexa): void self::EXPERIENCE_PACKAGES, self::COMMERCE_PACKAGES ); + $ibexa->isEnterprise = self::hasAnyPackage($this->composerInfo, $dxpPackages); $ibexa->lowestStability = self::getStability($this->composerInfo); } diff --git a/src/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php b/src/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php index 55c73ae..5cb870b 100644 --- a/src/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php @@ -4,10 +4,12 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); 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; @@ -17,15 +19,9 @@ /** * Collects information about installed Composer packages, by reading json from composer.lock. */ -class JsonComposerLockSystemInfoCollector implements SystemInfoCollector +final class JsonComposerLockSystemInfoCollector implements SystemInfoCollector { - public const IBEXA_OSS_PACKAGE = 'ibexa/oss'; - - private VersionStabilityChecker $versionStabilityChecker; - - private string $lockFile; - - private string $jsonFile; + public const string IBEXA_OSS_PACKAGE = 'ibexa/oss'; /** * The collected value, cached in case info is collected by other collectors. @@ -33,21 +29,18 @@ class JsonComposerLockSystemInfoCollector implements SystemInfoCollector 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. + * @throws \Ibexa\Bundle\SystemInfo\SystemInfo\Exception\ComposerLockFileNotFoundException if the composer.lock file was not found. + * @throws \Ibexa\Bundle\SystemInfo\SystemInfo\Exception\ComposerJsonFileNotFoundException if the composer.json file was not found. + * @throws \Ibexa\Bundle\SystemInfo\SystemInfo\Exception\ComposerFileValidationException if composer.lock of composer.json are not valid. */ public function collect(): ComposerSystemInfo { @@ -104,18 +97,18 @@ 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])) { $stabilityFlag = (int)$lockData['stability-flags'][$package->name]; - if (isset(Stability::STABILITIES[$stabilityFlag])) { - $package->stability = Stability::STABILITIES[$stabilityFlag]; - } + $package->stability = Stability::STABILITIES[$stabilityFlag] ?? null; + } else { + $package->stability = null; } if (isset($rootAliases[$package->name])) { @@ -161,12 +154,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/EzcPhpSystemInfoCollector.php b/src/bundle/SystemInfo/Collector/PhpSystemInfoCollector.php similarity index 55% rename from src/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollector.php rename to src/bundle/SystemInfo/Collector/PhpSystemInfoCollector.php index 16b89f1..37e2e39 100644 --- a/src/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/PhpSystemInfoCollector.php @@ -4,22 +4,20 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\Collector; -use Ibexa\Bundle\SystemInfo\SystemInfo\EzcSystemInfoWrapper; +use Ibexa\Bundle\SystemInfo\SystemInfo\SystemInfoWrapper; use Ibexa\Bundle\SystemInfo\SystemInfo\Value\PhpSystemInfo; /** * Collects PHP information using zetacomponents/sysinfo. */ -class EzcPhpSystemInfoCollector implements SystemInfoCollector +final readonly class PhpSystemInfoCollector implements SystemInfoCollector { - private EzcSystemInfoWrapper $ezcSystemInfo; - - public function __construct(EzcSystemInfoWrapper $ezcSystemInfo) + public function __construct(private SystemInfoWrapper $wrapper) { - $this->ezcSystemInfo = $ezcSystemInfo; } /** @@ -34,14 +32,14 @@ public function collect(): PhpSystemInfo 'acceleratorEnabled' => false, ]; - if ($this->ezcSystemInfo->phpAccelerator) { + if ($this->wrapper->phpAccelerator) { $properties = array_merge( $properties, [ - 'acceleratorEnabled' => $this->ezcSystemInfo->phpAccelerator->isEnabled, - 'acceleratorName' => $this->ezcSystemInfo->phpAccelerator->name, - 'acceleratorURL' => $this->ezcSystemInfo->phpAccelerator->url, - 'acceleratorVersion' => $this->ezcSystemInfo->phpAccelerator->versionString, + 'acceleratorEnabled' => $this->wrapper->phpAccelerator->isEnabled, + 'acceleratorName' => $this->wrapper->phpAccelerator->name, + 'acceleratorURL' => $this->wrapper->phpAccelerator->url, + 'acceleratorVersion' => $this->wrapper->phpAccelerator->versionString, ] ); } diff --git a/src/bundle/SystemInfo/Collector/RepositorySystemInfoCollector.php b/src/bundle/SystemInfo/Collector/RepositorySystemInfoCollector.php index ec4bd4c..7993e1e 100644 --- a/src/bundle/SystemInfo/Collector/RepositorySystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/RepositorySystemInfoCollector.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\Collector; @@ -15,22 +16,12 @@ /** * Collects database information using Doctrine. */ -class RepositorySystemInfoCollector implements SystemInfoCollector +readonly class RepositorySystemInfoCollector implements SystemInfoCollector { - /** - * The database connection, only used to retrieve some information on the database itself. - */ - private Connection $connection; - - /** - * The metrics provider needed to populate Repository value object consisting of several metrics. - */ - private MetricsProvider $metricsProvider; - - public function __construct(Connection $db, MetricsProvider $metricsProvider) - { - $this->connection = $db; - $this->metricsProvider = $metricsProvider; + public function __construct( + private Connection $connection, + private MetricsProvider $metricsProvider + ) { } /** @@ -40,8 +31,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..4aecb1a 100644 --- a/src/bundle/SystemInfo/Collector/ServicesSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/ServicesSystemInfoCollector.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\Collector; @@ -13,13 +14,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/Collector/SystemInfoCollector.php b/src/bundle/SystemInfo/Collector/SystemInfoCollector.php index e256360..ecf3464 100644 --- a/src/bundle/SystemInfo/Collector/SystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/SystemInfoCollector.php @@ -4,20 +4,13 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\Collector; use Ibexa\Bundle\SystemInfo\SystemInfo\Value; -/** - * Collects system information. - */ interface SystemInfoCollector { - /** - * Collects system information. - * - * @return Value\SystemInfo - */ - public function collect(); + public function collect(): Value\SystemInfo; } diff --git a/src/bundle/SystemInfo/Exception/ComposerFileValidationException.php b/src/bundle/SystemInfo/Exception/ComposerFileValidationException.php index 2c327c8..a15c3d9 100644 --- a/src/bundle/SystemInfo/Exception/ComposerFileValidationException.php +++ b/src/bundle/SystemInfo/Exception/ComposerFileValidationException.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\Exception; diff --git a/src/bundle/SystemInfo/Exception/ComposerJsonFileNotFoundException.php b/src/bundle/SystemInfo/Exception/ComposerJsonFileNotFoundException.php index 3227338..aa7955a 100644 --- a/src/bundle/SystemInfo/Exception/ComposerJsonFileNotFoundException.php +++ b/src/bundle/SystemInfo/Exception/ComposerJsonFileNotFoundException.php @@ -4,13 +4,14 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\Exception; use Exception; use Ibexa\Core\Base\Exceptions\NotFoundException as BaseNotFoundException; -class ComposerJsonFileNotFoundException extends BaseNotFoundException implements SystemInfoException +final class ComposerJsonFileNotFoundException extends BaseNotFoundException implements SystemInfoException { public function __construct(string $path, Exception $previous = null) { diff --git a/src/bundle/SystemInfo/Exception/ComposerLockFileNotFoundException.php b/src/bundle/SystemInfo/Exception/ComposerLockFileNotFoundException.php index ae5f124..da5d64a 100644 --- a/src/bundle/SystemInfo/Exception/ComposerLockFileNotFoundException.php +++ b/src/bundle/SystemInfo/Exception/ComposerLockFileNotFoundException.php @@ -4,13 +4,14 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\Exception; use Exception; use Ibexa\Core\Base\Exceptions\NotFoundException as BaseNotFoundException; -class ComposerLockFileNotFoundException extends BaseNotFoundException implements SystemInfoException +final class ComposerLockFileNotFoundException extends BaseNotFoundException implements SystemInfoException { public function __construct(string $path, Exception $previous = null) { diff --git a/src/bundle/SystemInfo/Exception/MetricsNotFoundException.php b/src/bundle/SystemInfo/Exception/MetricsNotFoundException.php index 2f2738a..3f8da70 100644 --- a/src/bundle/SystemInfo/Exception/MetricsNotFoundException.php +++ b/src/bundle/SystemInfo/Exception/MetricsNotFoundException.php @@ -4,13 +4,14 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\Exception; use Exception; use Ibexa\Core\Base\Exceptions\NotFoundException as BaseNotFoundException; -class MetricsNotFoundException extends BaseNotFoundException +final class MetricsNotFoundException extends BaseNotFoundException { public function __construct(string $identifier, Exception $previous = null) { diff --git a/src/bundle/SystemInfo/Exception/SystemInfoException.php b/src/bundle/SystemInfo/Exception/SystemInfoException.php index d5d28ef..d301ffc 100644 --- a/src/bundle/SystemInfo/Exception/SystemInfoException.php +++ b/src/bundle/SystemInfo/Exception/SystemInfoException.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\Exception; diff --git a/src/bundle/SystemInfo/Exception/SystemInfoServiceNotFoundException.php b/src/bundle/SystemInfo/Exception/SystemInfoServiceNotFoundException.php index 20f9dd3..616c180 100644 --- a/src/bundle/SystemInfo/Exception/SystemInfoServiceNotFoundException.php +++ b/src/bundle/SystemInfo/Exception/SystemInfoServiceNotFoundException.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare (strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\Exception; diff --git a/src/bundle/SystemInfo/OutputFormat.php b/src/bundle/SystemInfo/OutputFormat.php index e35ec4d..ec05ef7 100644 --- a/src/bundle/SystemInfo/OutputFormat.php +++ b/src/bundle/SystemInfo/OutputFormat.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo; @@ -13,8 +14,6 @@ interface OutputFormat * Format an array of collected information data, and return it as string. * * @param array $collectedInfo - * - * @return string */ - public function format(array $collectedInfo); + public function format(array $collectedInfo): string; } diff --git a/src/bundle/SystemInfo/OutputFormat/JsonOutputFormat.php b/src/bundle/SystemInfo/OutputFormat/JsonOutputFormat.php index 8a5b644..46aa992 100644 --- a/src/bundle/SystemInfo/OutputFormat/JsonOutputFormat.php +++ b/src/bundle/SystemInfo/OutputFormat/JsonOutputFormat.php @@ -4,23 +4,16 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\OutputFormat; use Ibexa\Bundle\SystemInfo\SystemInfo\OutputFormat as SystemInfoOutputFormat; -/** - * Implements the JSON output format. - */ -class JsonOutputFormat implements SystemInfoOutputFormat +final readonly class JsonOutputFormat implements SystemInfoOutputFormat { public function format(array $collectedInfo): string { - $json = json_encode($collectedInfo, JSON_PRETTY_PRINT); - if ($json === false) { - return ''; - } - - return $json; + return json_encode($collectedInfo, JSON_PRETTY_PRINT) ?: ''; } } diff --git a/src/bundle/SystemInfo/OutputFormatRegistry.php b/src/bundle/SystemInfo/OutputFormatRegistry.php index 514ab61..47a8647 100644 --- a/src/bundle/SystemInfo/OutputFormatRegistry.php +++ b/src/bundle/SystemInfo/OutputFormatRegistry.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo; @@ -12,17 +13,13 @@ /** * A registry of OutputFormats. */ -class OutputFormatRegistry +final 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; } /** @@ -38,9 +35,7 @@ public function getItem(string $identifier): OutputFormat } /** - * Returns the identifiers of all registered OutputFormats. - * - * @return string[] Array of identifier strings. + * @return string[] */ public function getIdentifiers(): array { diff --git a/src/bundle/SystemInfo/Registry/IdentifierBased.php b/src/bundle/SystemInfo/Registry/IdentifierBased.php index ed302f0..9f6dbfa 100644 --- a/src/bundle/SystemInfo/Registry/IdentifierBased.php +++ b/src/bundle/SystemInfo/Registry/IdentifierBased.php @@ -4,38 +4,30 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); 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 +final readonly class IdentifierBased implements SystemInfoCollectorRegistry { - /** @var \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector[] */ - private array $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. + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException */ - public function getItem($identifier) + public function getItem(string $identifier): SystemInfoCollector { if (isset($this->registry[$identifier])) { return $this->registry[$identifier]; @@ -45,11 +37,9 @@ public function getItem($identifier) } /** - * Returns the identifiers of all registered SystemInfoCollectors. - * - * @return string[] Array of identifier strings. + * @return string[] */ - 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..b621ba8 100644 --- a/src/bundle/SystemInfo/SystemInfoCollectorRegistry.php +++ b/src/bundle/SystemInfo/SystemInfoCollectorRegistry.php @@ -4,9 +4,12 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo; +use Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector; + /** * A registry of SystemInfoCollectors. */ @@ -20,18 +23,12 @@ 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[] */ - public function getIdentifiers(); + public function getIdentifiers(): array; } diff --git a/src/bundle/SystemInfo/EzcSystemInfoWrapper.php b/src/bundle/SystemInfo/SystemInfoWrapper.php similarity index 96% rename from src/bundle/SystemInfo/EzcSystemInfoWrapper.php rename to src/bundle/SystemInfo/SystemInfoWrapper.php index 0fdceea..e9aa215 100644 --- a/src/bundle/SystemInfo/EzcSystemInfoWrapper.php +++ b/src/bundle/SystemInfo/SystemInfoWrapper.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo; @@ -15,7 +16,7 @@ * This wraps zetacomponents/sysinfo, exposing its magic properties as public properties. * Used here to allow lazy loading. */ -class EzcSystemInfoWrapper +class SystemInfoWrapper { public ?string $osType; diff --git a/src/bundle/SystemInfo/Value/ComposerPackage.php b/src/bundle/SystemInfo/Value/ComposerPackage.php index 3e2a69c..17484ed 100644 --- a/src/bundle/SystemInfo/Value/ComposerPackage.php +++ b/src/bundle/SystemInfo/Value/ComposerPackage.php @@ -4,96 +4,33 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\Value; +use DateTimeInterface; use Ibexa\Contracts\Core\Repository\Values\ValueObject; /** * Value for information about a Composer package. */ -class ComposerPackage extends ValueObject implements SystemInfo +final class ComposerPackage extends ValueObject implements SystemInfo { - /** - * Name. - * - * Example: ezsystems/ezpublish-kernel - * - * @var string - */ - public $name; + public string $name; - /** - * Tag or Branch. - * - * Examples: v2.7.10, dev-master - * - * @var string - */ - public $branch; + public string $branch; - /** - * Alias. - * - * Examples: v2.7.x-dev - * - * @var string|null - */ - public $alias = null; + public string $version; - /** - * Normilized version number. - * - * Uses root-alias or package-aliases if present to try to provide a version number even on branches. - * - * Examples: 2.7.10, 2.8.x - * - * @var string - */ - public $version; + public ?string $alias = null; - /** - * License string. - * - * Only contains the first license on the package, if set. - * - * Examples: 'TTL-2.0', 'GPL-2.0-only' - * - * @var string|null - */ - public $license = null; + public ?string $license = null; - /** - * Stability. - * - * One of: stable, RC, beta, alpha, dev, or null if not set. - * - * @var string|null - */ - public $stability; + public ?string $stability; - /** - * Date and time. - * - * @var \DateTime - */ - public $dateTime; + public ?DateTimeInterface $dateTime; - /** - * Homepage URL, or null of not set. - * - * Example: https://symfony.com - * - * @var string|null - */ - public $homepage; + public ?string $homepage; - /** - * Reference. - * - * Example: 9a3b6bf6ebee49370aaf15abc1bdeb4b1986a67d - * - * @var string - */ - public $reference; + public ?string $reference; } diff --git a/src/bundle/SystemInfo/Value/ComposerSystemInfo.php b/src/bundle/SystemInfo/Value/ComposerSystemInfo.php index 3261cdc..be7e1a2 100644 --- a/src/bundle/SystemInfo/Value/ComposerSystemInfo.php +++ b/src/bundle/SystemInfo/Value/ComposerSystemInfo.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\Value; @@ -12,25 +13,17 @@ /** * Value for information about installed Composer packages. */ -class ComposerSystemInfo extends ValueObject implements SystemInfo +final class ComposerSystemInfo extends ValueObject implements SystemInfo { - /** - * Packages. - * - * A hash of composer package names and ComposerPackage values, or null if packages cannot be read. - * - * @var ComposerPackage[]|null - */ - public $packages; + /** @var \Ibexa\Bundle\SystemInfo\SystemInfo\Value\ComposerPackage[]|null */ + public ?array $packages; /** * Minimum stability, as read from composer.lock. * * One of: stable, RC, beta, alpha, dev, or null if not set. - * - * @var string|null */ - public $minimumStability; + public ?string $minimumStability; /** * Additional Composer repository urls used. @@ -39,5 +32,5 @@ class ComposerSystemInfo extends ValueObject implements SystemInfo * * @var string[] */ - public $repositoryUrls = []; + public array $repositoryUrls = []; } diff --git a/src/bundle/SystemInfo/Value/HardwareSystemInfo.php b/src/bundle/SystemInfo/Value/HardwareSystemInfo.php index 73ed827..61acbae 100644 --- a/src/bundle/SystemInfo/Value/HardwareSystemInfo.php +++ b/src/bundle/SystemInfo/Value/HardwareSystemInfo.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\Value; @@ -12,33 +13,13 @@ /** * Value for information about the hardware we are running on. */ -class HardwareSystemInfo extends ValueObject implements SystemInfo +final class HardwareSystemInfo extends ValueObject implements SystemInfo { - /** - * CPU type. - * - * @var string - */ - public $cpuType; + public ?string $cpuType; - /** - * CPU speed. - * - * @var string - */ - public $cpuSpeed; + public ?string $cpuSpeed; - /** - * CPU count. - * - * @var int - */ - public $cpuCount; + public ?int $cpuCount; - /** - * Memory size. - * - * @var float - */ - public $memorySize; + public ?float $memorySize; } diff --git a/src/bundle/SystemInfo/Value/IbexaSystemInfo.php b/src/bundle/SystemInfo/Value/IbexaSystemInfo.php index 723bfcd..9a15124 100644 --- a/src/bundle/SystemInfo/Value/IbexaSystemInfo.php +++ b/src/bundle/SystemInfo/Value/IbexaSystemInfo.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\Value; @@ -15,74 +16,55 @@ * * @internal This class will greatly change in the future and should not be used as an api. */ -class IbexaSystemInfo extends ValueObject implements SystemInfo +final class IbexaSystemInfo extends ValueObject implements SystemInfo { - public const PRODUCT_NAME_OSS = 'Ibexa Open Source'; - public const PRODUCT_NAME_ENTERPRISE = 'Ibexa DXP'; - public const PRODUCT_NAME_VARIANTS = [ + public const string PRODUCT_NAME_OSS = 'Ibexa Open Source'; + + public const array PRODUCT_NAME_VARIANTS = [ 'oss' => self::PRODUCT_NAME_OSS, 'headless' => 'Ibexa Headless', 'experience' => 'Ibexa Experience', 'commerce' => 'Ibexa Commerce', ]; - /** - * @var string - */ - public $name = self::PRODUCT_NAME_OSS; + public string $name = self::PRODUCT_NAME_OSS; - /** - * @var string|null Either string like '2.5' or null if not detected. - */ - public $release; + public ?string $release; - /** - * @var bool - */ - public $isEnterprise = false; + public bool $isEnterprise = false; - /** - * @var bool - */ - public $isCommerce = false; + public bool $isCommerce = false; /** - * @var bool - * * @uses $endOfMaintenanceDate */ - public $isEndOfMaintenance = true; + public bool $isEndOfMaintenance = true; /** - * @var \DateTime EOM for the given release, if you have an Ibexa DXP / Enterpise susbscription. + * @var \DateTime|null EOM for the given release, if you have an Ibexa DXP / Enterpise susbscription. * * @see https://support.ibexa.co/Public/Service-Life */ public ?DateTime $endOfMaintenanceDate; /** - * @var bool - * * @uses $endOfLifeDate */ - public $isEndOfLife = true; + public bool $isEndOfLife = true; /** - * @var \DateTime EOL for the given release, if you have an Ibexa DXP susbscription. + * @var \DateTime|null EOL for the given release, if you have an Ibexa DXP susbscription. * * @see https://support.ibexa.co/Public/Service-Life */ public ?DateTime $endOfLifeDate; - /** - * @var bool - */ - public $isTrial = false; + public bool $isTrial = false; /** * Lowest stability found in the installation (packages / minimumStability). * * @var string One of {@see \Ibexa\SystemInfo\Value\Stability::STABILITIES}. */ - public $lowestStability; + public string $lowestStability; } diff --git a/src/bundle/SystemInfo/Value/InvalidSystemInfo.php b/src/bundle/SystemInfo/Value/InvalidSystemInfo.php index 26adc9f..9801451 100644 --- a/src/bundle/SystemInfo/Value/InvalidSystemInfo.php +++ b/src/bundle/SystemInfo/Value/InvalidSystemInfo.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\Value; @@ -14,10 +15,5 @@ */ final class InvalidSystemInfo extends ValueObject implements SystemInfo { - /** - * Error message shown in the System info tab. - * - * @var string - */ - public $errorMessage; + public string $errorMessage; } diff --git a/src/bundle/SystemInfo/Value/PhpSystemInfo.php b/src/bundle/SystemInfo/Value/PhpSystemInfo.php index 995cc61..9a55caa 100644 --- a/src/bundle/SystemInfo/Value/PhpSystemInfo.php +++ b/src/bundle/SystemInfo/Value/PhpSystemInfo.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\Value; @@ -12,48 +13,25 @@ /** * Value for information about the PHP interpreter and accelerator (if any) we are using. */ -class PhpSystemInfo extends ValueObject implements SystemInfo +final class PhpSystemInfo extends ValueObject implements SystemInfo { - /** - * PHP version. - * - * Example: 5.6.7-1 - * - * @var string - */ - public $version; + public string $version; - /** - * True if an accelerator is enabled. - * - * @var bool - */ - public $acceleratorEnabled; + public bool $acceleratorEnabled; - /** - * PHP accelerator name, or null if no accelerator is enabled. - * - * Example: Zend OPcache - * - * @var string|null - */ - public $acceleratorName; + public ?string $acceleratorName; /** * PHP accelerator URL, or null if no accelerator is enabled. * * Example: http://www.php.net/opcache - * - * @var string|null */ - public $acceleratorURL; + public ?string $acceleratorURL; /** * PHP accelerator version, or null if no accelerator is enabled. * * Example: 7.0.4-devFE - * - * @var string|null */ - public $acceleratorVersion; + public ?string $acceleratorVersion; } diff --git a/src/bundle/SystemInfo/Value/RepositoryMetrics.php b/src/bundle/SystemInfo/Value/RepositoryMetrics.php index 9021d52..5aff160 100644 --- a/src/bundle/SystemInfo/Value/RepositoryMetrics.php +++ b/src/bundle/SystemInfo/Value/RepositoryMetrics.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\Value; @@ -12,36 +13,15 @@ /** * Value for various repository metrics (content object count, user count etc.). */ -class RepositoryMetrics extends ValueObject implements SystemInfo +final class RepositoryMetrics extends ValueObject implements SystemInfo { - /** - * Count of all published content objects. - * - * @var int - */ - public $publishedCount; - - /** - * Count of users. - * - * @var int - */ - public $usersCount; - - /** - * Count of drafts. - * - * @var int - */ - public $draftsCount; - - /** - * Total count of versions. - * - * @var int - */ - public $versionsCount; - - /** @var int */ - public $contentTypesCount; + public int $publishedCount; + + public int $usersCount; + + public int $draftsCount; + + public int $versionsCount; + + public int $contentTypesCount; } diff --git a/src/bundle/SystemInfo/Value/RepositorySystemInfo.php b/src/bundle/SystemInfo/Value/RepositorySystemInfo.php index a99e8ce..5adef11 100644 --- a/src/bundle/SystemInfo/Value/RepositorySystemInfo.php +++ b/src/bundle/SystemInfo/Value/RepositorySystemInfo.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\Value; @@ -12,48 +13,15 @@ /** * Value for information about the database we are using. */ -class RepositorySystemInfo extends ValueObject implements SystemInfo +final class RepositorySystemInfo extends ValueObject implements SystemInfo { - /** - * Database type. - * - * Example: mysql - * - * @var string - */ - public $type; - - /** - * Database name. - * - * Example: ezp_platform - * - * @var string - */ - public $name; - - /** - * Database host. - * - * Example: localhost - * - * @var string - */ - public $host; - - /** - * Database username. - * - * Example: ezp_user - * - * @var string - */ - public $username; - - /** - * RepositoryMetrics contains counts of content objects, users etc. - * - * @var \Ibexa\Bundle\SystemInfo\SystemInfo\Value\RepositoryMetrics - */ - public $repositoryMetrics; + public string $type; + + public string $name; + + public string $host; + + public string $username; + + public RepositoryMetrics $repositoryMetrics; } diff --git a/src/bundle/SystemInfo/Value/ServicesSystemInfo.php b/src/bundle/SystemInfo/Value/ServicesSystemInfo.php index 328c8a5..f65d71b 100644 --- a/src/bundle/SystemInfo/Value/ServicesSystemInfo.php +++ b/src/bundle/SystemInfo/Value/ServicesSystemInfo.php @@ -4,43 +4,20 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\Value; /** * Value for information about services used within the project. */ -final class ServicesSystemInfo implements SystemInfo +final readonly 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 + private string $searchEngine, + private string $httpCacheProxy, + private string $persistenceCacheAdapter ) { - $this->searchEngine = $searchEngine; - $this->httpCacheProxy = $httpCacheProxy; - $this->persistenceCacheAdapter = $persistenceCacheAdapter; } public function getSearchEngine(): string diff --git a/src/bundle/SystemInfo/Value/SymfonyKernelSystemInfo.php b/src/bundle/SystemInfo/Value/SymfonyKernelSystemInfo.php index 858754c..6a5171e 100644 --- a/src/bundle/SystemInfo/Value/SymfonyKernelSystemInfo.php +++ b/src/bundle/SystemInfo/Value/SymfonyKernelSystemInfo.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\Value; @@ -12,32 +13,13 @@ /** * Value for information about the Symfony kernel we are using. */ -class SymfonyKernelSystemInfo extends ValueObject implements SystemInfo +final class SymfonyKernelSystemInfo extends ValueObject implements SystemInfo { - /** - * Symfony environment. - * - * "dev" or "prod". - * - * @var string - */ - public $environment; + public string $environment; - /** - * True if Symfony is in debug mode. - * - * @var bool - */ - public $debugMode; + public bool $debugMode; - /** - * Symfony version. - * - * Example: 2.7.10 - * - * @var string - */ - public $version; + public string $version; /** * Installed bundles. @@ -52,41 +34,13 @@ class SymfonyKernelSystemInfo extends ValueObject implements SystemInfo * * @var array */ - public $bundles; + public array $bundles; - /** - * Project directory. - * - * Example: /srv/www/ibexa-dxp/app - * - * @var string - */ - public $projectDir; + public string $projectDir; - /** - * Cache directory. - * - * Example: /srv/www/ibexa-dxp/app/cache/prod - * - * @var string - */ - public $cacheDir; + public string $cacheDir; - /** - * Log file directory. - * - * Example: /srv/www/ibexa-dxp/app/logs - * - * @var string - */ - public $logDir; + public string $logDir; - /** - * Character set. - * - * Example: UTF-8 - * - * @var string - */ - public $charset; + public string $charset; } diff --git a/src/bundle/SystemInfo/Value/SystemInfo.php b/src/bundle/SystemInfo/Value/SystemInfo.php index 3fa49e2..f27de74 100644 --- a/src/bundle/SystemInfo/Value/SystemInfo.php +++ b/src/bundle/SystemInfo/Value/SystemInfo.php @@ -4,12 +4,10 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\SystemInfo\Value; -/** - * System information value. - */ interface SystemInfo { } diff --git a/src/bundle/View/Matcher/SystemInfo/Identifier.php b/src/bundle/View/Matcher/SystemInfo/Identifier.php index 6617b86..e0d423d 100644 --- a/src/bundle/View/Matcher/SystemInfo/Identifier.php +++ b/src/bundle/View/Matcher/SystemInfo/Identifier.php @@ -4,21 +4,23 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\View\Matcher\SystemInfo; use Ibexa\Bundle\SystemInfo\View\SystemInfoView; use Ibexa\Core\MVC\Symfony\Matcher\ViewMatcherInterface; use Ibexa\Core\MVC\Symfony\View\View; +use RuntimeException; -class Identifier implements ViewMatcherInterface +final class Identifier implements ViewMatcherInterface { /** * Matched SystemInfo identifier. Example: 'php', 'hardware'... */ private string $identifier; - public function setMatchingConfig($matchingConfig): void + public function setMatchingConfig(mixed $matchingConfig): void { $this->identifier = $matchingConfig; } @@ -37,7 +39,7 @@ public function match(View $view): bool private function toIdentifier(object $object): string { - $className = \get_class($object); + $className = get_class($object); $className = substr($className, strrpos($className, '\\') + 1); $className = str_replace('SystemInfo', '', $className); @@ -49,7 +51,7 @@ private function normalizeName(string $name): string $normalized = preg_replace('~(?<=\\w)([A-Z])~u', '_$1', $name); if ($normalized === null) { - throw new \RuntimeException(sprintf( + throw new RuntimeException(sprintf( 'preg_replace returned null for value "%s"', $name )); diff --git a/src/bundle/View/SystemInfoView.php b/src/bundle/View/SystemInfoView.php index bd593ca..c6aefb3 100644 --- a/src/bundle/View/SystemInfoView.php +++ b/src/bundle/View/SystemInfoView.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\View; @@ -11,7 +12,7 @@ use Ibexa\Core\MVC\Symfony\View\BaseView; use Ibexa\Core\MVC\Symfony\View\View; -class SystemInfoView extends BaseView implements View +final class SystemInfoView extends BaseView implements View { private SystemInfo $info; diff --git a/src/bundle/View/SystemInfoViewBuilder.php b/src/bundle/View/SystemInfoViewBuilder.php index 326b9d0..be72f53 100644 --- a/src/bundle/View/SystemInfoViewBuilder.php +++ b/src/bundle/View/SystemInfoViewBuilder.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Bundle\SystemInfo\View; @@ -13,24 +14,16 @@ 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 +final readonly class SystemInfoViewBuilder implements ViewBuilder { - private Configurator $viewConfigurator; - - /** - * System info collector registry. - */ - private SystemInfoCollectorRegistry $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 + public function matches(mixed $argument): bool { return $argument === 'ibexa.support_tools.view.controller::viewInfoAction'; } @@ -38,9 +31,10 @@ public function matches($argument): bool /** * @param array $parameters * - * @return \Ibexa\Bundle\SystemInfo\View\SystemInfoView + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException */ - public function buildView(array $parameters): View + public function buildView(array $parameters): SystemInfoView { $collector = $this->getCollector($parameters['systemInfoIdentifier']); $view = new SystemInfoView(null, [], $parameters['viewType']); @@ -59,7 +53,7 @@ public function buildView(array $parameters): View } /** - * @param string $identifier A SystemInfo collector identifier (php, hardware...) + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException */ private function getCollector(string $identifier): SystemInfoCollector { diff --git a/src/lib/Component/Dashboard/EzInfoTwigComponent.php b/src/lib/Component/Dashboard/EzInfoTwigComponent.php deleted file mode 100644 index 9d9d723..0000000 --- a/src/lib/Component/Dashboard/EzInfoTwigComponent.php +++ /dev/null @@ -1,79 +0,0 @@ - */ - protected array $parameters; - - private IbexaSystemInfo $ibexaSystemInfo; - - /** @var array */ - private array $urlList; - - /** - * @param array $urlList - * @param array $parameters - */ - public function __construct( - Environment $twig, - string $template, - IbexaSystemInfo $ibexaSystemInfo, - array $urlList, - array $parameters = [] - ) { - $this->twig = $twig; - $this->template = $template; - $this->parameters = $parameters; - $this->ibexaSystemInfo = $ibexaSystemInfo; - $this->urlList = $urlList; - } - - /** - * @param array $parameters - */ - public function render(array $parameters = []): string - { - $urls = $this->replaceUrlPlaceholders(); - - return $this->twig->render( - $this->template, - $parameters + ['urls' => $urls, 'ibexa' => $this->ibexaSystemInfo] + $this->parameters - ); - } - - /** - * @return array - */ - private function replaceUrlPlaceholders(): array - { - $urls = $this->urlList; - foreach ($this->urlList as $urlName => $url) { - foreach (get_object_vars($this->ibexaSystemInfo) as $attribute => $value) { - if (\is_string($value) && \strpos($url, '{ez.' . $attribute . '}') !== false) { - $urls[$urlName] = \str_replace('{ez.' . $attribute . '}', $value, $url); - } - } - } - - return $urls; - } -} diff --git a/src/lib/EventListener/ConfigureMainMenuListener.php b/src/lib/EventListener/ConfigureMainMenuListener.php index a71846b..1ad08b0 100644 --- a/src/lib/EventListener/ConfigureMainMenuListener.php +++ b/src/lib/EventListener/ConfigureMainMenuListener.php @@ -16,25 +16,16 @@ use JMS\TranslationBundle\Translation\TranslationContainerInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -class ConfigureMainMenuListener implements EventSubscriberInterface, TranslationContainerInterface +final readonly class ConfigureMainMenuListener implements EventSubscriberInterface, TranslationContainerInterface { - public const ITEM_ADMIN__SYSTEMINFO = 'main__admin__systeminfo'; - - private MenuItemFactoryInterface $menuItemFactory; - - private PermissionResolver $permissionResolver; + public const string ITEM_ADMIN__SYSTEMINFO = 'main__admin__systeminfo'; public function __construct( - MenuItemFactoryInterface $menuItemFactory, - PermissionResolver $permissionResolver + private MenuItemFactoryInterface $menuItemFactory, + private PermissionResolver $permissionResolver ) { - $this->menuItemFactory = $menuItemFactory; - $this->permissionResolver = $permissionResolver; } - /** - * @param \Ibexa\AdminUi\Menu\Event\ConfigureMenuEvent $event - */ public function onMenuConfigure(ConfigureMenuEvent $event): void { $menu = $event->getMenu(); @@ -47,6 +38,7 @@ public function onMenuConfigure(ConfigureMenuEvent $event): void if ($adminMenu === null) { return; } + $adminMenu->addChild( $this->menuItemFactory->createItem( self::ITEM_ADMIN__SYSTEMINFO, diff --git a/src/lib/EventListener/SystemInfoTabGroupListener.php b/src/lib/EventListener/SystemInfoTabGroupListener.php index 60403d3..eae4657 100644 --- a/src/lib/EventListener/SystemInfoTabGroupListener.php +++ b/src/lib/EventListener/SystemInfoTabGroupListener.php @@ -4,37 +4,22 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\SystemInfo\EventListener; 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 +final readonly class SystemInfoTabGroupListener implements EventSubscriberInterface { - protected TabRegistry $tabRegistry; - - protected TabFactory $tabFactory; - - protected SystemInfoCollectorRegistry $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 @@ -47,7 +32,6 @@ public static function getSubscribedEvents(): array public function onTabGroupPreRender(TabGroupEvent $event): void { $tabGroup = $event->getData(); - if ('systeminfo' !== $tabGroup->getIdentifier()) { return; } diff --git a/src/lib/Service/AggregateServiceProvider.php b/src/lib/Service/AggregateServiceProvider.php index 297b249..46e7faa 100644 --- a/src/lib/Service/AggregateServiceProvider.php +++ b/src/lib/Service/AggregateServiceProvider.php @@ -15,17 +15,13 @@ /** * @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 \Symfony\Component\DependencyInjection\ServiceLocator<\Ibexa\SystemInfo\Service\ServiceInfo> $serviceLocator */ - public function __construct(ServiceLocator $service) + public function __construct(private ServiceLocator $serviceLocator) { - $this->serviceLocator = $service; } /** 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..ebc72cf 100644 --- a/src/lib/Service/PersistenceCacheServiceInfo.php +++ b/src/lib/Service/PersistenceCacheServiceInfo.php @@ -13,19 +13,19 @@ /** * @internal */ -final class PersistenceCacheServiceInfo implements ServiceInfo +final readonly 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) - { - $this->configResolver = $configResolver; + public function __construct( + private ConfigResolverInterface $configResolver + ) { } public function getServiceType(): string { - return $this->configResolver->getParameter(self::PERSISTENCE_CACHE_CONFIG_KEY); + return $this->configResolver->getParameter( + self::PERSISTENCE_CACHE_CONFIG_KEY + ); } } diff --git a/src/lib/Service/SearchEngineServiceInfo.php b/src/lib/Service/SearchEngineServiceInfo.php index 835b424..af683dc 100644 --- a/src/lib/Service/SearchEngineServiceInfo.php +++ b/src/lib/Service/SearchEngineServiceInfo.php @@ -15,16 +15,17 @@ */ 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) - { - $this->repositoryConfigProvider = $repositoryConfigProvider; + public function __construct( + private RepositoryConfigurationProviderInterface $repositoryConfigProvider + ) { } + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException + */ public function getServiceType(): string { $repositoryConfig = $this->repositoryConfigProvider->getRepositoryConfig(); diff --git a/src/lib/Storage/AggregateMetricsProvider.php b/src/lib/Storage/AggregateMetricsProvider.php index 03d0d51..3ad94fc 100644 --- a/src/lib/Storage/AggregateMetricsProvider.php +++ b/src/lib/Storage/AggregateMetricsProvider.php @@ -15,17 +15,13 @@ /** * @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 \Symfony\Component\DependencyInjection\ServiceLocator<\Ibexa\SystemInfo\Storage\Metrics> $metricsLocator */ - public function __construct(ServiceLocator $metrics) + public function __construct(private ServiceLocator $metricsLocator) { - $this->metricsLocator = $metrics; } /** diff --git a/src/lib/Storage/Metrics/ContentTypesCountMetrics.php b/src/lib/Storage/Metrics/ContentTypesCountMetrics.php index 3144061..6e7cc00 100644 --- a/src/lib/Storage/Metrics/ContentTypesCountMetrics.php +++ b/src/lib/Storage/Metrics/ContentTypesCountMetrics.php @@ -16,7 +16,6 @@ */ final class ContentTypesCountMetrics extends RepositoryConnectionAwareMetrics { - private const string CONTENT_TYPE_TABLE = ContentTypeGateway::CONTENT_TYPE_TABLE; private const string ID_COLUMN = 'id'; private const string STATUS_COLUMN = 'status'; @@ -28,11 +27,11 @@ public function getValue(): int $queryBuilder = $this->connection->createQueryBuilder(); $queryBuilder ->select($this->getCountExpression(self::ID_COLUMN)) - ->from(self::CONTENT_TYPE_TABLE) + ->from(ContentTypeGateway::CONTENT_TYPE_TABLE) ->where( $queryBuilder->expr()->eq(self::STATUS_COLUMN, Type::STATUS_DEFINED) ); - return (int) $queryBuilder->executeQuery()->fetchFirstColumn(); + return (int)$queryBuilder->executeQuery()->fetchOne(); } } diff --git a/src/lib/Storage/Metrics/DraftsCountMetrics.php b/src/lib/Storage/Metrics/DraftsCountMetrics.php index 5101346..3ddecc0 100644 --- a/src/lib/Storage/Metrics/DraftsCountMetrics.php +++ b/src/lib/Storage/Metrics/DraftsCountMetrics.php @@ -17,9 +17,6 @@ */ final class DraftsCountMetrics extends RepositoryConnectionAwareMetrics { - private const string CONTENTOBJECT_VERSION_TABLE = ContentGateway::CONTENT_VERSION_TABLE; - private const string CONTENTOBJECT_TABLE = ContentGateway::CONTENT_ITEM_TABLE; - /** * @throws \Doctrine\DBAL\Exception */ @@ -30,10 +27,10 @@ public function getValue(): int $queryBuilder ->select($this->getCountExpression('v.id')) - ->from(self::CONTENTOBJECT_VERSION_TABLE, 'v') + ->from(ContentGateway::CONTENT_VERSION_TABLE, 'v') ->innerJoin( 'v', - self::CONTENTOBJECT_TABLE, + ContentGateway::CONTENT_ITEM_TABLE, 'c', $expr->and( $expr->eq('c.id', 'v.contentobject_id'), @@ -45,6 +42,6 @@ public function getValue(): int ) ->setParameter('status', ContentInfo::STATUS_DRAFT, ParameterType::INTEGER); - return (int) $queryBuilder->executeQuery()->fetchFirstColumn(); + return (int)$queryBuilder->executeQuery()->fetchOne(); } } diff --git a/src/lib/Storage/Metrics/PublishedContentObjectsCountMetrics.php b/src/lib/Storage/Metrics/PublishedContentObjectsCountMetrics.php index 91b89e8..f01793a 100644 --- a/src/lib/Storage/Metrics/PublishedContentObjectsCountMetrics.php +++ b/src/lib/Storage/Metrics/PublishedContentObjectsCountMetrics.php @@ -16,7 +16,6 @@ */ final class PublishedContentObjectsCountMetrics extends RepositoryConnectionAwareMetrics { - private const string CONTENTOBJECT_TABLE = ContentGateway::CONTENT_ITEM_TABLE; private const string ID_COLUMN = 'id'; private const string STATUS_COLUMN = 'status'; @@ -28,11 +27,11 @@ public function getValue(): int $queryBuilder = $this->connection->createQueryBuilder(); $queryBuilder ->select($this->getCountExpression(self::ID_COLUMN)) - ->from(self::CONTENTOBJECT_TABLE) + ->from(ContentGateway::CONTENT_ITEM_TABLE) ->where( $queryBuilder->expr()->eq(self::STATUS_COLUMN, ContentInfo::STATUS_PUBLISHED) ); - return (int) $queryBuilder->executeQuery()->fetchFirstColumn(); + return (int)$queryBuilder->executeQuery()->fetchOne(); } } diff --git a/src/lib/Storage/Metrics/UsersCountMetrics.php b/src/lib/Storage/Metrics/UsersCountMetrics.php index c855836..3b4e72f 100644 --- a/src/lib/Storage/Metrics/UsersCountMetrics.php +++ b/src/lib/Storage/Metrics/UsersCountMetrics.php @@ -15,7 +15,6 @@ */ final class UsersCountMetrics extends RepositoryConnectionAwareMetrics { - private const string USER_TABLE = UserGateway::USER_TABLE; private const string CONTENTOBJECT_ID_COLUMN = 'contentobject_id'; /** @@ -26,8 +25,8 @@ public function getValue(): int $queryBuilder = $this->connection->createQueryBuilder(); $queryBuilder ->select($this->getCountExpression(self::CONTENTOBJECT_ID_COLUMN)) - ->from(self::USER_TABLE); + ->from(UserGateway::USER_TABLE); - return (int) $queryBuilder->executeQuery()->fetchFirstColumn(); + return (int)$queryBuilder->executeQuery()->fetchOne(); } } diff --git a/src/lib/Storage/Metrics/VersionsCountMetrics.php b/src/lib/Storage/Metrics/VersionsCountMetrics.php index ab8c2b0..d98f3b9 100644 --- a/src/lib/Storage/Metrics/VersionsCountMetrics.php +++ b/src/lib/Storage/Metrics/VersionsCountMetrics.php @@ -15,7 +15,6 @@ */ final class VersionsCountMetrics extends RepositoryConnectionAwareMetrics { - private const string CONTENTOBJECT_VERSION_TABLE = ContentGateway::CONTENT_VERSION_TABLE; private const string ID_COLUMN = 'id'; /** @@ -26,8 +25,8 @@ public function getValue(): int $queryBuilder = $this->connection->createQueryBuilder(); $queryBuilder ->select($this->getCountExpression(self::ID_COLUMN)) - ->from(self::CONTENTOBJECT_VERSION_TABLE); + ->from(ContentGateway::CONTENT_VERSION_TABLE); - return (int) $queryBuilder->executeQuery()->fetchFirstColumn(); + return (int)$queryBuilder->executeQuery()->fetchOne(); } } diff --git a/src/lib/Tab/SystemInfo/SystemInfoTab.php b/src/lib/Tab/SystemInfo/SystemInfoTab.php index 985bb7c..fb308f5 100644 --- a/src/lib/Tab/SystemInfo/SystemInfoTab.php +++ b/src/lib/Tab/SystemInfo/SystemInfoTab.php @@ -9,6 +9,7 @@ namespace Ibexa\SystemInfo\Tab\SystemInfo; use Ibexa\Contracts\AdminUi\Tab\AbstractControllerBasedTab; +use JMS\TranslationBundle\Annotation\Ignore; use Symfony\Bridge\Twig\Extension\HttpKernelRuntime; use Symfony\Component\HttpKernel\Controller\ControllerReference; use Symfony\Contracts\Translation\TranslatorInterface; @@ -16,28 +17,14 @@ class SystemInfoTab extends AbstractControllerBasedTab { - protected string $tabIdentifier; - - protected string $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 @@ -55,6 +42,10 @@ public function getIdentifier(): string public function getName(): string { - return /** @Ignore */$this->translator->trans(sprintf('tab.name.%s', $this->tabIdentifier), [], 'ibexa_systeminfo'); + return /** @Ignore */$this->translator->trans( + sprintf('tab.name.%s', $this->tabIdentifier), + [], + 'ibexa_systeminfo' + ); } } diff --git a/src/lib/Tab/SystemInfo/TabFactory.php b/src/lib/Tab/SystemInfo/TabFactory.php index 688d269..071c824 100644 --- a/src/lib/Tab/SystemInfo/TabFactory.php +++ b/src/lib/Tab/SystemInfo/TabFactory.php @@ -14,35 +14,17 @@ class TabFactory { - protected HttpKernelRuntime $httpKernelRuntime; - - protected Environment $twig; - - protected TranslatorInterface $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 + private readonly Environment $twig, + private readonly TranslatorInterface $translator, + private readonly 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 - { + public function createTab( + string $collectorIdentifier, + ?string $tabIdentifier = null + ): SystemInfoTab { $tabIdentifier = $tabIdentifier ?? $collectorIdentifier; return new SystemInfoTab( diff --git a/src/lib/Value/Stability.php b/src/lib/Value/Stability.php index 8472d07..f5833ef 100644 --- a/src/lib/Value/Stability.php +++ b/src/lib/Value/Stability.php @@ -8,14 +8,14 @@ namespace Ibexa\SystemInfo\Value; -final class Stability +final readonly class Stability { /** * @var array Hash of stability constant values to human readable stabilities, see Composer\Package\BasePackage. * * Needed as long as we don't want to depend on Composer. */ - public const STABILITIES = [ + public const array STABILITIES = [ 0 => 'stable', 5 => 'RC', 10 => 'beta', diff --git a/tests/bundle/DependencyInjection/Compiler/SystemInfoTabGroupPassTest.php b/tests/bundle/DependencyInjection/Compiler/SystemInfoTabGroupPassTest.php index 235a51f..b69c283 100644 --- a/tests/bundle/DependencyInjection/Compiler/SystemInfoTabGroupPassTest.php +++ b/tests/bundle/DependencyInjection/Compiler/SystemInfoTabGroupPassTest.php @@ -15,7 +15,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; -class SystemInfoTabGroupPassTest extends AbstractCompilerPassTestCase +final class SystemInfoTabGroupPassTest extends AbstractCompilerPassTestCase { protected function setUp(): void { diff --git a/tests/bundle/DependencyInjection/IbexaSystemInfoExtensionTest.php b/tests/bundle/DependencyInjection/IbexaSystemInfoExtensionTest.php index 52170bb..4d88b97 100644 --- a/tests/bundle/DependencyInjection/IbexaSystemInfoExtensionTest.php +++ b/tests/bundle/DependencyInjection/IbexaSystemInfoExtensionTest.php @@ -17,8 +17,11 @@ use Ibexa\SystemInfo\Storage\MetricsProvider; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; -class IbexaSystemInfoExtensionTest extends AbstractExtensionTestCase +final class IbexaSystemInfoExtensionTest extends AbstractExtensionTestCase { + /** + * @return \Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface[] + */ protected function getContainerExtensions(): array { return [new IbexaSystemInfoExtension()]; diff --git a/tests/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollectorTest.php b/tests/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollectorTest.php index 407b14f..cb0ac91 100644 --- a/tests/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollectorTest.php +++ b/tests/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollectorTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\SystemInfo\SystemInfo\Collector; @@ -12,7 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpKernel\Kernel; -class ConfigurationSymfonyKernelSystemInfoCollectorTest extends TestCase +final class ConfigurationSymfonyKernelSystemInfoCollectorTest extends TestCase { /** * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\ConfigurationSymfonyKernelSystemInfoCollector::collect() @@ -35,39 +36,42 @@ public function testCollect(): void 'charset' => 'UTF-8', ]); - $kernelMock = $this->getMockBuilder('Symfony\Component\HttpKernel\Kernel') - ->setConstructorArgs([$expected->environment, $expected->debugMode]) + $kernelMock = $this->getMockBuilder(Kernel::class) + ->setConstructorArgs([ + $expected->environment, + $expected->debugMode, + ]) ->getMock(); $kernelMock ->expects(self::once()) ->method('getEnvironment') - ->will(self::returnValue($expected->environment)); + ->willReturn($expected->environment); $kernelMock ->expects(self::once()) ->method('isDebug') - ->will(self::returnValue($expected->debugMode)); + ->willReturn($expected->debugMode); $kernelMock ->expects(self::once()) ->method('getProjectDir') - ->will(self::returnValue($expected->projectDir)); + ->willReturn($expected->projectDir); $kernelMock ->expects(self::once()) ->method('getCacheDir') - ->will(self::returnValue($expected->cacheDir)); + ->willReturn($expected->cacheDir); $kernelMock ->expects(self::once()) ->method('getLogDir') - ->will(self::returnValue($expected->logDir)); + ->willReturn($expected->logDir); $kernelMock ->expects(self::once()) ->method('getCharset') - ->will(self::returnValue($expected->charset)); + ->willReturn($expected->charset); $symfonyCollector = new ConfigurationSymfonyKernelSystemInfoCollector( $kernelMock, diff --git a/tests/bundle/SystemInfo/Collector/EzcHardwareSystemInfoCollectorTest.php b/tests/bundle/SystemInfo/Collector/EzcHardwareSystemInfoCollectorTest.php deleted file mode 100644 index b7b919a..0000000 --- a/tests/bundle/SystemInfo/Collector/EzcHardwareSystemInfoCollectorTest.php +++ /dev/null @@ -1,53 +0,0 @@ -ezcSystemInfoMock = $this - ->getMockBuilder(EzcSystemInfoWrapper::class) - ->disableOriginalConstructor() - ->getMock(); - $this->ezcSystemInfoMock->cpuType = 'Intel(R) Core(TM) i7-3720QM CPU @ 2.60GHz'; - $this->ezcSystemInfoMock->cpuSpeed = 2591.9000000000001; - $this->ezcSystemInfoMock->cpuCount = 1; - $this->ezcSystemInfoMock->memorySize = 1554632704; - - $this->ezcHardware = new EzcHardwareSystemInfoCollector($this->ezcSystemInfoMock); - } - - /** - * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\EzcHardwareSystemInfoCollector::collect() - */ - public function testCollect(): void - { - $value = $this->ezcHardware->collect(); - - self::assertEquals( - new HardwareSystemInfo([ - 'cpuType' => $this->ezcSystemInfoMock->cpuType, - 'cpuSpeed' => $this->ezcSystemInfoMock->cpuSpeed, - 'cpuCount' => $this->ezcSystemInfoMock->cpuCount, - 'memorySize' => $this->ezcSystemInfoMock->memorySize, - ]), - $value - ); - } -} diff --git a/tests/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollectorTest.php b/tests/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollectorTest.php deleted file mode 100644 index ce36d6f..0000000 --- a/tests/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollectorTest.php +++ /dev/null @@ -1,67 +0,0 @@ -ezcSystemInfoMock = $this - ->getMockBuilder(EzcSystemInfoWrapper::class) - ->disableOriginalConstructor() - ->getMock(); - $this->ezcSystemInfoMock->phpVersion = explode('.', PHP_VERSION); - - $this->ezcSystemInfoMock->phpAccelerator = $this - ->getMockBuilder(ezcSystemInfoAccelerator::class) - ->setConstructorArgs( - [ - 'Zend OPcache', - 'http://www.php.net/opcache', - true, - false, - '7.0.4-devFE', - ] - ) - ->getMock(); - - $this->ezcPhpCollector = new EzcPhpSystemInfoCollector($this->ezcSystemInfoMock); - } - - /** - * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\EzcPhpSystemInfoCollector::collect() - */ - public function testCollect(): void - { - $value = $this->ezcPhpCollector->collect(); - - self::assertInstanceOf(ezcSystemInfoAccelerator::class, $this->ezcSystemInfoMock->phpAccelerator); - - self::assertEquals( - new PhpSystemInfo([ - 'version' => implode('.', $this->ezcSystemInfoMock->phpVersion ?? []), - 'acceleratorEnabled' => $this->ezcSystemInfoMock->phpAccelerator->isEnabled, - 'acceleratorName' => $this->ezcSystemInfoMock->phpAccelerator->name, - 'acceleratorURL' => $this->ezcSystemInfoMock->phpAccelerator->url, - 'acceleratorVersion' => $this->ezcSystemInfoMock->phpAccelerator->versionString, - ]), - $value - ); - } -} diff --git a/tests/bundle/SystemInfo/Collector/HardwareSystemInfoCollectorTest.php b/tests/bundle/SystemInfo/Collector/HardwareSystemInfoCollectorTest.php new file mode 100644 index 0000000..62a4434 --- /dev/null +++ b/tests/bundle/SystemInfo/Collector/HardwareSystemInfoCollectorTest.php @@ -0,0 +1,55 @@ +systemInfoMock = $this + ->getMockBuilder(SystemInfoWrapper::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->systemInfoMock->cpuType = 'Intel(R) Core(TM) i7-3720QM CPU @ 2.60GHz'; + $this->systemInfoMock->cpuSpeed = 2591.9000000000001; + $this->systemInfoMock->cpuCount = 1; + $this->systemInfoMock->memorySize = 1554632704; + + $this->ezcHardware = new HardwareSystemInfoCollector($this->systemInfoMock); + } + + /** + * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\EzcHardwareSystemInfoCollector::collect() + */ + public function testCollect(): void + { + $value = $this->ezcHardware->collect(); + + self::assertEquals( + new HardwareSystemInfo([ + 'cpuType' => $this->systemInfoMock->cpuType, + 'cpuSpeed' => $this->systemInfoMock->cpuSpeed, + 'cpuCount' => $this->systemInfoMock->cpuCount, + 'memorySize' => $this->systemInfoMock->memorySize, + ]), + $value + ); + } +} diff --git a/tests/bundle/SystemInfo/Collector/IbexaSystemInfoCollectorTest.php b/tests/bundle/SystemInfo/Collector/IbexaSystemInfoCollectorTest.php index 8bf3800..c2659cc 100644 --- a/tests/bundle/SystemInfo/Collector/IbexaSystemInfoCollectorTest.php +++ b/tests/bundle/SystemInfo/Collector/IbexaSystemInfoCollectorTest.php @@ -16,7 +16,7 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class IbexaSystemInfoCollectorTest extends TestCase +final class IbexaSystemInfoCollectorTest extends TestCase { private VersionStabilityChecker&MockObject $versionStabilityChecker; @@ -33,16 +33,15 @@ public function testCollect(): void __DIR__ . '/_fixtures/composer.json' ); - $systemInfoCollector = new IbexaSystemInfoCollector( - $composerCollector, - dirname(__DIR__, 5) - ); + $systemInfoCollector = new IbexaSystemInfoCollector($composerCollector); + $systemInfo = $systemInfoCollector->collect(); + self::assertSame(IbexaSystemInfo::PRODUCT_NAME_OSS, $systemInfo->name); self::assertSame(Ibexa::VERSION, $systemInfo->release); // Test that information from the composer.json file is correctly extracted - self::assertSame('dev', $systemInfo->lowestStability); + self::assertSame('stable', $systemInfo->lowestStability); } public function testCollectWithInvalidComposerJson(): void @@ -53,11 +52,10 @@ public function testCollectWithInvalidComposerJson(): void __DIR__ . '/_fixtures/corrupted_composer.json' ); - $systemInfoCollector = new IbexaSystemInfoCollector( - $composerCollector, - dirname(__DIR__, 5) - ); - $systemInfo = $systemInfoCollector->collect(); - self::assertNull($systemInfo->lowestStability); + $systemInfoCollector = new IbexaSystemInfoCollector($composerCollector); + + self::expectNotToPerformAssertions(); + + $systemInfoCollector->collect(); } } diff --git a/tests/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollectorTest.php b/tests/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollectorTest.php index ee0a693..4d8de01 100644 --- a/tests/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollectorTest.php +++ b/tests/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollectorTest.php @@ -4,9 +4,11 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\SystemInfo\SystemInfo\Collector; +use DateTime; use Ibexa\Bundle\SystemInfo\SystemInfo\Collector\JsonComposerLockSystemInfoCollector; use Ibexa\Bundle\SystemInfo\SystemInfo\Exception\ComposerFileValidationException; use Ibexa\Bundle\SystemInfo\SystemInfo\Exception\ComposerJsonFileNotFoundException; @@ -17,7 +19,7 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class JsonComposerLockSystemInfoCollectorTest extends TestCase +final class JsonComposerLockSystemInfoCollectorTest extends TestCase { private VersionStabilityChecker&MockObject $versionStabilityChecker; @@ -33,14 +35,14 @@ public function testCollectWithMinimumStability(): void { $expected = new ComposerSystemInfo([ 'packages' => [ - 'ezsystems/ezpublish-kernel' => new ComposerPackage([ - 'name' => 'ezsystems/ezpublish-kernel', + 'ibexa/core' => new ComposerPackage([ + 'name' => 'ibexa/core', 'branch' => 'dev-master', 'alias' => '7.5.x-dev', 'version' => '7.5.x', 'license' => 'GPL-2.0', 'stability' => 'dev', - 'dateTime' => new \DateTime('2016-02-28 14:30:53'), + 'dateTime' => new DateTime('2016-02-28 14:30:53'), 'homepage' => 'https://ibexa.co', 'reference' => 'ec897baa77c63b745749acf201e85b92bd614723', ]), @@ -50,7 +52,8 @@ public function testCollectWithMinimumStability(): void 'alias' => null, 'version' => '2.5.4', 'license' => 'MIT', - 'dateTime' => new \DateTime('2016-01-05 22:11:12'), + 'stability' => null, + 'dateTime' => new DateTime('2016-01-05 22:11:12'), 'homepage' => 'http://www.doctrine-project.org', 'reference' => 'abbdfd1cff43a7b99d027af3be709bc8fc7d4769', ]), @@ -60,7 +63,8 @@ public function testCollectWithMinimumStability(): void 'alias' => null, 'version' => '2.7.10', 'license' => 'MIT', - 'dateTime' => new \DateTime('2016-02-28 20:37:19'), + 'stability' => null, + 'dateTime' => new DateTime('2016-02-28 20:37:19'), 'homepage' => 'https://symfony.com', 'reference' => '9a3b6bf6ebee49370aaf15abc1bdeb4b1986a67d', ]), @@ -70,7 +74,8 @@ public function testCollectWithMinimumStability(): void 'alias' => null, 'version' => '1.1', 'license' => 'Apache-2.0', - 'dateTime' => new \DateTime('2014-09-27 19:26:09'), + 'stability' => null, + 'dateTime' => new DateTime('2014-09-27 19:26:09'), 'homepage' => 'https://github.com/zetacomponents', 'reference' => 'be0e5b69dde0a51f8d2a036b891964521939769f', ]), @@ -101,6 +106,7 @@ public function testCollectLockFileNotFound(): void __DIR__ . '/_fixtures/snafu.lock', __DIR__ . '/_fixtures/composer.json' ); + $composerCollectorNotFound->collect(); } @@ -116,6 +122,7 @@ public function testCollectJsonFileNotFound(): void __DIR__ . '/_fixtures/composer.lock', __DIR__ . '/_fixtures/snafu.json' ); + $composerCollectorNotFound->collect(); } diff --git a/tests/bundle/SystemInfo/Collector/PhpSystemInfoCollectorTest.php b/tests/bundle/SystemInfo/Collector/PhpSystemInfoCollectorTest.php new file mode 100644 index 0000000..2fad63b --- /dev/null +++ b/tests/bundle/SystemInfo/Collector/PhpSystemInfoCollectorTest.php @@ -0,0 +1,71 @@ +systemInfoMock = $this + ->getMockBuilder(SystemInfoWrapper::class) + ->disableOriginalConstructor() + ->getMock(); + $this->systemInfoMock->phpVersion = explode('.', PHP_VERSION); + + $this->systemInfoMock->phpAccelerator = $this + ->getMockBuilder(ezcSystemInfoAccelerator::class) + ->setConstructorArgs( + [ + 'Zend OPcache', + 'https://www.php.net/opcache', + true, + false, + '7.0.4-devFE', + ] + ) + ->getMock(); + + $this->phpCollector = new PhpSystemInfoCollector($this->systemInfoMock); + } + + /** + * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\EzcPhpSystemInfoCollector::collect() + */ + public function testCollect(): void + { + $value = $this->phpCollector->collect(); + + self::assertInstanceOf( + ezcSystemInfoAccelerator::class, + $this->systemInfoMock->phpAccelerator + ); + + self::assertEquals( + new PhpSystemInfo([ + 'version' => implode('.', $this->systemInfoMock->phpVersion ?? []), + 'acceleratorEnabled' => $this->systemInfoMock->phpAccelerator->isEnabled, + 'acceleratorName' => $this->systemInfoMock->phpAccelerator->name, + 'acceleratorURL' => $this->systemInfoMock->phpAccelerator->url, + 'acceleratorVersion' => $this->systemInfoMock->phpAccelerator->versionString, + ]), + $value + ); + } +} diff --git a/tests/bundle/SystemInfo/Collector/RepositorySystemInfoCollectorTest.php b/tests/bundle/SystemInfo/Collector/RepositorySystemInfoCollectorTest.php index c5b6c24..00dc759 100644 --- a/tests/bundle/SystemInfo/Collector/RepositorySystemInfoCollectorTest.php +++ b/tests/bundle/SystemInfo/Collector/RepositorySystemInfoCollectorTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\SystemInfo\SystemInfo\Collector; @@ -17,7 +18,7 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class RepositorySystemInfoCollectorTest extends TestCase +final class RepositorySystemInfoCollectorTest extends TestCase { private Connection&MockObject $dbalConnectionMock; @@ -31,8 +32,8 @@ class RepositorySystemInfoCollectorTest extends TestCase protected function setUp(): void { - $this->dbalConnectionMock = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock(); - $this->dbalPlatformMock = $this->getMockBuilder(AbstractPlatform::class)->getMock(); + $this->dbalConnectionMock = $this->createMock(Connection::class); + $this->dbalPlatformMock = $this->createMock(AbstractPlatform::class); $this->metricsProviderMock = $this->createMock(MetricsProvider::class); $this->metricsMock = $this->createMock(Metrics::class); @@ -49,9 +50,9 @@ public function testCollect(): void { $expected = new RepositorySystemInfo([ 'type' => 'mysql', - 'name' => 'ezp_platform', + 'name' => 'ibexa_db', 'host' => 'localhost', - 'username' => 'ezp_user', + 'username' => 'ibexa_user', 'repositoryMetrics' => new RepositoryMetrics([ 'publishedCount' => 10, 'usersCount' => 5, diff --git a/tests/bundle/SystemInfo/Collector/ServicesSystemInfoCollectorTest.php b/tests/bundle/SystemInfo/Collector/ServicesSystemInfoCollectorTest.php index 0cd4300..94a9855 100644 --- a/tests/bundle/SystemInfo/Collector/ServicesSystemInfoCollectorTest.php +++ b/tests/bundle/SystemInfo/Collector/ServicesSystemInfoCollectorTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\SystemInfo\SystemInfo\Collector; diff --git a/tests/bundle/SystemInfo/Collector/_fixtures/composer.json b/tests/bundle/SystemInfo/Collector/_fixtures/composer.json index 45e88b7..03a6e62 100644 --- a/tests/bundle/SystemInfo/Collector/_fixtures/composer.json +++ b/tests/bundle/SystemInfo/Collector/_fixtures/composer.json @@ -1,21 +1,20 @@ { - "name": "ezsystems/ezplatform-ee", - "description": "Ibexa Experience distribution", - "homepage": "https://github.com/ezsystems/ezplatform-ee", + "name": "ibexa/commerce", + "description": "Ibexa Commerce distribution", + "homepage": "https://github.com/ibexa/commerce", "license": "proprietary", "type": "project", "authors": [ { "name": "Ibexa dev-team & Ibexa Community", - "homepage": "https://github.com/ezsystems/ezplatform-ee/contributors" + "homepage": "https://github.com/ibexa/commerce/contributors" } ], "repositories": [ { "type": "composer", "url": "https://updates.ibexa.co/bul" } ], "replace": { - "ezsystems/ezstudio": "*", - "ezsystems/ezpublish-community": "*" + "ibexa/phpstan": "*" }, "autoload": { "psr-4": { @@ -38,7 +37,6 @@ "ibexa/admin-ui-assets": "^4.0@dev", "ibexa/cron": "^4.0@dev", "ibexa/design-engine": "^4.0@dev", - "ezsystems/ezplatform-ee-installer": "^2.5", "ibexa/form-builder": "^4.0@dev", "ibexa/graphql": "^4.0@dev", "ibexa/http-cache": "^4.0@dev", @@ -51,10 +49,8 @@ "ibexa/standard-design": "^4.0@dev", "ibexa/user": "^4.0@dev", "ibexa/workflow": "^4.0@dev", - "ezsystems/ezpublish-kernel": "^7.5", - "ezsystems/flex-workflow": "^3.2", - "ezsystems/repository-forms": "^2.5", - "ezsystems/symfony-tools": "~1.0.0", + "ibexa/core": "^7.5", + "ibexa/content-forms": "^2.5", "friendsofsymfony/jsrouting-bundle": "^1.6.3", "gregwar/captcha-bundle": "^2.0", "incenteev/composer-parameter-handler": "^2.1.3", @@ -81,8 +77,7 @@ "behat/mink-selenium2-driver": "^1.3.1", "behat/symfony2-extension": "^2.1.5", "bex/behat-screenshot": "^1.2.7", - "ezsystems/behat-screenshot-image-driver-cloudinary": "^1.1.0", - "ezsystems/behatbundle": "^9.0@dev", + "ibexa/behat": "^9.0@dev", "overblog/graphiql-bundle": "^0.1.2", "phpunit/phpunit": "^6.5.13", "sensio/generator-bundle": "^3.1.7", @@ -98,7 +93,7 @@ "scripts": { "symfony-scripts": [ "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters", - "eZ\\Bundle\\EzPublishCoreBundle\\Composer\\ScriptHandler::clearCache", + "Ibexa\\Bundle\\IbexaCoreBundle\\Composer\\ScriptHandler::clearCache", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile", "@php bin/console bazinga:js-translation:dump web/assets --merge-domains", @@ -113,17 +108,17 @@ "@symfony-scripts" ], "post-create-project-cmd": [ - "eZ\\Bundle\\EzPublishCoreBundle\\Composer\\ScriptHandler::installWelcomeText" + "Ibexa\\Bundle\\IbexaCoreBundle\\Composer\\ScriptHandler::installWelcomeText" ], - "ezplatform-install": [ - "@php bin/console ezplatform:install ezplatform-ee-clean" + "ibexa-install": [ + "@php bin/console ibexa:install ibexa-commerce-clean" ] }, "config": { "bin-dir": "bin", "sort-packages": true, "preferred-install": { - "ezsystems/*": "dist" + "ibexa/*": "dist" } }, "extra": { diff --git a/tests/bundle/SystemInfo/Collector/_fixtures/composer.lock b/tests/bundle/SystemInfo/Collector/_fixtures/composer.lock index 1164d37..5b2db27 100644 --- a/tests/bundle/SystemInfo/Collector/_fixtures/composer.lock +++ b/tests/bundle/SystemInfo/Collector/_fixtures/composer.lock @@ -79,16 +79,16 @@ "time": "2016-01-05 22:11:12" }, { - "name": "ezsystems/ezpublish-kernel", + "name": "ibexa/core", "version": "dev-master", "source": { "type": "git", - "url": "https://github.com/ezsystems/ezpublish-kernel.git", + "url": "https://github.com/ibexa/ibexa/core.git", "reference": "ec897baa77c63b745749acf201e85b92bd614723" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ezsystems/ezpublish-kernel/zipball/ec897baa77c63b745749acf201e85b92bd614723", + "url": "https://api.github.com/repos/ibexa/core/zipball/ec897baa77c63b745749acf201e85b92bd614723", "reference": "ec897baa77c63b745749acf201e85b92bd614723", "shasum": "" }, @@ -355,13 +355,10 @@ "aliases": [], "minimum-stability": "stable", "stability-flags": { - "ezsystems/ezpublish-kernel": 20, - "ezsystems/repository-forms": 20, - "ezsystems/ezplatform-solr-search-engine": 20, - "ezsystems/platform-ui-bundle": 20, - "ezsystems/platform-ui-assets-bundle": 15, - "ezsystems/ez-support-tools": 20, - "ezsystems/behatbundle": 20 + "ibexa/core": 20, + "ibexa/content-forms": 20, + "ibexa/solr": 20, + "ibexa/behat": 20 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/tests/bundle/SystemInfo/Collector/_fixtures/corrupted_composer.lock b/tests/bundle/SystemInfo/Collector/_fixtures/corrupted_composer.lock index 945dd1d..4a08f2f 100644 --- a/tests/bundle/SystemInfo/Collector/_fixtures/corrupted_composer.lock +++ b/tests/bundle/SystemInfo/Collector/_fixtures/corrupted_composer.lock @@ -79,16 +79,16 @@ "time": "2016-01-05 22:11:12" }, { - "name": "ezsystems/ezpublish-kernel", + "name": "ibexa/core", "version": "dev-master", "source": { "type": "git", - "url": "https://github.com/ezsystems/ezpublish-kernel.git", + "url": "https://github.com/ibexa/core.git", "reference": "ec897baa77c63b745749acf201e85b92bd614723" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ezsystems/ezpublish-kernel/zipball/ec897baa77c63b745749acf201e85b92bd614723", + "url": "https://api.github.com/repos/ibexa/core/zipball/ec897baa77c63b745749acf201e85b92bd614723", "reference": "ec897baa77c63b745749acf201e85b92bd614723", "shasum": "" }, @@ -120,9 +120,9 @@ "zetacomponents/mail": "~1.8" }, "replace": { - "ezsystems/ezpublish": "*", - "ezsystems/ezpublish-api": "self.version", - "ezsystems/ezpublish-spi": "self.version" + "ibexa/dxp": "*", + "ibexa/dxp-api": "self.version", + "ibexa/dxp-spi": "self.version" }, "require-dev": { "ezsystems/behatbundle": "^6.1", @@ -355,13 +355,10 @@ "aliases": [], "minimum-stability": "stable", "stability-flags": { - "ezsystems/ezpublish-kernel": 20, - "ezsystems/repository-forms": 20, - "ezsystems/ezplatform-solr-search-engine": 20, - "ezsystems/platform-ui-bundle": 20, - "ezsystems/platform-ui-assets-bundle": 15, - "ezsystems/ez-support-tools": 20, - "ezsystems/behatbundle": 20 + "ibexa/core": 20, + "ibexa/content-forms": 20, + "ibexa/solr": 20, + "ibexa/behat": 20 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/tests/bundle/SystemInfo/Registry/IdentifierBasedTest.php b/tests/bundle/SystemInfo/Registry/IdentifierBasedTest.php index ff1acb0..ebad80c 100644 --- a/tests/bundle/SystemInfo/Registry/IdentifierBasedTest.php +++ b/tests/bundle/SystemInfo/Registry/IdentifierBasedTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\SystemInfo\SystemInfo\Registry; @@ -12,13 +13,11 @@ use Ibexa\Core\Base\Exceptions\NotFoundException; use PHPUnit\Framework\TestCase; -class IdentifierBasedTest extends TestCase +final class IdentifierBasedTest extends TestCase { private IdentifierBased $registry; - /** - * @var \PHPUnit\Framework\MockObject\MockObject[]|\Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector[] - */ + /** @var \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector[] */ private array $testItems; protected function setUp(): void @@ -35,6 +34,8 @@ protected function setUp(): void * Test adding items to the registry, and getting items from it. * * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Registry\IdentifierBased::getItem + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException */ public function testAddAndGetItems(): void { diff --git a/tests/bundle/View/Matcher/SystemInfo/IdentitifierTest.php b/tests/bundle/View/Matcher/SystemInfo/IdentifierTest.php similarity index 94% rename from tests/bundle/View/Matcher/SystemInfo/IdentitifierTest.php rename to tests/bundle/View/Matcher/SystemInfo/IdentifierTest.php index c4b63b7..eb33cdd 100644 --- a/tests/bundle/View/Matcher/SystemInfo/IdentitifierTest.php +++ b/tests/bundle/View/Matcher/SystemInfo/IdentifierTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\SystemInfo\View\Matcher\SystemInfo; @@ -13,7 +14,7 @@ use Ibexa\Core\MVC\Symfony\View\ContentView; use PHPUnit\Framework\TestCase; -class IdentitifierTest extends TestCase +final class IdentifierTest extends TestCase { public function testMatch(): void { diff --git a/tests/bundle/View/SystemInfoViewBuilderTest.php b/tests/bundle/View/SystemInfoViewBuilderTest.php index d4e206c..682e589 100644 --- a/tests/bundle/View/SystemInfoViewBuilderTest.php +++ b/tests/bundle/View/SystemInfoViewBuilderTest.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\Bundle\SystemInfo\View; @@ -15,7 +16,7 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class SystemInfoViewBuilderTest extends TestCase +final class SystemInfoViewBuilderTest extends TestCase { private Configurator&MockObject $configuratorMock; @@ -25,13 +26,23 @@ class SystemInfoViewBuilderTest extends TestCase public function testMatches(): void { - $builder = new SystemInfoViewBuilder($this->getConfiguratorMock(), $this->getRegistryMock()); - self::assertTrue($builder->matches('ibexa.support_tools.view.controller::viewInfoAction')); + $builder = new SystemInfoViewBuilder( + $this->getConfiguratorMock(), + $this->getRegistryMock() + ); + + self::assertTrue( + $builder->matches('ibexa.support_tools.view.controller::viewInfoAction') + ); } public function testNotMatches(): void { - $builder = new SystemInfoViewBuilder($this->getConfiguratorMock(), $this->getRegistryMock()); + $builder = new SystemInfoViewBuilder( + $this->getConfiguratorMock(), + $this->getRegistryMock() + ); + self::assertFalse($builder->matches('service::someAction')); } @@ -54,14 +65,12 @@ public function testBuildView(): void ->will(self::returnValue($systemInfo)); $view = $builder->buildView(['systemInfoIdentifier' => 'test', 'viewType' => 'test']); + self::assertSame($view->getInfo(), $systemInfo); - self::assertEquals($view->getViewType(), 'test'); + self::assertEquals('test', $view->getViewType()); } - /** - * @return \PHPUnit\Framework\MockObject\MockObject&\Ibexa\Core\MVC\Symfony\View\Configurator - */ - protected function getConfiguratorMock(): Configurator + protected function getConfiguratorMock(): MockObject&Configurator { $this->configuratorMock ??= $this->createMock(Configurator::class); diff --git a/tests/lib/EventListener/SystemInfoTabGroupListenerTest.php b/tests/lib/EventListener/SystemInfoTabGroupListenerTest.php index 0ef6235..6ce3d29 100644 --- a/tests/lib/EventListener/SystemInfoTabGroupListenerTest.php +++ b/tests/lib/EventListener/SystemInfoTabGroupListenerTest.php @@ -4,13 +4,13 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\Tests\SystemInfo\EventListener; 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; @@ -18,21 +18,17 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class SystemInfoTabGroupListenerTest extends TestCase +final class SystemInfoTabGroupListenerTest extends TestCase { private TabGroupEvent $event; - private TabRegistry&MockObject $tabRegistry; - private TabFactory&MockObject $tabFactory; protected function setUp(): void { parent::setUp(); - $this->tabRegistry = $this->createMock(TabRegistry::class); $this->tabFactory = $this->createMock(TabFactory::class); - $this->event = new TabGroupEvent(); } @@ -42,7 +38,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); @@ -73,7 +69,10 @@ public function testOnTabGroupPreRender(array $identifiers): void ->method('getIdentifiers') ->willReturn($identifiers); - $systemInfoTabGroupListener = new SystemInfoTabGroupListener($this->tabRegistry, $this->tabFactory, $systemInfoCollectorRegistry); + $systemInfoTabGroupListener = new SystemInfoTabGroupListener( + $this->tabFactory, + $systemInfoCollectorRegistry + ); $tabGroup = new TabGroup('systeminfo', []); $this->event->setData($tabGroup); @@ -84,9 +83,15 @@ public function testOnTabGroupPreRender(array $identifiers): void public function testSubscribedEvents(): void { $systemInfoCollectorRegistry = $this->createMock(SystemInfoCollectorRegistry::class); - $systemInfoTabGroupListener = new SystemInfoTabGroupListener($this->tabRegistry, $this->tabFactory, $systemInfoCollectorRegistry); - - self::assertSame([TabEvents::TAB_GROUP_PRE_RENDER => ['onTabGroupPreRender', 10]], $systemInfoTabGroupListener::getSubscribedEvents()); + $systemInfoTabGroupListener = new SystemInfoTabGroupListener( + $this->tabFactory, + $systemInfoCollectorRegistry + ); + + self::assertSame( + [TabEvents::TAB_GROUP_PRE_RENDER => ['onTabGroupPreRender', 10]], + $systemInfoTabGroupListener::getSubscribedEvents() + ); } /**