diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c53e8d1..4bc85af 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -65,6 +65,9 @@ jobs: - name: Run test suite run: composer run-script --timeout=600 test + - name: Run PHPStan analysis + run: composer run-script phpstan + integration-tests: name: Integration yests needs: tests diff --git a/composer.json b/composer.json index 2343626..79b09e1 100644 --- a/composer.json +++ b/composer.json @@ -22,13 +22,17 @@ "ibexa/fieldtype-richtext": "~5.0.x-dev", "ibexa/http-cache": "~5.0.x-dev", "ibexa/notifications": "~5.0.x-dev", + "ibexa/phpstan": "~5.0.x-dev", "ibexa/rest": "~5.0.x-dev", "ibexa/search": "~5.0.x-dev", "ibexa/test-core": "~5.0.x-dev", "ibexa/user": "~5.0.x-dev", "hautelook/templated-uri-bundle": "^3.4", "matthiasnoback/symfony-dependency-injection-test": "^4.0", - "phpunit/phpunit": "^9.6" + "phpunit/phpunit": "^9.6", + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpstan/phpstan-symfony": "^2.0" }, "autoload": { "psr-4": { @@ -53,7 +57,8 @@ "fix-cs": "php-cs-fixer fix --config=.php-cs-fixer.php -v --show-progress=dots", "check-cs": "@fix-cs --dry-run", "test": "phpunit -c phpunit.xml", - "test-integration": "phpunit -c phpunit.integration.xml" + "test-integration": "phpunit -c phpunit.integration.xml", + "phpstan": "phpstan analyse" }, "config": { "allow-plugins": false, diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..fb338b9 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,25 @@ +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/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..e0188e8 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,15 @@ +includes: + - phpstan-baseline.neon + - vendor/phpstan/phpstan-phpunit/extension.neon + - vendor/phpstan/phpstan-symfony/extension.neon + - vendor/ibexa/phpstan/extension.neon + +parameters: + level: 8 + paths: + - src + - tests + treatPhpDocTypesAsCertain: false + ignoreErrors: + - + message: "#^Cannot call method (fetchOne|fetchColumn|fetchAllAssociative|fetchAssociative|fetchAllKeyValue|fetchFirstColumn)\\(\\) on Doctrine\\\\DBAL\\\\ForwardCompatibility\\\\Result\\|int\\|string\\.$#" diff --git a/src/bundle/Command/SystemInfoDumpCommand.php b/src/bundle/Command/SystemInfoDumpCommand.php index 33b067e..6bd32dd 100644 --- a/src/bundle/Command/SystemInfoDumpCommand.php +++ b/src/bundle/Command/SystemInfoDumpCommand.php @@ -29,10 +29,7 @@ public function __construct(SystemInfoCollectorRegistry $systemInfoCollectorRegi parent::__construct(); } - /** - * Define command and input options. - */ - protected function configure() + protected function configure(): void { $this ->setName('ibexa:system-info:dump') @@ -79,9 +76,9 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output): int { if ($input->getOption('list-info-collectors')) { - $output->writeln('Available info collectors:', true); + $output->writeln('Available info collectors:', OutputInterface::OUTPUT_NORMAL); foreach ($this->systemInfoCollectorRegistry->getIdentifiers() as $identifier) { - $output->writeln(" $identifier", true); + $output->writeln(" $identifier", OutputInterface::OUTPUT_NORMAL); } return Command::SUCCESS; diff --git a/src/bundle/Controller/SystemInfoController.php b/src/bundle/Controller/SystemInfoController.php index cc17b97..f19f2ac 100644 --- a/src/bundle/Controller/SystemInfoController.php +++ b/src/bundle/Controller/SystemInfoController.php @@ -26,7 +26,7 @@ public function __construct(SystemInfoCollectorRegistry $collectorRegistry) $this->collectorRegistry = $collectorRegistry; } - public function performAccessCheck() + public function performAccessCheck(): void { parent::performAccessCheck(); $this->denyAccessUnlessGranted(new Attribute('setup', 'system_info')); @@ -44,22 +44,19 @@ public function infoAction(): Response ]); } - public function viewInfoAction(SystemInfoView $view) + public function viewInfoAction(SystemInfoView $view): SystemInfoView { return $view; } /** * Renders a PHP info page. - * - * @return \Symfony\Component\HttpFoundation\Response */ public function phpinfoAction(): Response { ob_start(); phpinfo(); - $response = new Response(ob_get_clean()); - return $response; + return new Response(ob_get_clean() ?: ''); } } diff --git a/src/bundle/DependencyInjection/Compiler/OutputFormatPass.php b/src/bundle/DependencyInjection/Compiler/OutputFormatPass.php index e2663e5..4f6734b 100644 --- a/src/bundle/DependencyInjection/Compiler/OutputFormatPass.php +++ b/src/bundle/DependencyInjection/Compiler/OutputFormatPass.php @@ -19,7 +19,7 @@ class OutputFormatPass implements CompilerPassInterface * * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { if (!$container->has(OutputFormatRegistry::class)) { return; diff --git a/src/bundle/DependencyInjection/Compiler/SystemInfoCollectorPass.php b/src/bundle/DependencyInjection/Compiler/SystemInfoCollectorPass.php index 9a1518f..2b118aa 100644 --- a/src/bundle/DependencyInjection/Compiler/SystemInfoCollectorPass.php +++ b/src/bundle/DependencyInjection/Compiler/SystemInfoCollectorPass.php @@ -15,12 +15,7 @@ class SystemInfoCollectorPass implements CompilerPassInterface { - /** - * Registers the SystemInfoCollector into the system info collector registry. - * - * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container - */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { if (!$container->has(IdentifierBased::class)) { return; diff --git a/src/bundle/DependencyInjection/Compiler/SystemInfoTabGroupPass.php b/src/bundle/DependencyInjection/Compiler/SystemInfoTabGroupPass.php index 1215869..6507435 100644 --- a/src/bundle/DependencyInjection/Compiler/SystemInfoTabGroupPass.php +++ b/src/bundle/DependencyInjection/Compiler/SystemInfoTabGroupPass.php @@ -19,12 +19,10 @@ class SystemInfoTabGroupPass implements CompilerPassInterface { /** - * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container - * * @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException * @throws \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { if (!$container->hasDefinition(TabRegistry::class)) { return; diff --git a/src/bundle/DependencyInjection/IbexaSystemInfoExtension.php b/src/bundle/DependencyInjection/IbexaSystemInfoExtension.php index 85aaa77..6ecc22b 100644 --- a/src/bundle/DependencyInjection/IbexaSystemInfoExtension.php +++ b/src/bundle/DependencyInjection/IbexaSystemInfoExtension.php @@ -12,7 +12,6 @@ use Ibexa\Bundle\SystemInfo\SystemInfo\Collector\IbexaSystemInfoCollector; use Ibexa\Bundle\SystemInfo\SystemInfo\Value\IbexaSystemInfo; use Ibexa\Contracts\Core\Ibexa; -use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; @@ -30,7 +29,7 @@ public function getAlias(): string return self::EXTENSION_NAME; } - public function getConfiguration(array $config, ContainerBuilder $container): ?ConfigurationInterface + public function getConfiguration(array $config, ContainerBuilder $container): Configuration { return new Configuration(); } @@ -38,7 +37,7 @@ public function getConfiguration(array $config, ContainerBuilder $container): ?C /** * {@inheritdoc} */ - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $loader = new Loader\YamlFileLoader( $container, @@ -62,7 +61,7 @@ public function load(array $configs, ContainerBuilder $container) } } - public function prepend(ContainerBuilder $container) + public function prepend(ContainerBuilder $container): void { $this->prependJMSTranslation($container); } diff --git a/src/bundle/IbexaSystemInfoBundle.php b/src/bundle/IbexaSystemInfoBundle.php index 25582cb..1426a81 100644 --- a/src/bundle/IbexaSystemInfoBundle.php +++ b/src/bundle/IbexaSystemInfoBundle.php @@ -17,7 +17,7 @@ class IbexaSystemInfoBundle extends Bundle { - public function build(ContainerBuilder $container) + public function build(ContainerBuilder $container): void { parent::build($container); $container->addCompilerPass(new SystemInfoCollectorPass()); diff --git a/src/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollector.php b/src/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollector.php index 503247d..fada46e 100644 --- a/src/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollector.php @@ -33,10 +33,13 @@ class ConfigurationSymfonyKernelSystemInfoCollector implements SystemInfoCollect * 'AsseticBundle' => 'Symfony\\Bundle\\AsseticBundle\\AsseticBundle', * ) * - * @var array + * @var array */ private $bundles; + /** + * @param array $bundles + */ public function __construct(Kernel $kernel, array $bundles) { $this->kernel = $kernel; diff --git a/src/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollector.php b/src/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollector.php index 8d3eb4c..b478a0b 100644 --- a/src/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollector.php @@ -29,8 +29,6 @@ public function __construct(EzcSystemInfoWrapper $ezcSystemInfo) * Collects information about the PHP installation Ibexa DXP is using. * - php version * - php accelerator info. - * - * @return \Ibexa\Bundle\SystemInfo\SystemInfo\Value\PhpSystemInfo */ public function collect(): PhpSystemInfo { diff --git a/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php b/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php index 1b38d9d..0c803f7 100644 --- a/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php @@ -128,7 +128,10 @@ public function __construct( string $kernelProjectDir, ) { try { - $this->composerInfo = $composerCollector->collect(); + $composerInfo = $composerCollector->collect(); + if ($composerInfo instanceof ComposerSystemInfo) { + $this->composerInfo = $composerInfo; + } } catch (ComposerLockFileNotFoundException | ComposerFileValidationException $e) { // do nothing } @@ -194,9 +197,6 @@ private function extractComposerInfo(IbexaSystemInfo $ibexa): void $ibexa->lowestStability = self::getStability($this->composerInfo); } - /** - * @throws \Exception - */ private function getEOMDate(string $ibexaRelease): ?DateTime { return isset(self::EOM[$ibexaRelease]) ? @@ -204,9 +204,6 @@ private function getEOMDate(string $ibexaRelease): ?DateTime null; } - /** - * @throws \Exception - */ private function getEOLDate(string $ibexaRelease): ?DateTime { return isset(self::EOL[$ibexaRelease]) ? @@ -224,7 +221,7 @@ private static function getStability(ComposerSystemInfo $composerInfo): string $stabilityFlags['stable']; // Check if any of the watched packages has lower stability than root - foreach ($composerInfo->packages as $name => $package) { + foreach ($composerInfo->packages ?? [] as $name => $package) { if (!preg_match(self::PACKAGE_WATCH_REGEX, $name)) { continue; } @@ -241,6 +238,9 @@ private static function getStability(ComposerSystemInfo $composerInfo): string return Stability::STABILITIES[$stabilityFlag]; } + /** + * @param list $packageNames + */ private static function hasAnyPackage( ComposerSystemInfo $composerInfo, array $packageNames diff --git a/src/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php b/src/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php index 4514737..55c73ae 100644 --- a/src/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollector.php @@ -21,28 +21,21 @@ class JsonComposerLockSystemInfoCollector implements SystemInfoCollector { public const IBEXA_OSS_PACKAGE = 'ibexa/oss'; - /** @var \Ibexa\SystemInfo\VersionStability\VersionStabilityChecker */ - private $versionStabilityChecker; + private VersionStabilityChecker $versionStabilityChecker; - /** - * @var string Composer lock file with full path. - */ - private $lockFile; + private string $lockFile; - /** - * @var string Composer json file with full path. - */ - private $jsonFile; + private string $jsonFile; /** - * @var \Ibexa\Bundle\SystemInfo\SystemInfo\Value\ComposerSystemInfo The collected value, cached in case info is collected by other collectors. + * The collected value, cached in case info is collected by other collectors. */ - private $value; + private ?ComposerSystemInfo $value = null; public function __construct( VersionStabilityChecker $versionStabilityChecker, - $lockFile, - $jsonFile + string $lockFile, + string $jsonFile ) { $this->versionStabilityChecker = $versionStabilityChecker; $this->lockFile = $lockFile; @@ -52,13 +45,9 @@ public function __construct( /** * Collects information about installed composer packages. * - * @return \Ibexa\Bundle\SystemInfo\SystemInfo\Value\ComposerSystemInfo - * * @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. - * - * @return \Ibexa\Bundle\SystemInfo\SystemInfo\Value\ComposerSystemInfo */ public function collect(): ComposerSystemInfo { @@ -74,8 +63,8 @@ public function collect(): ComposerSystemInfo throw new Exception\ComposerJsonFileNotFoundException($this->jsonFile); } - $lockData = json_decode(file_get_contents($this->lockFile), true); - $jsonData = json_decode(file_get_contents($this->jsonFile), true); + $lockData = json_decode(file_get_contents($this->lockFile) ?: '', true); + $jsonData = json_decode(file_get_contents($this->jsonFile) ?: '', true); if (!is_array($lockData)) { throw new Exception\ComposerFileValidationException($this->lockFile); @@ -87,7 +76,7 @@ public function collect(): ComposerSystemInfo $stability = InstalledVersions::isInstalled(self::IBEXA_OSS_PACKAGE) ? $this->versionStabilityChecker->getStability( - InstalledVersions::getVersion(self::IBEXA_OSS_PACKAGE) + InstalledVersions::getVersion(self::IBEXA_OSS_PACKAGE) ?? '' ) : $this->getMinimumStability($lockData); @@ -99,7 +88,7 @@ public function collect(): ComposerSystemInfo } /** - * @param array $lockData + * @param array $lockData * * @return \Ibexa\Bundle\SystemInfo\SystemInfo\Value\ComposerPackage[] */ @@ -146,7 +135,7 @@ private function extractPackages(array $lockData): array } /** - * @param array $jsonData + * @param array $jsonData * * @return string[] */ @@ -190,6 +179,9 @@ private static function setNormalizedVersion(ComposerPackage $package): void $package->version = $version; } + /** + * @param array $lockData + */ private function getMinimumStability(array $lockData): ?string { return $lockData['minimum-stability'] ?? null; diff --git a/src/bundle/SystemInfo/Exception/ComposerFileValidationException.php b/src/bundle/SystemInfo/Exception/ComposerFileValidationException.php index 565f513..2c327c8 100644 --- a/src/bundle/SystemInfo/Exception/ComposerFileValidationException.php +++ b/src/bundle/SystemInfo/Exception/ComposerFileValidationException.php @@ -11,7 +11,7 @@ final class ComposerFileValidationException extends Exception implements SystemInfoException { - public function __construct(string $path, $code = 0, Exception $previous = null) + public function __construct(string $path, int $code = 0, Exception $previous = null) { $message = sprintf('Composer file %s is not valid.', $path); diff --git a/src/bundle/SystemInfo/Exception/ComposerLockFileNotFoundException.php b/src/bundle/SystemInfo/Exception/ComposerLockFileNotFoundException.php index ac8c6d4..ae5f124 100644 --- a/src/bundle/SystemInfo/Exception/ComposerLockFileNotFoundException.php +++ b/src/bundle/SystemInfo/Exception/ComposerLockFileNotFoundException.php @@ -12,7 +12,7 @@ class ComposerLockFileNotFoundException extends BaseNotFoundException implements SystemInfoException { - public function __construct($path, Exception $previous = null) + public function __construct(string $path, Exception $previous = null) { parent::__construct('composer.lock file', $path, $previous); } diff --git a/src/bundle/SystemInfo/EzcSystemInfoWrapper.php b/src/bundle/SystemInfo/EzcSystemInfoWrapper.php index 0c7f1f2..3dc309d 100644 --- a/src/bundle/SystemInfo/EzcSystemInfoWrapper.php +++ b/src/bundle/SystemInfo/EzcSystemInfoWrapper.php @@ -8,6 +8,7 @@ namespace Ibexa\Bundle\SystemInfo\SystemInfo; use ezcSystemInfo; +use ezcSystemInfoAccelerator; use ezcSystemInfoReaderCantScanOSException; /** @@ -16,41 +17,30 @@ */ class EzcSystemInfoWrapper { - /** @var string */ - public $osType; + public ?string $osType; - /** @var string */ - public $osName; + public ?string $osName; - /** @var string */ - public $fileSystemType; + public ?string $fileSystemType; - /** @var int */ - public $cpuCount; + public ?int $cpuCount; - /** @var string */ - public $cpuType; + public ?string $cpuType; - /** @var float */ - public $cpuSpeed; + public ?float $cpuSpeed; /** @var int */ - public $memorySize; + public ?int $memorySize; - /** @var string */ - public $lineSeparator; + public ?string $lineSeparator; - /** @var string */ - public $backupFileName; + public ?string $backupFileName; - /** @var array */ - public $phpVersion; + public ?string $phpVersion; - /** @var \ezcSystemInfoAccelerator */ - public $phpAccelerator; + public ?ezcSystemInfoAccelerator $phpAccelerator; - /** @var bool */ - public $isShellExecution; + public ?bool $isShellExecution; public function __construct() { diff --git a/src/bundle/SystemInfo/OutputFormat.php b/src/bundle/SystemInfo/OutputFormat.php index 13a3a47..e35ec4d 100644 --- a/src/bundle/SystemInfo/OutputFormat.php +++ b/src/bundle/SystemInfo/OutputFormat.php @@ -12,7 +12,7 @@ interface OutputFormat /** * Format an array of collected information data, and return it as string. * - * @param array $collectedInfo + * @param array $collectedInfo * * @return string */ diff --git a/src/bundle/SystemInfo/OutputFormat/JsonOutputFormat.php b/src/bundle/SystemInfo/OutputFormat/JsonOutputFormat.php index 2da4d6a..8d40d40 100644 --- a/src/bundle/SystemInfo/OutputFormat/JsonOutputFormat.php +++ b/src/bundle/SystemInfo/OutputFormat/JsonOutputFormat.php @@ -16,6 +16,11 @@ class JsonOutputFormat implements SystemInfoOutputFormat { public function format(array $collectedInfo) { - return json_encode($collectedInfo, JSON_PRETTY_PRINT); + $json = json_encode($collectedInfo, JSON_PRETTY_PRINT); + if ($json === false) { + return ''; + } + + return $json; } } diff --git a/src/bundle/SystemInfo/OutputFormatRegistry.php b/src/bundle/SystemInfo/OutputFormatRegistry.php index 2cd5f04..514ab61 100644 --- a/src/bundle/SystemInfo/OutputFormatRegistry.php +++ b/src/bundle/SystemInfo/OutputFormatRegistry.php @@ -15,7 +15,7 @@ class OutputFormatRegistry { /** @var \Ibexa\Bundle\SystemInfo\SystemInfo\OutputFormat[] */ - private $registry = []; + private array $registry = []; /** * @param \Ibexa\Bundle\SystemInfo\SystemInfo\OutputFormat[] $items Hash of OutputFormats, with identifier string as key. @@ -26,15 +26,9 @@ public function __construct(array $items = []) } /** - * Returns the OutputFormat matching the argument. - * - * @param string $identifier An identifier string. - * * @throws \Ibexa\Core\Base\Exceptions\NotFoundException If no OutputFormat exists with this identifier - * - * @return \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\OutputFormat The OutputFormat given by the identifier. */ - public function getItem($identifier) + public function getItem(string $identifier): OutputFormat { if (isset($this->registry[$identifier])) { return $this->registry[$identifier]; @@ -48,7 +42,7 @@ public function getItem($identifier) * * @return string[] Array of identifier strings. */ - public function getIdentifiers() + public function getIdentifiers(): array { return array_keys($this->registry); } diff --git a/src/bundle/SystemInfo/Value/IbexaSystemInfo.php b/src/bundle/SystemInfo/Value/IbexaSystemInfo.php index af792f9..723bfcd 100644 --- a/src/bundle/SystemInfo/Value/IbexaSystemInfo.php +++ b/src/bundle/SystemInfo/Value/IbexaSystemInfo.php @@ -7,6 +7,7 @@ namespace Ibexa\Bundle\SystemInfo\SystemInfo\Value; +use DateTime; use Ibexa\Contracts\Core\Repository\Values\ValueObject; /** @@ -57,7 +58,7 @@ class IbexaSystemInfo extends ValueObject implements SystemInfo * * @see https://support.ibexa.co/Public/Service-Life */ - public $endOfMaintenanceDate; + public ?DateTime $endOfMaintenanceDate; /** * @var bool @@ -71,7 +72,7 @@ class IbexaSystemInfo extends ValueObject implements SystemInfo * * @see https://support.ibexa.co/Public/Service-Life */ - public $endOfLifeDate; + public ?DateTime $endOfLifeDate; /** * @var bool diff --git a/src/bundle/SystemInfo/Value/SymfonyKernelSystemInfo.php b/src/bundle/SystemInfo/Value/SymfonyKernelSystemInfo.php index ccb158f..858754c 100644 --- a/src/bundle/SystemInfo/Value/SymfonyKernelSystemInfo.php +++ b/src/bundle/SystemInfo/Value/SymfonyKernelSystemInfo.php @@ -50,7 +50,7 @@ class SymfonyKernelSystemInfo extends ValueObject implements SystemInfo * 'AsseticBundle' => 'Symfony\\Bundle\\AsseticBundle\\AsseticBundle', * ) * - * @var array + * @var array */ public $bundles; diff --git a/src/bundle/View/Matcher/SystemInfo/Identifier.php b/src/bundle/View/Matcher/SystemInfo/Identifier.php index 3664aee..6617b86 100644 --- a/src/bundle/View/Matcher/SystemInfo/Identifier.php +++ b/src/bundle/View/Matcher/SystemInfo/Identifier.php @@ -15,32 +15,18 @@ class Identifier implements ViewMatcherInterface { /** * Matched SystemInfo identifier. Example: 'php', 'hardware'... - * - * @var string */ - private $identifier; + private string $identifier; - /** - * Registers the matching configuration for the matcher. - * It's up to the implementor to validate $matchingConfig since it can be anything configured by the end-developer. - * - * @param mixed $matchingConfig - * - * @throws \InvalidArgumentException Should be thrown if $matchingConfig is not valid. - */ - public function setMatchingConfig($matchingConfig) + public function setMatchingConfig($matchingConfig): void { $this->identifier = $matchingConfig; } /** * Matches the $view against a set of matchers. - * - * @param \Ibexa\Bundle\SystemInfo\View\SystemInfoView $view - * - * @return bool */ - public function match(View $view) + public function match(View $view): bool { if (!$view instanceof SystemInfoView) { return false; @@ -49,7 +35,7 @@ public function match(View $view) return $this->toIdentifier($view->getInfo()) === $this->identifier; } - private function toIdentifier($object) + private function toIdentifier(object $object): string { $className = \get_class($object); $className = substr($className, strrpos($className, '\\') + 1); diff --git a/src/bundle/View/SystemInfoView.php b/src/bundle/View/SystemInfoView.php index 6347bd9..bd593ca 100644 --- a/src/bundle/View/SystemInfoView.php +++ b/src/bundle/View/SystemInfoView.php @@ -7,37 +7,30 @@ namespace Ibexa\Bundle\SystemInfo\View; +use Ibexa\Bundle\SystemInfo\SystemInfo\Value\SystemInfo; use Ibexa\Core\MVC\Symfony\View\BaseView; use Ibexa\Core\MVC\Symfony\View\View; class SystemInfoView extends BaseView implements View { - /** - * @var \Ibexa\Bundle\SystemInfo\SystemInfo\Value\SystemInfo - */ - private $info; + private SystemInfo $info; - /** - * @param \Ibexa\Bundle\SystemInfo\SystemInfo\Value\SystemInfo $info - * - * @return SystemInfoView - */ - public function setInfo($info) + public function setInfo(SystemInfo $info): self { $this->info = $info; return $this; } - /** - * @return \Ibexa\Bundle\SystemInfo\SystemInfo\Value\SystemInfo - */ - public function getInfo() + public function getInfo(): SystemInfo { return $this->info; } - protected function getInternalParameters() + /** + * @return array{info: \Ibexa\Bundle\SystemInfo\SystemInfo\Value\SystemInfo} + */ + protected function getInternalParameters(): array { return ['info' => $this->info]; } diff --git a/src/bundle/View/SystemInfoViewBuilder.php b/src/bundle/View/SystemInfoViewBuilder.php index 8f986cb..0578b14 100644 --- a/src/bundle/View/SystemInfoViewBuilder.php +++ b/src/bundle/View/SystemInfoViewBuilder.php @@ -7,11 +7,13 @@ namespace Ibexa\Bundle\SystemInfo\View; +use Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector; use Ibexa\Bundle\SystemInfo\SystemInfo\Exception\SystemInfoException; use Ibexa\Bundle\SystemInfo\SystemInfo\SystemInfoCollectorRegistry; 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 { @@ -33,12 +35,17 @@ public function __construct(Configurator $viewConfigurator, SystemInfoCollectorR $this->registry = $registry; } - public function matches($argument) + public function matches($argument): bool { return $argument === 'ibexa.support_tools.view.controller:viewInfoAction'; } - public function buildView(array $parameters) + /** + * @param array $parameters + * + * @return \Ibexa\Bundle\SystemInfo\View\SystemInfoView + */ + public function buildView(array $parameters): View { $collector = $this->getCollector($parameters['systemInfoIdentifier']); $view = new SystemInfoView(null, [], $parameters['viewType']); @@ -58,10 +65,8 @@ public function buildView(array $parameters) /** * @param string $identifier A SystemInfo collector identifier (php, hardware...) - * - * @return \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector */ - private function getCollector($identifier) + private function getCollector(string $identifier): SystemInfoCollector { return $this->registry->getItem($identifier); } diff --git a/src/lib/Component/Dashboard/EzInfoTwigComponent.php b/src/lib/Component/Dashboard/EzInfoTwigComponent.php index 11443da..8158bc8 100644 --- a/src/lib/Component/Dashboard/EzInfoTwigComponent.php +++ b/src/lib/Component/Dashboard/EzInfoTwigComponent.php @@ -14,27 +14,21 @@ class EzInfoTwigComponent implements Renderable { - /** @var string */ - protected $template; + protected string $template; - /** @var \Twig\Environment */ - protected $twig; + protected Environment $twig; - /** @var array */ - protected $parameters; + /** @var array */ + protected array $parameters; - /** @var \Ibexa\Bundle\SystemInfo\SystemInfo\Value\IbexaSystemInfo */ - private $ibexaSystemInfo; + private IbexaSystemInfo $ibexaSystemInfo; - /** @var array */ - private $urlList; + /** @var array */ + private array $urlList; /** - * @param \Twig\Environment $twig - * @param string $template - * @param \Ibexa\Bundle\SystemInfo\SystemInfo\Value\IbexaSystemInfo $ibexaSystemInfo - * @param array $urlList - * @param array $parameters + * @param array $urlList + * @param array $parameters */ public function __construct( Environment $twig, @@ -51,9 +45,7 @@ public function __construct( } /** - * @param array $parameters - * - * @return string + * @param array $parameters */ public function render(array $parameters = []): string { @@ -66,13 +58,13 @@ public function render(array $parameters = []): string } /** - * @return array + * @return array */ private function replaceUrlPlaceholders(): array { $urls = $this->urlList; foreach ($this->urlList as $urlName => $url) { - foreach ($this->ibexaSystemInfo as $attribute => $value) { + 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); } diff --git a/src/lib/EventListener/ConfigureMainMenuListener.php b/src/lib/EventListener/ConfigureMainMenuListener.php index 2c27a1e..ad0bf88 100644 --- a/src/lib/EventListener/ConfigureMainMenuListener.php +++ b/src/lib/EventListener/ConfigureMainMenuListener.php @@ -45,7 +45,11 @@ public function onMenuConfigure(ConfigureMenuEvent $event): void return; } - $menu->getChild(MainMenuBuilder::ITEM_ADMIN)->addChild( + $adminMenu = $menu->getChild(MainMenuBuilder::ITEM_ADMIN); + 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 7f0c3e9..981af91 100644 --- a/src/lib/EventListener/SystemInfoTabGroupListener.php +++ b/src/lib/EventListener/SystemInfoTabGroupListener.php @@ -40,9 +40,6 @@ public function __construct( $this->systeminfoCollectorRegistry = $systeminfoCollectorRegistry; } - /** - * @return array - */ public static function getSubscribedEvents(): array { return [ @@ -50,10 +47,7 @@ public static function getSubscribedEvents(): array ]; } - /** - * @param \Ibexa\AdminUi\Tab\Event\TabGroupEvent $event - */ - public function onTabGroupPreRender(TabGroupEvent $event) + public function onTabGroupPreRender(TabGroupEvent $event): void { $tabGroup = $event->getData(); diff --git a/src/lib/Value/Stability.php b/src/lib/Value/Stability.php index 85b40a4..8472d07 100644 --- a/src/lib/Value/Stability.php +++ b/src/lib/Value/Stability.php @@ -11,7 +11,7 @@ final class Stability { /** - * @var array Hash of stability constant values to human readable stabilities, see Composer\Package\BasePackage. + * @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. */ diff --git a/tests/bundle/DependencyInjection/Compiler/SystemInfoTabGroupPassTest.php b/tests/bundle/DependencyInjection/Compiler/SystemInfoTabGroupPassTest.php index 2deec69..10a8224 100644 --- a/tests/bundle/DependencyInjection/Compiler/SystemInfoTabGroupPassTest.php +++ b/tests/bundle/DependencyInjection/Compiler/SystemInfoTabGroupPassTest.php @@ -31,7 +31,7 @@ protected function registerCompilerPass(ContainerBuilder $container): void $container->addCompilerPass(new SystemInfoTabGroupPass()); } - public function testProcess() + public function testProcess(): void { $tabGroupDefinition = new Definition(TabGroup::class, ['systeminfo']); diff --git a/tests/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollectorTest.php b/tests/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollectorTest.php index 25efd0b..407b14f 100644 --- a/tests/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollectorTest.php +++ b/tests/bundle/SystemInfo/Collector/ConfigurationSymfonyKernelSystemInfoCollectorTest.php @@ -17,7 +17,7 @@ class ConfigurationSymfonyKernelSystemInfoCollectorTest extends TestCase /** * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\ConfigurationSymfonyKernelSystemInfoCollector::collect() */ - public function testCollect() + public function testCollect(): void { $expected = new SymfonyKernelSystemInfo([ 'environment' => 'dev', @@ -76,8 +76,6 @@ public function testCollect() $value = $symfonyCollector->collect(); - self::assertInstanceOf('Ibexa\\Bundle\\SystemInfo\\SystemInfo\\Value\\SymfonyKernelSystemInfo', $value); - self::assertEquals($expected, $value); } } diff --git a/tests/bundle/SystemInfo/Collector/EzcHardwareSystemInfoCollectorTest.php b/tests/bundle/SystemInfo/Collector/EzcHardwareSystemInfoCollectorTest.php index 5d49c5a..90cc6c1 100644 --- a/tests/bundle/SystemInfo/Collector/EzcHardwareSystemInfoCollectorTest.php +++ b/tests/bundle/SystemInfo/Collector/EzcHardwareSystemInfoCollectorTest.php @@ -8,6 +8,7 @@ namespace Ibexa\Tests\Bundle\SystemInfo\SystemInfo\Collector; use Ibexa\Bundle\SystemInfo\SystemInfo\Collector\EzcHardwareSystemInfoCollector; +use Ibexa\Bundle\SystemInfo\SystemInfo\EzcSystemInfoWrapper; use Ibexa\Bundle\SystemInfo\SystemInfo\Value\HardwareSystemInfo; use PHPUnit\Framework\TestCase; @@ -26,13 +27,13 @@ class EzcHardwareSystemInfoCollectorTest extends TestCase protected function setUp(): void { $this->ezcSystemInfoMock = $this - ->getMockBuilder('Ibexa\\Bundle\\SystemInfo\\SystemInfo\\EzcSystemInfoWrapper') + ->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->ezcSystemInfoMock->cpuSpeed = 2591.9000000000001; + $this->ezcSystemInfoMock->cpuCount = 1; + $this->ezcSystemInfoMock->memorySize = 1554632704; $this->ezcHardware = new EzcHardwareSystemInfoCollector($this->ezcSystemInfoMock); } @@ -40,11 +41,11 @@ protected function setUp(): void /** * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\EzcHardwareSystemInfoCollector::collect() */ - public function testCollect() + public function testCollect(): void { $value = $this->ezcHardware->collect(); - self::assertInstanceOf('Ibexa\\Bundle\\SystemInfo\\SystemInfo\\Value\\HardwareSystemInfo', $value); + self::assertInstanceOf(HardwareSystemInfo::class, $value); self::assertEquals( new HardwareSystemInfo([ diff --git a/tests/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollectorTest.php b/tests/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollectorTest.php index 93928fb..d57b6e1 100644 --- a/tests/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollectorTest.php +++ b/tests/bundle/SystemInfo/Collector/EzcPhpSystemInfoCollectorTest.php @@ -7,7 +7,9 @@ namespace Ibexa\Tests\Bundle\SystemInfo\SystemInfo\Collector; +use ezcSystemInfoAccelerator; use Ibexa\Bundle\SystemInfo\SystemInfo\Collector\EzcPhpSystemInfoCollector; +use Ibexa\Bundle\SystemInfo\SystemInfo\EzcSystemInfoWrapper; use Ibexa\Bundle\SystemInfo\SystemInfo\Value\PhpSystemInfo; use PHPUnit\Framework\TestCase; @@ -26,13 +28,13 @@ class EzcPhpSystemInfoCollectorTest extends TestCase protected function setUp(): void { $this->ezcSystemInfoMock = $this - ->getMockBuilder('Ibexa\\Bundle\\SystemInfo\\SystemInfo\\EzcSystemInfoWrapper') + ->getMockBuilder(EzcSystemInfoWrapper::class) ->disableOriginalConstructor() ->getMock(); $this->ezcSystemInfoMock->phpVersion = PHP_VERSION; $this->ezcSystemInfoMock->phpAccelerator = $this - ->getMockBuilder('ezcSystemInfoAccelerator') + ->getMockBuilder(ezcSystemInfoAccelerator::class) ->setConstructorArgs( [ 'Zend OPcache', @@ -50,11 +52,12 @@ protected function setUp(): void /** * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\EzcPhpSystemInfoCollector::collect() */ - public function testCollect() + public function testCollect(): void { $value = $this->ezcPhpCollector->collect(); - self::assertInstanceOf('Ibexa\\Bundle\\SystemInfo\\SystemInfo\\Value\\PhpSystemInfo', $value); + self::assertInstanceOf(PhpSystemInfo::class, $value); + self::assertInstanceOf(ezcSystemInfoAccelerator::class, $this->ezcSystemInfoMock->phpAccelerator); self::assertEquals( new PhpSystemInfo([ diff --git a/tests/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollectorTest.php b/tests/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollectorTest.php index 91b0037..659f255 100644 --- a/tests/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollectorTest.php +++ b/tests/bundle/SystemInfo/Collector/JsonComposerLockSystemInfoCollectorTest.php @@ -86,7 +86,6 @@ public function testCollectWithMinimumStability(): void ); $value = $composerCollector->collect(); - self::assertInstanceOf('Ibexa\\Bundle\\SystemInfo\\SystemInfo\\Value\\ComposerSystemInfo', $value); self::assertEquals($expected, $value); } diff --git a/tests/bundle/SystemInfo/Collector/RepositorySystemInfoCollectorTest.php b/tests/bundle/SystemInfo/Collector/RepositorySystemInfoCollectorTest.php index dbc4839..34ecba3 100644 --- a/tests/bundle/SystemInfo/Collector/RepositorySystemInfoCollectorTest.php +++ b/tests/bundle/SystemInfo/Collector/RepositorySystemInfoCollectorTest.php @@ -24,7 +24,7 @@ class RepositorySystemInfoCollectorTest extends TestCase private $dbalConnectionMock; /** - * @var \Doctrine\DBAL\Platforms\MySqlPlatform|\PHPUnit\Framework\MockObject\MockObject + * @var \Doctrine\DBAL\Platforms\AbstractPlatform&\PHPUnit\Framework\MockObject\MockObject */ private $dbalPlatformMock; @@ -59,7 +59,7 @@ protected function setUp(): void /** * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\RepositorySystemInfoCollector::collect() */ - public function testCollect() + public function testCollect(): void { $expected = new RepositorySystemInfo([ 'type' => 'mysql', diff --git a/tests/bundle/SystemInfo/Registry/IdentifierBasedTest.php b/tests/bundle/SystemInfo/Registry/IdentifierBasedTest.php index c9b9248..ff1acb0 100644 --- a/tests/bundle/SystemInfo/Registry/IdentifierBasedTest.php +++ b/tests/bundle/SystemInfo/Registry/IdentifierBasedTest.php @@ -7,27 +7,25 @@ namespace Ibexa\Tests\Bundle\SystemInfo\SystemInfo\Registry; +use Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector; use Ibexa\Bundle\SystemInfo\SystemInfo\Registry\IdentifierBased; use Ibexa\Core\Base\Exceptions\NotFoundException; use PHPUnit\Framework\TestCase; class IdentifierBasedTest extends TestCase { - /** - * @var \Ibexa\Bundle\SystemInfo\SystemInfo\Registry\IdentifierBasedEzcPhpSystemInfoCollector - */ - private $registry; + private IdentifierBased $registry; /** * @var \PHPUnit\Framework\MockObject\MockObject[]|\Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector[] */ - private $testItems; + private array $testItems; protected function setUp(): void { $this->testItems = [ - 'foo' => $this->createMock('Ibexa\\Bundle\\SystemInfo\\SystemInfo\\Collector\\SystemInfoCollector'), - 'bar' => $this->createMock('Ibexa\\Bundle\\SystemInfo\\SystemInfo\\Collector\\SystemInfoCollector'), + 'foo' => $this->createMock(SystemInfoCollector::class), + 'bar' => $this->createMock(SystemInfoCollector::class), ]; $this->registry = new IdentifierBased(); @@ -36,9 +34,9 @@ protected function setUp(): void /** * Test adding items to the registry, and getting items from it. * - * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Registry\IdentifierBased::getItem() + * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Registry\IdentifierBased::getItem */ - public function testAddAndGetItems() + public function testAddAndGetItems(): void { $this->registry = new IdentifierBased($this->testItems); @@ -49,9 +47,9 @@ public function testAddAndGetItems() /** * Test exception when registry item is not found. * - * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Registry\IdentifierBased::getItem() + * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Registry\IdentifierBased::getItem */ - public function testGetItemNotFound() + public function testGetItemNotFound(): void { $this->expectException(NotFoundException::class); $this->registry->getItem('notfound'); @@ -60,9 +58,9 @@ public function testGetItemNotFound() /** * Test replacing an item in the registry. * - * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Registry\IdentifierBased::getItem() + * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Registry\IdentifierBased::getItem */ - public function testReplaceItem() + public function testReplaceItem(): void { $this->registry = new IdentifierBased($this->testItems); @@ -79,11 +77,11 @@ public function testReplaceItem() /** * Test getting all registered identifiers. * - * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Registry\IdentifierBased::getIdentifiers() + * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Registry\IdentifierBased::getItem * * @depends testAddAndGetItems */ - public function testGetIdentifiers() + public function testGetIdentifiers(): void { $this->registry = new IdentifierBased($this->testItems); diff --git a/tests/bundle/View/Matcher/SystemInfo/IdentitifierTest.php b/tests/bundle/View/Matcher/SystemInfo/IdentitifierTest.php index aeec29e..c4b63b7 100644 --- a/tests/bundle/View/Matcher/SystemInfo/IdentitifierTest.php +++ b/tests/bundle/View/Matcher/SystemInfo/IdentitifierTest.php @@ -15,7 +15,7 @@ class IdentitifierTest extends TestCase { - public function testMatch() + public function testMatch(): void { $view = new SystemInfoView(); $view->setInfo(new HardwareSystemInfo()); @@ -26,7 +26,7 @@ public function testMatch() self::assertTrue($matcher->match($view)); } - public function testNoMatch() + public function testNoMatch(): void { $view = new SystemInfoView(); $view->setInfo(new HardwareSystemInfo()); @@ -37,7 +37,7 @@ public function testNoMatch() self::assertFalse($matcher->match($view)); } - public function testMatchOtherView() + public function testMatchOtherView(): void { $view = new ContentView(); diff --git a/tests/bundle/View/SystemInfoViewBuilderTest.php b/tests/bundle/View/SystemInfoViewBuilderTest.php index f71a3d3..1b6994d 100644 --- a/tests/bundle/View/SystemInfoViewBuilderTest.php +++ b/tests/bundle/View/SystemInfoViewBuilderTest.php @@ -7,31 +7,43 @@ namespace Ibexa\Tests\Bundle\SystemInfo\View; +use Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector; +use Ibexa\Bundle\SystemInfo\SystemInfo\SystemInfoCollectorRegistry; use Ibexa\Bundle\SystemInfo\SystemInfo\Value\SystemInfo; use Ibexa\Bundle\SystemInfo\View\SystemInfoViewBuilder; +use Ibexa\Core\MVC\Symfony\View\Configurator; use PHPUnit\Framework\TestCase; class SystemInfoViewBuilderTest extends TestCase { - private $configuratorMock; + /** + * @var \PHPUnit\Framework\MockObject\MockObject&\Ibexa\Core\MVC\Symfony\View\Configurator + */ + private Configurator $configuratorMock; - private $registryMock; + /** + * @var \PHPUnit\Framework\MockObject\MockObject&\Ibexa\Bundle\SystemInfo\SystemInfo\SystemInfoCollectorRegistry + */ + private SystemInfoCollectorRegistry $registryMock; - private $collectorMock; + /** + * @var \PHPUnit\Framework\MockObject\MockObject&\Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector + */ + private SystemInfoCollector $collectorMock; - public function testMatches() + public function testMatches(): void { $builder = new SystemInfoViewBuilder($this->getConfiguratorMock(), $this->getRegistryMock()); self::assertTrue($builder->matches('ibexa.support_tools.view.controller:viewInfoAction')); } - public function testNotMatches() + public function testNotMatches(): void { $builder = new SystemInfoViewBuilder($this->getConfiguratorMock(), $this->getRegistryMock()); self::assertFalse($builder->matches('service:someAction')); } - public function testBuildView() + public function testBuildView(): void { $builder = new SystemInfoViewBuilder( $this->getConfiguratorMock(), @@ -55,37 +67,33 @@ public function testBuildView() } /** - * @return \PHPUnit\Framework\MockObject\MockObject|\Ibexa\Core\MVC\Symfony\View\Configurator + * @return \PHPUnit\Framework\MockObject\MockObject&\Ibexa\Core\MVC\Symfony\View\Configurator */ - protected function getConfiguratorMock() + protected function getConfiguratorMock(): Configurator { - if (!isset($this->configuratorMock)) { - $this->configuratorMock = $this->createMock('Ibexa\\Core\\MVC\\Symfony\\View\\Configurator'); - } + $this->configuratorMock ??= $this->createMock(Configurator::class); return $this->configuratorMock; } /** - * @return \PHPUnit\Framework\MockObject\MockObject|\Ibexa\Bundle\SystemInfo\SystemInfo\SystemInfoCollectorRegistry + * @return \PHPUnit\Framework\MockObject\MockObject&\Ibexa\Bundle\SystemInfo\SystemInfo\SystemInfoCollectorRegistry */ - protected function getRegistryMock() + protected function getRegistryMock(): SystemInfoCollectorRegistry { - if (!isset($this->registryMock)) { - $this->registryMock = $this->createMock('Ibexa\\Bundle\\SystemInfo\\SystemInfo\\SystemInfoCollectorRegistry'); - } + $this->registryMock ??= $this->createMock( + SystemInfoCollectorRegistry::class + ); return $this->registryMock; } /** - * @return \PHPUnit\Framework\MockObject\MockObject|\Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector + * @return \PHPUnit\Framework\MockObject\MockObject&\Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector */ - protected function getCollectorMock() + protected function getCollectorMock(): SystemInfoCollector { - if (!isset($this->collectorMock)) { - $this->collectorMock = $this->createMock('Ibexa\\Bundle\\SystemInfo\\SystemInfo\\Collector\\SystemInfoCollector'); - } + $this->collectorMock ??= $this->createMock(SystemInfoCollector::class); return $this->collectorMock; } diff --git a/tests/lib/EventListener/SystemInfoTabGroupListenerTest.php b/tests/lib/EventListener/SystemInfoTabGroupListenerTest.php index e25a6db..3ce3d30 100644 --- a/tests/lib/EventListener/SystemInfoTabGroupListenerTest.php +++ b/tests/lib/EventListener/SystemInfoTabGroupListenerTest.php @@ -16,20 +16,12 @@ use Ibexa\SystemInfo\Tab\SystemInfo\SystemInfoTab; use Ibexa\SystemInfo\Tab\SystemInfo\TabFactory; use PHPUnit\Framework\TestCase; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\HttpKernelInterface; class SystemInfoTabGroupListenerTest extends TestCase { - /** @var \Symfony\Component\HttpFoundation\Request */ - private $request; - /** @var \Ibexa\AdminUi\Tab\Event\TabGroupEvent */ private $event; - /** @var \Symfony\Component\HttpKernel\HttpKernelInterface|\PHPUnit\Framework\MockObject\MockObject */ - private $httpKernel; - /** @var \PHPUnit\Framework\MockObject\MockObject|\Ibexa\AdminUi\Tab\TabRegistry */ private $tabRegistry; @@ -43,13 +35,10 @@ protected function setUp(): void $this->tabRegistry = $this->createMock(TabRegistry::class); $this->tabFactory = $this->createMock(TabFactory::class); - $this->request = $this->createMock(Request::class); - - $this->httpKernel = $this->createMock(HttpKernelInterface::class); $this->event = new TabGroupEvent(); } - public function testOnTabGroupPreRenderWithNoSystemInfoTabGroup() + public function testOnTabGroupPreRenderWithNoSystemInfoTabGroup(): void { $systemInfoCollectorRegistry = $this->createMock(SystemInfoCollectorRegistry::class); $systemInfoCollectorRegistry->expects(self::never()) @@ -94,7 +83,7 @@ public function testOnTabGroupPreRender(array $identifiers): void $systemInfoTabGroupListener->onTabGroupPreRender($this->event); } - public function testSubscribedEvents() + public function testSubscribedEvents(): void { $systemInfoCollectorRegistry = $this->createMock(SystemInfoCollectorRegistry::class); $systemInfoTabGroupListener = new SystemInfoTabGroupListener($this->tabRegistry, $this->tabFactory, $systemInfoCollectorRegistry); @@ -102,6 +91,9 @@ public function testSubscribedEvents() self::assertSame([TabEvents::TAB_GROUP_PRE_RENDER => ['onTabGroupPreRender', 10]], $systemInfoTabGroupListener::getSubscribedEvents()); } + /** + * @return array>> + */ public function dataProvider(): array { return [ diff --git a/tests/lib/VersionStability/VersionStabilityCheckerTest.php b/tests/lib/VersionStability/VersionStabilityCheckerTest.php index 8164dd2..3453b73 100644 --- a/tests/lib/VersionStability/VersionStabilityCheckerTest.php +++ b/tests/lib/VersionStability/VersionStabilityCheckerTest.php @@ -32,6 +32,9 @@ public function testIsStableVersion(string $stableVersion): void ); } + /** + * @return iterable + */ public function provideStableVersions(): iterable { yield ['1.0.0.0']; @@ -51,6 +54,9 @@ public function testIsNotStableVersion(string $notStableVersion): void ); } + /** + * @return iterable + */ public function provideNotStableVersions(): iterable { yield ['1.0.20']; @@ -79,6 +85,9 @@ public function testGetStability( ); } + /** + * @return iterable + */ public function provideVersions(): iterable { yield ['0.1.10.50', Stability::STABILITIES[0]];