diff --git a/.travis.yml b/.travis.yml index c2cc7a5d..5a0d9d04 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,7 +57,7 @@ jobs: - mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{.disabled,} - if [[ ! $(php -m | grep -si xdebug) ]]; then echo "xdebug required for mutation"; exit 1; fi script: - - ./vendor/bin/infection -s --min-msi=98 --min-covered-msi=98 --threads=$(nproc) + - ./vendor/bin/infection -s --min-msi=100 --min-covered-msi=100 --threads=$(nproc) - stage: Quality env: STATIC_ANALYSIS=1 diff --git a/composer.json b/composer.json index 244f14e0..a77a40f8 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,7 @@ "infection/infection": "^0.15", "lcobucci/coding-standard": "^4.0", "mikey179/vfsstream": "^1.6.8", + "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^0.12", "phpstan/phpstan-deprecation-rules": "^0.12", "phpstan/phpstan-phpunit": "^0.12", diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 6cc785c1..673b56c6 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,12 +1,5 @@ -includes: - - vendor/phpstan/phpstan-phpunit/extension.neon - - vendor/phpstan/phpstan-phpunit/rules.neon - - vendor/phpstan/phpstan-strict-rules/rules.neon - - vendor/phpstan/phpstan-deprecation-rules/rules.neon - parameters: level: 7 paths: - src - test - checkMissingIterableValueType: false diff --git a/src/Compiler.php b/src/Compiler.php index 22f28f98..f72d1bbd 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -16,6 +16,7 @@ use function class_exists; use function dirname; use function is_array; +use function is_int; use function is_string; final class Compiler @@ -55,13 +56,15 @@ private function configurePassList( ContainerConfiguration $config ): void { foreach ($config->getPassList() as $passConfig) { - assert(is_array($passConfig)); [$pass, $type, $priority] = $passConfig + self::DEFAULT_PASS_CONFIG; + assert(is_string($type)); + assert(is_int($priority)); if (! $pass instanceof CompilerPassInterface) { [$className, $constructArguments] = $pass; $pass = new $className(...$constructArguments); + assert($pass instanceof CompilerPassInterface); } $container->addCompilerPass($pass, $type, $priority); diff --git a/src/CompilerPassListProvider.php b/src/CompilerPassListProvider.php index c192e96d..404c83ae 100644 --- a/src/CompilerPassListProvider.php +++ b/src/CompilerPassListProvider.php @@ -5,8 +5,12 @@ use Generator as DefaultGenerator; use Lcobucci\DependencyInjection\Config\Package; +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; interface CompilerPassListProvider extends Package { + /** + * @return DefaultGenerator>>> + */ public function getCompilerPasses(): DefaultGenerator; } diff --git a/src/Config/ContainerConfiguration.php b/src/Config/ContainerConfiguration.php index 9c39e183..4e30317d 100644 --- a/src/Config/ContainerConfiguration.php +++ b/src/Config/ContainerConfiguration.php @@ -28,7 +28,7 @@ final class ContainerConfiguration private array $files; /** - * @var mixed[] + * @var array>>> */ private array $passList; @@ -97,6 +97,9 @@ public function addPackage(string $className, array $constructArguments = []): v $this->packages[] = [$className, $constructArguments]; } + /** + * @return Generator + */ public function getFiles(): Generator { foreach ($this->filterPackages(FileListProvider::class) as $package) { @@ -126,6 +129,9 @@ public function addFile(string $file): void $this->files[] = $file; } + /** + * @return Generator>>> + */ public function getPassList(): Generator { foreach ($this->filterPackages(CompilerPassListProvider::class) as $package) { diff --git a/src/FileListProvider.php b/src/FileListProvider.php index cfedd3bc..eb5edeab 100644 --- a/src/FileListProvider.php +++ b/src/FileListProvider.php @@ -8,5 +8,8 @@ interface FileListProvider extends Package { + /** + * @return DefaultGenerator + */ public function getFiles(): DefaultGenerator; } diff --git a/test/CompilerTest.php b/test/CompilerTest.php index babd5c8b..cd7eb0f3 100644 --- a/test/CompilerTest.php +++ b/test/CompilerTest.php @@ -14,7 +14,6 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Config\ConfigCache; use Symfony\Component\DependencyInjection\Compiler\PassConfig; -use function assert; use function count; use function file_put_contents; use function iterator_to_array; @@ -86,8 +85,6 @@ public function compileShouldCreateMultipleFiles(): void self::assertCount(count($expectedFiles), $generatedFiles); foreach ($generatedFiles as $name => $file) { - assert($file instanceof vfsStreamFile); - self::assertContains($name, $expectedFiles); self::assertSame($expectedPermissions, $file->getPermissions()); } @@ -141,6 +138,9 @@ public function compilationShouldBeSkippedWhenFileAlreadyExists(): void self::assertCount(1, $generatedFiles); } + /** + * @return PHPGenerator + */ private function getGeneratedFiles(vfsStreamDirectory $directory): PHPGenerator { foreach ($directory->getChildren() as $child) { @@ -150,9 +150,11 @@ private function getGeneratedFiles(vfsStreamDirectory $directory): PHPGenerator continue; } - if ($child->getName() !== 'services.yml') { - yield $child->getName() => $child; + if (! $child instanceof vfsStreamFile || $child->getName() === 'services.yml') { + continue; } + + yield $child->getName() => $child; } } } diff --git a/test/Config/ContainerConfigurationTest.php b/test/Config/ContainerConfigurationTest.php index 9e6c2082..c26571c5 100644 --- a/test/Config/ContainerConfigurationTest.php +++ b/test/Config/ContainerConfigurationTest.php @@ -62,6 +62,9 @@ public function getFilesShouldYieldTheFilesFromPackagesFirst(): void { $package1 = new class implements CompilerPassListProvider { + /** + * @return Generator>>> + */ public function getCompilerPasses(): Generator { yield [CompilerPassInterface::class, 'beforeOptimization']; @@ -70,6 +73,9 @@ public function getCompilerPasses(): Generator $package2 = new class implements FileListProvider { + /** + * @return Generator + */ public function getFiles(): Generator { yield 'services2.xml'; diff --git a/test/ContainerBuilderTest.php b/test/ContainerBuilderTest.php index 6bc3c16e..301a0f4d 100644 --- a/test/ContainerBuilderTest.php +++ b/test/ContainerBuilderTest.php @@ -15,6 +15,7 @@ use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\DependencyInjection\ContainerInterface; use function get_class; +use function iterator_to_array; final class ContainerBuilderTest extends TestCase { @@ -278,7 +279,7 @@ public function getContainerShouldGenerateAndReturnTheContainer(): void $this->generator->expects(self::once()) ->method('generate') - ->with($this->config, self::equalTo(new ConfigCache($this->config->getDumpFile(), false))) + ->with($this->config, new ConfigCache($this->config->getDumpFile(), false)) ->willReturn($container); self::assertSame($container, $builder->getContainer()); @@ -307,9 +308,13 @@ public function getTestContainerShouldGenerateAndReturnTheContainer(): void $this->generator->expects(self::once()) ->method('generate') - ->with(self::equalTo($config), self::equalTo($cacheConfig)) + ->with($config, $cacheConfig) ->willReturn($container); self::assertSame($container, $builder->getTestContainer()); + + $compilerPasses = iterator_to_array($this->config->getPassList()); + self::assertCount(1, $compilerPasses); + self::assertSame($this->parameterBag, $compilerPasses[0][0]); } }