diff --git a/src/DependencyInjection/ConditionalTagsExtension.php b/src/DependencyInjection/ConditionalTagsExtension.php index ff811f9874..9d4137dcf3 100644 --- a/src/DependencyInjection/ConditionalTagsExtension.php +++ b/src/DependencyInjection/ConditionalTagsExtension.php @@ -12,7 +12,9 @@ use PHPStan\PhpDoc\TypeNodeResolverExtension; use PHPStan\Rules\RegistryFactory as RuleRegistryFactory; use PHPStan\ShouldNotHappenException; +use function array_reduce; use function count; +use function is_array; use function sprintf; class ConditionalTagsExtension extends CompilerExtension @@ -20,7 +22,7 @@ class ConditionalTagsExtension extends CompilerExtension public function getConfigSchema(): Nette\Schema\Schema { - $bool = Expect::bool(); + $bool = Expect::anyOf(Expect::bool(), Expect::listOf(Expect::bool())); return Expect::arrayOf(Expect::structure([ BrokerFactory::PROPERTIES_CLASS_REFLECTION_EXTENSION_TAG => $bool, BrokerFactory::METHODS_CLASS_REFLECTION_EXTENSION_TAG => $bool, @@ -51,6 +53,9 @@ public function beforeCompile(): void } foreach ($services as $service) { foreach ($tags as $tag => $parameter) { + if (is_array($parameter)) { + $parameter = array_reduce($parameter, static fn ($carry, $item) => $carry && (bool) $item, true); + } if ((bool) $parameter) { $service->addTag($tag); continue; diff --git a/tests/PHPStan/DependencyInjection/ConditionalTagsExtensionTest.php b/tests/PHPStan/DependencyInjection/ConditionalTagsExtensionTest.php new file mode 100644 index 0000000000..a244aa9441 --- /dev/null +++ b/tests/PHPStan/DependencyInjection/ConditionalTagsExtensionTest.php @@ -0,0 +1,35 @@ +getServicesByTag(RuleRegistryFactory::RULE_TAG); + $enabledServices = array_map(static fn ($service) => get_class($service), $enabledServices); + $this->assertNotContains(TestedConditionalServiceDisabled::class, $enabledServices); + $this->assertContains(TestedConditionalServiceEnabled::class, $enabledServices); + $this->assertNotContains(TestedConditionalServiceDisabledDisabled::class, $enabledServices); + $this->assertNotContains(TestedConditionalServiceDisabledEnabled::class, $enabledServices); + $this->assertNotContains(TestedConditionalServiceEnabledDisabled::class, $enabledServices); + $this->assertContains(TestedConditionalServiceEnabledEnabled::class, $enabledServices); + } + + /** + * @return string[] + */ + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/conditionalTags.neon', + ]; + } + +} diff --git a/tests/PHPStan/DependencyInjection/TestedConditionalServiceDisabled.php b/tests/PHPStan/DependencyInjection/TestedConditionalServiceDisabled.php new file mode 100644 index 0000000000..0d0af6673c --- /dev/null +++ b/tests/PHPStan/DependencyInjection/TestedConditionalServiceDisabled.php @@ -0,0 +1,8 @@ +