diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 47db796420..570d507f87 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -4776,48 +4776,6 @@ parameters: count: 1 path: src/contracts/Collection/MutableArrayList.php - - - message: '#^Binary operation "\." between array\|bool\|float\|int\|string\|null and ''/'' results in an error\.$#' - identifier: binaryOp.invalid - count: 1 - path: src/contracts/Container/Encore/ConfigurationDumper.php - - - - message: '#^Method Ibexa\\Contracts\\Core\\Container\\Encore\\ConfigurationDumper\:\:createFinder\(\) has parameter \$bundlesMetadata with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/contracts/Container/Encore/ConfigurationDumper.php - - - - message: '#^Method Ibexa\\Contracts\\Core\\Container\\Encore\\ConfigurationDumper\:\:dumpConfigurationPaths\(\) has parameter \$paths with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/contracts/Container/Encore/ConfigurationDumper.php - - - - message: '#^Method Ibexa\\Contracts\\Core\\Container\\Encore\\ConfigurationDumper\:\:locateConfigurationFiles\(\) has parameter \$bundlesMetadata with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/contracts/Container/Encore/ConfigurationDumper.php - - - - message: '#^Method Ibexa\\Contracts\\Core\\Container\\Encore\\ConfigurationDumper\:\:locateConfigurationFiles\(\) has parameter \$configFiles with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/contracts/Container/Encore/ConfigurationDumper.php - - - - message: '#^Method Ibexa\\Contracts\\Core\\Container\\Encore\\ConfigurationDumper\:\:locateConfigurationFiles\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/contracts/Container/Encore/ConfigurationDumper.php - - - - message: '#^Parameter \#1 \$bundlesMetadata of method Ibexa\\Contracts\\Core\\Container\\Encore\\ConfigurationDumper\:\:locateConfigurationFiles\(\) expects array, array\|bool\|float\|int\|string\|null given\.$#' - identifier: argument.type - count: 1 - path: src/contracts/Container/Encore/ConfigurationDumper.php - - message: '#^Method Ibexa\\Contracts\\Core\\FieldType\\BinaryBase\\PathGeneratorInterface\:\:getStoragePathForField\(\) has no return type specified\.$#' identifier: missingType.return @@ -41814,12 +41772,6 @@ parameters: count: 1 path: tests/lib/Collection/MutableArrayMapTest.php - - - message: '#^Parameter \#2 \$string of static method PHPUnit\\Framework\\Assert\:\:assertRegExp\(\) expects string, string\|false given\.$#' - identifier: argument.type - count: 2 - path: tests/lib/Container/Encore/ConfigurationDumperTest.php - - message: '#^Method Ibexa\\Tests\\Core\\Event\\BookmarkServiceTest\:\:testCreateBookmarkEvents\(\) has no return type specified\.$#' identifier: missingType.return diff --git a/src/contracts/Container/Encore/ConfigurationDumper.php b/src/contracts/Container/Encore/ConfigurationDumper.php index 92b3736abb..ab556b26f3 100644 --- a/src/contracts/Container/Encore/ConfigurationDumper.php +++ b/src/contracts/Container/Encore/ConfigurationDumper.php @@ -20,8 +20,8 @@ */ final class ConfigurationDumper { - public const ENCORE_DIR = 'encore'; - public const ENCORE_TARGET_PATH = 'var/encore'; + public const string ENCORE_DIR = 'encore'; + public const string ENCORE_TARGET_PATH = 'var/encore'; private ContainerInterface $containerBuilder; @@ -38,8 +38,9 @@ public function __construct(ContainerInterface $containerBuilder) public function dumpCustomConfiguration( array $webpackConfigNames ): void { + /** @var array $bundlesMetadata */ $bundlesMetadata = $this->containerBuilder->getParameter('kernel.bundles_metadata'); - $rootPath = $this->containerBuilder->getParameter('kernel.project_dir') . '/'; + $rootPath = $this->getProjectDirectory() . '/'; foreach ($webpackConfigNames as $configName => $configFiles) { $paths = $this->locateConfigurationFiles($bundlesMetadata, $configFiles, $rootPath); $this->dumpConfigurationPaths( @@ -50,6 +51,12 @@ public function dumpCustomConfiguration( } } + /** + * @param array $bundlesMetadata + * @param array $configFiles + * + * @return array + */ private function locateConfigurationFiles( array $bundlesMetadata, array $configFiles, @@ -67,12 +74,12 @@ private function locateConfigurationFiles( '4.0.0', 'Support for old configuration files is deprecated, please update name of %s file, to %s', $fileInfo->getPathname(), - $options['alternative'] + $options['alternative'] ?? '' ); } $path = $fileInfo->getRealPath(); - if (strpos($path, $rootPath) === 0) { + if (str_starts_with($path, $rootPath)) { $path = './' . substr($path, strlen($rootPath)); } @@ -84,6 +91,8 @@ private function locateConfigurationFiles( } /** + * @param array $paths + * * @throws \JsonException */ private function dumpConfigurationPaths( @@ -98,6 +107,9 @@ private function dumpConfigurationPaths( ); } + /** + * @param array $bundlesMetadata + */ private function createFinder( array $bundlesMetadata, string $configFile, @@ -121,4 +133,14 @@ private function createFinder( return $finder; } + + private function getProjectDirectory(): string + { + $projectDirectory = $this->containerBuilder->getParameter('kernel.project_dir'); + if (!is_string($projectDirectory)) { + throw new \LogicException('Kernel project directory parameter is either not set or is not a string.'); + } + + return $projectDirectory; + } } diff --git a/tests/lib/Container/Encore/ConfigurationDumperTest.php b/tests/lib/Container/Encore/ConfigurationDumperTest.php index 6e337c9d6a..8876af9084 100644 --- a/tests/lib/Container/Encore/ConfigurationDumperTest.php +++ b/tests/lib/Container/Encore/ConfigurationDumperTest.php @@ -18,8 +18,8 @@ */ final class ConfigurationDumperTest extends TestCase { - private const PROJECT_DIR = '/var/io-tests/'; - private const FOO_BAR_BUNDLE_DIR = 'foo-bar'; + private const string PROJECT_DIR = '/var/io-tests/'; + private const string FOO_BAR_BUNDLE_DIR = 'foo-bar'; private Filesystem $filesystem; @@ -64,11 +64,12 @@ public function testDumpCustomConfiguration(): void $compiledFilePath = $this->projectDir . '/var/encore/foo-bar.js'; self::assertFileExists($compiledFilePath); $compiledFileContents = file_get_contents($compiledFilePath); - self::assertRegExp( + self::assertNotFalse($compiledFileContents, "Failed to read compiled file '$compiledFilePath' contents"); + self::assertMatchesRegularExpression( '@^module\.exports = \[.*io-tests\\\/foo-bar\\\/Resources\\\/encore\\\/foo-bar\.js@', $compiledFileContents ); - self::assertRegExp( + self::assertMatchesRegularExpression( '@^module\.exports = \[.*io-tests\\\/encore\\\/foo-bar\.js@', $compiledFileContents );