From 8e9c2c9aef28e5c73746916ae477c1b33e51187a Mon Sep 17 00:00:00 2001 From: Dawid Parafinski Date: Mon, 23 Dec 2024 13:47:36 +0100 Subject: [PATCH] fixed even more issues after CR --- phpstan-baseline.neon | 18 ------------- .../IbexaSystemInfoExtension.php | 5 +--- .../Collector/IbexaSystemInfoCollector.php | 9 +------ .../Registry/IdentifierBasedTest.php | 8 +++--- .../bundle/View/SystemInfoViewBuilderTest.php | 27 ++++++++++--------- 5 files changed, 21 insertions(+), 46 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index ec67bc8..fb338b9 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -23,21 +23,3 @@ parameters: identifier: argument.type count: 3 path: tests/bundle/SystemInfo/Registry/IdentifierBasedTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\SystemInfo\\View\\SystemInfoViewBuilderTest\:\:getCollectorMock\(\) should return Ibexa\\Bundle\\SystemInfo\\SystemInfo\\Collector\\SystemInfoCollector&PHPUnit\\Framework\\MockObject\\MockObject but returns Ibexa\\Bundle\\SystemInfo\\SystemInfo\\Collector\\SystemInfoCollector\.$#' - identifier: return.type - count: 1 - path: tests/bundle/View/SystemInfoViewBuilderTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\SystemInfo\\View\\SystemInfoViewBuilderTest\:\:getConfiguratorMock\(\) should return Ibexa\\Core\\MVC\\Symfony\\View\\Configurator&PHPUnit\\Framework\\MockObject\\MockObject but returns Ibexa\\Core\\MVC\\Symfony\\View\\Configurator\.$#' - identifier: return.type - count: 1 - path: tests/bundle/View/SystemInfoViewBuilderTest.php - - - - message: '#^Method Ibexa\\Tests\\Bundle\\SystemInfo\\View\\SystemInfoViewBuilderTest\:\:getRegistryMock\(\) should return Ibexa\\Bundle\\SystemInfo\\SystemInfo\\SystemInfoCollectorRegistry&PHPUnit\\Framework\\MockObject\\MockObject but returns Ibexa\\Bundle\\SystemInfo\\SystemInfo\\SystemInfoCollectorRegistry\.$#' - identifier: return.type - count: 1 - path: tests/bundle/View/SystemInfoViewBuilderTest.php diff --git a/src/bundle/DependencyInjection/IbexaSystemInfoExtension.php b/src/bundle/DependencyInjection/IbexaSystemInfoExtension.php index 7f2be65..fea6714 100644 --- a/src/bundle/DependencyInjection/IbexaSystemInfoExtension.php +++ b/src/bundle/DependencyInjection/IbexaSystemInfoExtension.php @@ -29,10 +29,7 @@ public function getAlias() return self::EXTENSION_NAME; } - /** - * @return \Ibexa\Bundle\SystemInfo\DependencyInjection\Configuration - */ - public function getConfiguration(array $config, ContainerBuilder $container) + public function getConfiguration(array $config, ContainerBuilder $container): Configuration { return new Configuration(); } diff --git a/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php b/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php index 87d185c..458e9e0 100644 --- a/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php +++ b/src/bundle/SystemInfo/Collector/IbexaSystemInfoCollector.php @@ -145,10 +145,6 @@ class IbexaSystemInfoCollector implements SystemInfoCollector /** @var string */ private $kernelProjectDir; - /** - * @param \Ibexa\Bundle\SystemInfo\SystemInfo\Collector\JsonComposerLockSystemInfoCollector|SystemInfoCollector $composerCollector - * @param bool $debug - */ public function __construct( SystemInfoCollector $composerCollector, string $kernelProjectDir, @@ -251,11 +247,8 @@ private static function getStability(ComposerSystemInfo $composerInfo): string $stabilityFlags[$composerInfo->minimumStability] : $stabilityFlags['stable']; - if ($composerInfo->packages === null) { - return Stability::STABILITIES[$stabilityFlag]; - } // 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; } diff --git a/tests/bundle/SystemInfo/Registry/IdentifierBasedTest.php b/tests/bundle/SystemInfo/Registry/IdentifierBasedTest.php index 0d26ec5..62daae2 100644 --- a/tests/bundle/SystemInfo/Registry/IdentifierBasedTest.php +++ b/tests/bundle/SystemInfo/Registry/IdentifierBasedTest.php @@ -33,7 +33,7 @@ protected function setUp(): void /** * Test adding items to the registry, and getting items from it. * - * @covers \IdentifierBased::getItem + * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Registry\IdentifierBased::getItem */ public function testAddAndGetItems(): void { @@ -46,7 +46,7 @@ public function testAddAndGetItems(): void /** * Test exception when registry item is not found. * - * @covers \IdentifierBased::getItem + * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Registry\IdentifierBased::getItem */ public function testGetItemNotFound(): void { @@ -57,7 +57,7 @@ public function testGetItemNotFound(): void /** * Test replacing an item in the registry. * - * @covers \IdentifierBased::getItem + * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Registry\IdentifierBased::getItem */ public function testReplaceItem(): void { @@ -76,7 +76,7 @@ public function testReplaceItem(): void /** * Test getting all registered identifiers. * - * @covers \IdentifierBased::getIdentifiers + * @covers \Ibexa\Bundle\SystemInfo\SystemInfo\Registry\IdentifierBased::getItem * @depends testAddAndGetItems */ public function testGetIdentifiers(): void diff --git a/tests/bundle/View/SystemInfoViewBuilderTest.php b/tests/bundle/View/SystemInfoViewBuilderTest.php index a859a45..ced8511 100644 --- a/tests/bundle/View/SystemInfoViewBuilderTest.php +++ b/tests/bundle/View/SystemInfoViewBuilderTest.php @@ -15,10 +15,19 @@ class SystemInfoViewBuilderTest extends TestCase { + /** + * @var \PHPUnit\Framework\MockObject\MockObject&\Ibexa\Core\MVC\Symfony\View\Configurator + */ private Configurator $configuratorMock; + /** + * @var \PHPUnit\Framework\MockObject\MockObject&\Ibexa\Bundle\SystemInfo\SystemInfo\SystemInfoCollectorRegistry + */ private SystemInfoCollectorRegistry $registryMock; + /** + * @var \PHPUnit\Framework\MockObject\MockObject&\Ibexa\Bundle\SystemInfo\SystemInfo\Collector\SystemInfoCollector + */ private SystemInfoCollector $collectorMock; public function testMatches(): void @@ -61,9 +70,7 @@ public function testBuildView(): void */ protected function getConfiguratorMock(): Configurator { - if (!isset($this->configuratorMock)) { - $this->configuratorMock = $this->createMock(Configurator::class); - } + $this->configuratorMock ??= $this->createMock(Configurator::class); return $this->configuratorMock; } @@ -73,23 +80,19 @@ protected function getConfiguratorMock(): Configurator */ protected function getRegistryMock(): SystemInfoCollectorRegistry { - if (!isset($this->registryMock)) { - $this->registryMock = $this->createMock( - SystemInfoCollectorRegistry::class - ); - } + $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(): SystemInfoCollector { - if (!isset($this->collectorMock)) { - $this->collectorMock = $this->createMock(SystemInfoCollector::class); - } + $this->collectorMock ??= $this->createMock(SystemInfoCollector::class); return $this->collectorMock; }