diff --git a/.composer-require-checker.json b/.composer-require-checker.json index 2c63c08..7ec31a8 100644 --- a/.composer-require-checker.json +++ b/.composer-require-checker.json @@ -1,2 +1,17 @@ { + "symbol-whitelist" : [ + "null", "true", "false", + "self", "parent", + "array", "string", "int", "float", "bool", "iterable", "callable", "void", "object", + "Contao\\ManagerPlugin\\Bundle\\BundlePluginInterface", + "Contao\\ManagerPlugin\\Bundle\\Config\\BundleConfig", + "Contao\\ManagerPlugin\\Bundle\\Parser\\ParserInterface", + "Contao\\ManagerPlugin\\Config\\ConfigPluginInterface", + "Contao\\ManagerPlugin\\Routing\\RoutingPluginInterface", + "CyberSpectrum\\I18N\\MetaModels\\MetaModelDictionaryDefinitionBuilder", + "CyberSpectrum\\I18N\\MetaModels\\MetaModelDictionaryProvider", + "MadeYourDay\\RockSolidCustomElements\\RockSolidCustomElementsBundle", + "MetaModels\\CoreBundle\\MetaModelsCoreBundle", + "Terminal42\\ChangeLanguage\\Terminal42ChangeLanguageBundle" + ] } diff --git a/composer.json b/composer.json index dee5df1..7bac0d4 100644 --- a/composer.json +++ b/composer.json @@ -22,13 +22,17 @@ }, "require": { "php": "^7.1.3", + "ext-json": "*", "contao/core-bundle": "^4.4.0", "cyberspectrum/i18n": "dev-fix/phpcq-2 as 1.0.0@dev", "cyberspectrum/i18n-bundle": "dev-fix/phpcq-2 as 1.0.0@dev", "cyberspectrum/i18n-contao": "dev-fix/phpcq-2 as 1.0.0@dev", "cyberspectrum/i18n-xliff": "dev-fix/phpcq-2 as 1.0.0@dev", + "psr/log": "^1.1.4 || ^2.0 || ^3.0", "symfony/config": "^3.4 || ^4.1 || ^5.0", + "symfony/console": "^3.4 || ^4.1 || ^5.0", "symfony/dependency-injection": "^4.4 || ^5.4 || ^6.0", + "symfony/error-handler": "^4.4 || ^5.4 || ^6.0", "symfony/form": "^4.4 || ^5.4 || ^6.0", "symfony/framework-bundle": "^4.4 || ^5.4 || ^6.0", "symfony/http-foundation": "^4.4 || ^5.4 || ^6.0", @@ -42,7 +46,6 @@ "contao-community-alliance/dc-general": "^2.1", "contao/manager-plugin": "^2.6.0", "cyberspectrum/i18n-metamodels": "dev-fix/phpcq-2 as 1.0.0@dev", - "metamodels/core": "^2.1", "phpcq/runner-bootstrap": "^1.0@dev" }, "suggest": { diff --git a/src/Command/DebugMapCommand.php b/src/Command/DebugMapCommand.php index 8ef3f86..e2eedf6 100644 --- a/src/Command/DebugMapCommand.php +++ b/src/Command/DebugMapCommand.php @@ -1,23 +1,6 @@ - * @copyright 2019 CyberSpectrum. - * @license https://github.com/cyberspectrum/i18n-contao-bundle/blob/master/LICENSE MIT - * @filesource - */ - -declare(strict_types = 1); +declare(strict_types=1); namespace CyberSpectrum\I18N\ContaoBundle\Command; @@ -33,12 +16,8 @@ */ class DebugMapCommand extends Command { - /** - * The map builder. - * - * @var MapBuilderInterface - */ - private $mapBuilder; + /** The map builder. */ + private MapBuilderInterface $mapBuilder; /** * Create a new instance. @@ -51,28 +30,25 @@ public function __construct(MapBuilderInterface $mapBuilder) $this->mapBuilder = $mapBuilder; } - /** - * {@inheritDoc} - */ protected function configure(): void { parent::configure(); $this->setName('debug:i18n-map'); $this->setDescription('Dump the mapping'); - $this->addArgument('table', InputArgument::OPTIONAL, 'The table name'); - $this->addArgument('source-language', InputArgument::OPTIONAL, 'The source language'); - $this->addArgument('target-language', InputArgument::OPTIONAL, 'The target language'); + $this->addArgument('table', InputArgument::REQUIRED, 'The table name'); + $this->addArgument('source-language', InputArgument::REQUIRED, 'The source language'); + $this->addArgument('target-language', InputArgument::REQUIRED, 'The target language'); } - /** - * {@inheritDoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { - $tableName = $input->getArgument('table'); + $tableName = $input->getArgument('table'); + assert(is_string($tableName)); $sourceLanguage = $input->getArgument('source-language'); + assert(is_string($sourceLanguage)); $targetLanguage = $input->getArgument('target-language'); + assert(is_string($targetLanguage)); $tableMap = $this->mapBuilder->getMappingFor($tableName, $sourceLanguage, $targetLanguage); $keys = $tableMap->sourceIds(); @@ -83,5 +59,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } $table->render(); + + return 0; } } diff --git a/src/ContaoManager/Plugin.php b/src/ContaoManager/Plugin.php index c63eeef..1cdb404 100644 --- a/src/ContaoManager/Plugin.php +++ b/src/ContaoManager/Plugin.php @@ -1,23 +1,6 @@ - * @copyright 2018 CyberSpectrum. - * @license https://github.com/cyberspectrum/i18n-contao-bundle/blob/master/LICENSE MIT - * @filesource - */ - -declare(strict_types = 1); +declare(strict_types=1); namespace CyberSpectrum\I18N\ContaoBundle\ContaoManager; @@ -27,13 +10,14 @@ use Contao\ManagerPlugin\Bundle\Parser\ParserInterface; use Contao\ManagerPlugin\Config\ConfigPluginInterface; use Contao\ManagerPlugin\Routing\RoutingPluginInterface; -use CyberSpectrum\I18N\ContaoBundle\CyberSpectrumI18NContaoBundle; use CyberSpectrum\I18NBundle\CyberSpectrumI18NBundle; +use CyberSpectrum\I18N\ContaoBundle\CyberSpectrumI18NContaoBundle; use MetaModels\CoreBundle\MetaModelsCoreBundle; use Symfony\Bundle\FrameworkBundle\FrameworkBundle; use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\Config\Loader\LoaderResolverInterface; use Symfony\Component\HttpKernel\KernelInterface; +use Symfony\Component\Routing\RouteCollection; /** * Plugin for the Contao Manager. @@ -43,7 +27,7 @@ class Plugin implements BundlePluginInterface, ConfigPluginInterface, RoutingPlu /** * {@inheritdoc} */ - public function getBundles(ParserInterface $parser) + public function getBundles(ParserInterface $parser): array { return [ BundleConfig::create(CyberSpectrumI18NContaoBundle::class) @@ -62,18 +46,26 @@ public function getBundles(ParserInterface $parser) /** * {@inheritDoc} */ - public function registerContainerConfiguration(LoaderInterface $loader, array $managerConfig) + public function registerContainerConfiguration(LoaderInterface $loader, array $managerConfig): void { $loader->load('@CyberSpectrumI18NContaoBundle/Resources/contao-manager/framework.yml'); } /** * {@inheritDoc} + * + * @psalm-suppress MixedInferredReturnType + * @psalm-suppress MixedReturnStatement */ - public function getRouteCollection(LoaderResolverInterface $resolver, KernelInterface $kernel) + public function getRouteCollection(LoaderResolverInterface $resolver, KernelInterface $kernel): ?RouteCollection { - return $resolver - ->resolve(__DIR__.'/../Resources/config/contao/routing.yml') - ->load(__DIR__.'/../Resources/config/contao/routing.yml'); + $loader = $resolver->resolve(__DIR__ . '/../Resources/config/contao/routing.yml'); + + if (!$loader instanceof LoaderInterface) { + throw new \RuntimeException('Failed to load routes'); + } + + return $loader + ->load(__DIR__ . '/../Resources/config/contao/routing.yml'); } } diff --git a/src/Controller/ContaoInspectProblemsController.php b/src/Controller/ContaoInspectProblemsController.php index 17b33c0..9dce9d3 100644 --- a/src/Controller/ContaoInspectProblemsController.php +++ b/src/Controller/ContaoInspectProblemsController.php @@ -1,68 +1,39 @@ - * @copyright 2018 CyberSpectrum. - * @license https://github.com/cyberspectrum/i18n-contao-bundle/blob/master/LICENSE MIT - * @filesource - */ - -declare(strict_types = 1); +declare(strict_types=1); namespace CyberSpectrum\I18N\ContaoBundle\Controller; use CyberSpectrum\I18N\Contao\Mapping\MapBuilderInterface; use CyberSpectrum\I18N\Contao\Mapping\Terminal42ChangeLanguage\ArticleMap; use CyberSpectrum\I18N\ContaoBundle\FormType\InspectMappingFormType; +use Psr\Log\LoggerAwareInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Symfony\Component\Debug\BufferingLogger; +use Symfony\Component\ErrorHandler\BufferingLogger; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Csrf\CsrfTokenManager; use Symfony\Component\Templating\EngineInterface; +use function in_array; +use function strtr; + /** * This allows to inspect dictionary problems in the Contao backend. */ class ContaoInspectProblemsController extends AbstractController { - /** - * The twig engine. - * - * @var EngineInterface - */ - private $templating; + /** The twig engine. */ + private EngineInterface $templating; - /** - * The Contao map builder. - * - * @var MapBuilderInterface - */ - private $mapBuilder; + /** The Contao map builder. */ + private MapBuilderInterface $mapBuilder; - /** - * The CSRF token manager. - * - * @var CsrfTokenManager - */ - private $csrfTokenManager; + /** The CSRF token manager. */ + private CsrfTokenManager $csrfTokenManager; - /** - * The CSRF token name. - * - * @var string - */ - private $csrfTokenName; + /** The CSRF token name. */ + private string $csrfTokenName; /** * Create a new instance. @@ -93,7 +64,7 @@ public function __construct( */ public function __invoke(Request $request): Response { - switch ($request->get('act')) { + switch ($request->query->get('act')) { case 'inspect-map': return $this->inspectMap($request); default: @@ -106,25 +77,29 @@ public function __invoke(Request $request): Response * Inspect Terminal42 mappings. * * @param Request $request The request. - * - * @return Response */ private function inspectMap(Request $request): Response { - if (empty($map = $request->get('map'))) { + if (empty($map = $request->query->get('map'))) { $map = 'tl_page'; } + assert(is_string($map)); $form = $this->createForm(InspectMappingFormType::class); $form->handleRequest($request); - $logger = new BufferingLogger(); + /** @var array{source: string, target: string} $data */ $data = $form->getData(); + $logger = new BufferingLogger(); $errors = []; if ($form->isSubmitted() && $form->isValid()) { - $this->mapBuilder->setLogger($logger); + if ($this->mapBuilder instanceof LoggerAwareInterface) { + $this->mapBuilder->setLogger($logger); + } $this->mapBuilder->getMappingFor($map, $data['source'], $data['target']); - foreach ($logger->cleanLogs() as $message) { + /** @var list}> $logs */ + $logs = $logger->cleanLogs(); + foreach ($logs as $message) { if ([] !== ($converted = $this->convertMessage($message))) { $errors[] = $converted; } @@ -143,7 +118,7 @@ private function inspectMap(Request $request): Response /** * Convert an error message to the correct error array. * - * @param array $message The error message to convert. + * @param array{0: string, 1: string, 2: array} $message The error message to convert. * * @return array * @@ -153,7 +128,7 @@ private function inspectMap(Request $request): Response private function convertMessage(array $message): array { [$level, $text, $context] = $message; - if (!\in_array($level, ['warning', 'error'])) { + if (!in_array($level, ['warning', 'error'])) { return []; } @@ -281,10 +256,8 @@ private function link(array $params): array /** * Transform the message by replacing the context parameters. * - * @param string $message The message template. - * @param array $context The context parameters. - * - * @return string + * @param string $message The message template. + * @param array $context The context parameters. */ private function transformMessage(string $message, array $context): string { diff --git a/src/CyberSpectrumI18NContaoBundle.php b/src/CyberSpectrumI18NContaoBundle.php index 16e91cd..1423f4c 100644 --- a/src/CyberSpectrumI18NContaoBundle.php +++ b/src/CyberSpectrumI18NContaoBundle.php @@ -1,23 +1,6 @@ - * @copyright 2018 CyberSpectrum. - * @license https://github.com/cyberspectrum/i18n-contao-bundle/blob/master/LICENSE MIT - * @filesource - */ - -declare(strict_types = 1); +declare(strict_types=1); namespace CyberSpectrum\I18N\ContaoBundle; @@ -36,10 +19,7 @@ */ class CyberSpectrumI18NContaoBundle extends Bundle { - /** - * {@inheritDoc} - */ - public function build(ContainerBuilder $container) + public function build(ContainerBuilder $container): void { parent::build($container); diff --git a/src/DependencyInjection/CompilerPass/CollectContaoExtractorsPass.php b/src/DependencyInjection/CompilerPass/CollectContaoExtractorsPass.php index 2b71247..8f70339 100644 --- a/src/DependencyInjection/CompilerPass/CollectContaoExtractorsPass.php +++ b/src/DependencyInjection/CompilerPass/CollectContaoExtractorsPass.php @@ -1,31 +1,17 @@ - * @copyright 2018 CyberSpectrum. - * @license https://github.com/cyberspectrum/i18n-contao-bundle/blob/master/LICENSE MIT - * @filesource - */ - -declare(strict_types = 1); +declare(strict_types=1); namespace CyberSpectrum\I18N\ContaoBundle\DependencyInjection\CompilerPass; use CyberSpectrum\I18N\Contao\ExtractorFactory; +use RuntimeException; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; +use function array_key_exists; + /** * This pass adds tagged services to the various factories. */ @@ -41,11 +27,9 @@ class CollectContaoExtractorsPass implements CompilerPassInterface * * @param ContainerBuilder $container The container builder. * - * @return void - * - * @throws \RuntimeException When a tag has no table name. + * @throws RuntimeException When a tag has no table name. */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { if (!$container->has(ExtractorFactory::class)) { return; @@ -54,13 +38,19 @@ public function process(ContainerBuilder $container) return; } + /** @var array> $extractorLists */ $extractorLists = []; $extractorContainer = $container->getDefinition('cyberspectrum_i18n.contao.extractor_container'); - $extractorList = $extractorContainer->getArgument(0); + /** @var array $extractorList */ + $extractorList = $extractorContainer->getArgument(0); + /** + * @var string $serviceId + * @var list $tags + */ foreach ($services as $serviceId => $tags) { foreach ($tags as $tag) { if (!array_key_exists('table', $tag)) { - throw new \RuntimeException('Tagged service "'. $serviceId .'" has no table name.'); + throw new RuntimeException('Tagged service "' . $serviceId . '" has no table name.'); } $tableName = $tag['table']; diff --git a/src/DependencyInjection/CompilerPass/CollectExtractorConditionsPass.php b/src/DependencyInjection/CompilerPass/CollectExtractorConditionsPass.php index f4cc446..4fd5f91 100644 --- a/src/DependencyInjection/CompilerPass/CollectExtractorConditionsPass.php +++ b/src/DependencyInjection/CompilerPass/CollectExtractorConditionsPass.php @@ -1,23 +1,6 @@ - * @copyright 2018 CyberSpectrum. - * @license https://github.com/cyberspectrum/i18n-contao-bundle/blob/master/LICENSE MIT - * @filesource - */ - -declare(strict_types = 1); +declare(strict_types=1); namespace CyberSpectrum\I18N\ContaoBundle\DependencyInjection\CompilerPass; @@ -28,26 +11,29 @@ use CyberSpectrum\I18N\Contao\Extractor\ConditionalStringExtractor; use CyberSpectrum\I18N\Contao\Extractor\MultiStringExtractorInterface; use CyberSpectrum\I18N\Contao\Extractor\StringExtractorInterface; +use RuntimeException; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; +use function array_merge; +use function array_slice; +use function assert; +use function in_array; +use function is_array; +use function json_encode; +use function sprintf; + /** * This pass adds tagged services to the various factories. */ class CollectExtractorConditionsPass implements CompilerPassInterface { - /** - * The tag name to use for attribute factories. - */ + /** The tag name to use for attribute factories. */ public const TAG_CONTAO_EXTRACTOR_CONDITION = 'cyberspectrum_i18n.contao_condition'; - /** - * Id of the expression language to use. - * - * @var string - */ + /** Id of the expression language to use. */ private const EXPRESSION_LANGUAGE = 'cyberspectrum_i18n.expression_language'; /** @@ -55,9 +41,7 @@ class CollectExtractorConditionsPass implements CompilerPassInterface * * @param ContainerBuilder $container The container builder. * - * @return void - * - * @throws \RuntimeException When a tag has no table name. + * @throws RuntimeException When a tag has no table name. */ public function process(ContainerBuilder $container): void { @@ -65,6 +49,10 @@ public function process(ContainerBuilder $container): void return; } + /** + * @var string $serviceId + * @var list $tags + */ foreach ($services as $serviceId => $tags) { foreach ($tags as $tag) { $this->handleTag($serviceId, $tag, $container); @@ -79,9 +67,7 @@ public function process(ContainerBuilder $container): void * @param array $tag The tag content. * @param ContainerBuilder $container The container builder. * - * @return void - * - * @throws \RuntimeException On error. + * @throws RuntimeException On error. */ private function handleTag(string $serviceId, array $tag, ContainerBuilder $container): void { @@ -91,11 +77,13 @@ private function handleTag(string $serviceId, array $tag, ContainerBuilder $cont return; } + /** @var list $conditions */ $conditions = []; + /** @var array{0: string, 1: list } $call */ foreach ($definition->getMethodCalls() as $call) { if ('setCondition' === $call[0]) { if (!$call[1][0] instanceof Reference) { - throw new \RuntimeException('Expected a reference as argument'); + throw new RuntimeException('Expected a reference as argument'); } $conditions[] = $call[1][0]; } @@ -107,16 +95,16 @@ private function handleTag(string $serviceId, array $tag, ContainerBuilder $cont // Scan if any of the conditions is a WhitelistCondition - if so, add all other to that one. foreach ($conditions as $index => $condition) { - /** @var Reference $condition */ - $referenced = $container->getDefinition($condition); + $referenced = $container->getDefinition($condition->__toString()); if ($referenced->getClass() === WhitelistCondition::class) { $arguments = $referenced->getArgument(0); + assert(is_array($arguments)); $referenced->setArgument( 0, array_merge( - \array_slice($arguments, 0, $index), - \array_slice($arguments, ($index + 1)), + array_slice($arguments, 0, $index), + array_slice($arguments, ($index + 1)), [$newCondition] ) ); @@ -146,12 +134,15 @@ private function handleTag(string $serviceId, array $tag, ContainerBuilder $cont * * @return Definition * - * @throws \RuntimeException On error. + * @throws RuntimeException On error. */ private function ensureConditionalService(string $serviceId, ContainerBuilder $container): Definition { $definition = $container->getDefinition($serviceId); - if ($this->classImplements($class = $definition->getClass(), ConditionalExtractorInterface::class)) { + if ( + (null === ($class = $definition->getClass())) + || $this->classImplements($class, ConditionalExtractorInterface::class) + ) { return $definition; } @@ -181,12 +172,14 @@ private function ensureConditionalService(string $serviceId, ContainerBuilder $c default: } - throw new \RuntimeException(sprintf( - 'Class %1$s does not implement %2$s - can not apply conditions (service: %3$s).', - $definition->getClass(), - ConditionalExtractorInterface::class, - $serviceId - )); + throw new RuntimeException( + sprintf( + 'Class %1$s does not implement %2$s - can not apply conditions (service: %3$s).', + $definition->getClass() ?? '?', + ConditionalExtractorInterface::class, + $serviceId + ) + ); } /** @@ -194,12 +187,10 @@ private function ensureConditionalService(string $serviceId, ContainerBuilder $c * * @param string $class The class to test. * @param string $interface The interface to test. - * - * @return bool */ private function classImplements(string $class, string $interface): bool { - return \in_array($interface, class_implements($class), true); + return in_array($interface, class_implements($class), true); } /** @@ -211,12 +202,12 @@ private function classImplements(string $class, string $interface): bool * * @return Reference * - * @throws \RuntimeException When the condition type is unknown. + * @throws RuntimeException When the condition type is unknown. */ private function createCondition(string $serviceId, array $tag, ContainerBuilder $container): Reference { if (!isset($tag['type'])) { - throw new \RuntimeException(sprintf( + throw new RuntimeException(sprintf( 'No type given for condition of service: %1$s.', $serviceId )); @@ -225,7 +216,7 @@ private function createCondition(string $serviceId, array $tag, ContainerBuilder switch ($tag['type']) { case 'expression': if (!isset($tag['expression'])) { - throw new \RuntimeException('Expression missing in tag for: ' . $serviceId); + throw new RuntimeException('Expression missing in tag for: ' . $serviceId); } $container->setDefinition( $conditionId = 'cyberspectrum_i18n.contao.extractor.condition.' . @@ -240,6 +231,6 @@ private function createCondition(string $serviceId, array $tag, ContainerBuilder default: } - throw new \RuntimeException('Unknown condition tag: ' . json_encode($tag)); + throw new RuntimeException('Unknown condition tag: ' . json_encode($tag)); } } diff --git a/src/DependencyInjection/CompilerPass/CollectMetaModelAttributeHandlerPass.php b/src/DependencyInjection/CompilerPass/CollectMetaModelAttributeHandlerPass.php index 88bf518..6571c43 100644 --- a/src/DependencyInjection/CompilerPass/CollectMetaModelAttributeHandlerPass.php +++ b/src/DependencyInjection/CompilerPass/CollectMetaModelAttributeHandlerPass.php @@ -1,23 +1,6 @@ - * @copyright 2018 CyberSpectrum. - * @license https://github.com/cyberspectrum/i18n-contao-bundle/blob/master/LICENSE MIT - * @filesource - */ - -declare(strict_types = 1); +declare(strict_types=1); namespace CyberSpectrum\I18N\ContaoBundle\DependencyInjection\CompilerPass; @@ -35,10 +18,7 @@ class CollectMetaModelAttributeHandlerPass implements CompilerPassInterface */ public const TAG_ATTRIBUTE_HANDLER_FACTORY = 'cyberspectrum_i18n.metamodels.attribute_handler'; - /** - * {@inheritDoc} - */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { if (!$container->hasDefinition('cyberspectrum_i18n.metamodels.attribute_handler_factories')) { return; @@ -46,7 +26,12 @@ public function process(ContainerBuilder $container) $factoryList = $container->getDefinition('cyberspectrum_i18n.metamodels.attribute_handler_factories'); $factories = $factoryList->getArgument(0); + assert(\is_array($factories)); + /** + * @var string $serviceId + * @var list $tags + */ foreach ($container->findTaggedServiceIds(self::TAG_ATTRIBUTE_HANDLER_FACTORY) as $serviceId => $tags) { foreach ($tags as $tag) { if ($type = ($tag['type'] ?? null)) { diff --git a/src/DependencyInjection/CompilerPass/RegisterDictionaryTypesPass.php b/src/DependencyInjection/CompilerPass/RegisterDictionaryTypesPass.php index d676d1a..eca12ac 100644 --- a/src/DependencyInjection/CompilerPass/RegisterDictionaryTypesPass.php +++ b/src/DependencyInjection/CompilerPass/RegisterDictionaryTypesPass.php @@ -1,33 +1,21 @@ - * @copyright 2018 CyberSpectrum. - * @license https://github.com/cyberspectrum/i18n-bundle/blob/master/LICENSE MIT - * @filesource - */ - -declare(strict_types = 1); +declare(strict_types=1); namespace CyberSpectrum\I18N\ContaoBundle\DependencyInjection\CompilerPass; use CyberSpectrum\I18N\Contao\ContaoDictionaryDefinitionBuilder; use CyberSpectrum\I18N\MetaModels\MetaModelDictionaryDefinitionBuilder; use CyberSpectrum\I18N\MetaModels\MetaModelDictionaryProvider; +use RuntimeException; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; +use function array_merge; +use function assert; +use function is_array; + /** * This pass adds dictionary builders. */ @@ -40,7 +28,7 @@ class RegisterDictionaryTypesPass implements CompilerPassInterface * * @return void * - * @throws \RuntimeException When a tag has no provider name or multiple services have been registered. + * @throws RuntimeException When a tag has no provider name or multiple services have been registered. */ public function process(ContainerBuilder $container): void { @@ -51,6 +39,8 @@ public function process(ContainerBuilder $container): void } $definition = $container->getDefinition('cyberspectrum_i18n.dictionary_definition_builders'); - $definition->setArgument(0, array_merge($definition->getArgument(0), $builders)); + $prevBuilders = $definition->getArgument(0); + assert(is_array($prevBuilders)); + $definition->setArgument(0, array_merge($prevBuilders, $builders)); } } diff --git a/src/DependencyInjection/CompilerPass/SetDefaultsPass.php b/src/DependencyInjection/CompilerPass/SetDefaultsPass.php index fc38758..1f55cde 100644 --- a/src/DependencyInjection/CompilerPass/SetDefaultsPass.php +++ b/src/DependencyInjection/CompilerPass/SetDefaultsPass.php @@ -1,28 +1,12 @@ - * @copyright 2018 CyberSpectrum. - * @license https://github.com/cyberspectrum/i18n-contao-bundle/blob/master/LICENSE MIT - * @filesource - */ - -declare(strict_types = 1); +declare(strict_types=1); namespace CyberSpectrum\I18N\ContaoBundle\DependencyInjection\CompilerPass; use CyberSpectrum\I18N\Contao\ContaoDictionaryProvider; use CyberSpectrum\I18N\Contao\Mapping\Terminal42ChangeLanguage\MapBuilder as Terminal42MapBuilder; +use RuntimeException; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -31,10 +15,7 @@ */ class SetDefaultsPass implements CompilerPassInterface { - /** - * {@inheritDoc} - */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { if ($container->has(ContaoDictionaryProvider::class)) { $this->setDefaultMapBuilder($container); @@ -46,9 +27,7 @@ public function process(ContainerBuilder $container) * * @param ContainerBuilder $container The container builder. * - * @return void - * - * @throws \RuntimeException When no default map builder has been defined. + * @throws RuntimeException When no default map builder has been defined. */ private function setDefaultMapBuilder(ContainerBuilder $container): void { @@ -60,7 +39,7 @@ private function setDefaultMapBuilder(ContainerBuilder $container): void return; } - throw new \RuntimeException( + throw new RuntimeException( 'No default map builder defined, please install an extension that provides ' . '"cyberspectrum_i18n.contao.default_map_builder".' ); diff --git a/src/DependencyInjection/CompilerPass/UpdateForRockSolidCustomElementPass.php b/src/DependencyInjection/CompilerPass/UpdateForRockSolidCustomElementPass.php index 98a3437..deb3fda 100644 --- a/src/DependencyInjection/CompilerPass/UpdateForRockSolidCustomElementPass.php +++ b/src/DependencyInjection/CompilerPass/UpdateForRockSolidCustomElementPass.php @@ -1,23 +1,6 @@ - * @copyright 2018 CyberSpectrum. - * @license https://github.com/cyberspectrum/i18n-contao-bundle/blob/master/LICENSE MIT - * @filesource - */ - -declare(strict_types = 1); +declare(strict_types=1); namespace CyberSpectrum\I18N\ContaoBundle\DependencyInjection\CompilerPass; @@ -29,10 +12,7 @@ */ class UpdateForRockSolidCustomElementPass implements CompilerPassInterface { - /** - * {@inheritDoc} - */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { $extractor = $container->getDefinition('cyberspectrum_i18n.contao.extractor.tl_content.headline'); $extractor->addTag(CollectExtractorConditionsPass::TAG_CONTAO_EXTRACTOR_CONDITION, [ diff --git a/src/DependencyInjection/CyberSpectrumI18NContaoExtension.php b/src/DependencyInjection/CyberSpectrumI18NContaoExtension.php index 5fb4c49..538e421 100644 --- a/src/DependencyInjection/CyberSpectrumI18NContaoExtension.php +++ b/src/DependencyInjection/CyberSpectrumI18NContaoExtension.php @@ -1,23 +1,6 @@ - * @copyright 2018 CyberSpectrum. - * @license https://github.com/cyberspectrum/i18n-contao-bundle/blob/master/LICENSE MIT - * @filesource - */ - -declare(strict_types = 1); +declare(strict_types=1); namespace CyberSpectrum\I18N\ContaoBundle\DependencyInjection; @@ -28,6 +11,10 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; +use Terminal42\ChangeLanguage\Terminal42ChangeLanguageBundle; + +use function array_key_exists; +use function in_array; /** * This is the class that loads and manages the bundle configuration @@ -37,15 +24,20 @@ class CyberSpectrumI18NContaoExtension extends Extension /** * {@inheritDoc} */ - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('contao/services.yml'); $loader->load('contao/extractor.yml'); + /** @psalm-suppress UndefinedClass - we do not need this class, this check is for feature detection only */ if ($this->hasBundle(RockSolidCustomElementsBundle::class, $container)) { $loader->load('contao/rock-solid-custom-elements.yml'); } - if ($this->hasBundle('changelanguage', $container)) { + /** @psalm-suppress UndefinedClass - we do not need this class, this check is for feature detection only */ + if ( + $this->hasBundle('changelanguage', $container) + || $this->hasBundle(Terminal42ChangeLanguageBundle::class, $container) + ) { $loader->load('contao/terminal42-change-language.yml'); } // Only activate if MetaModels bundle present. @@ -59,12 +51,15 @@ public function load(array $configs, ContainerBuilder $container) * * @param string $class The bundle class or bundle name. * @param ContainerBuilder $container The container builder. - * - * @return bool */ private function hasBundle(string $class, ContainerBuilder $container): bool { - if (\in_array($class, $bundles = $container->getParameter('kernel.bundles'), true)) { + /** + * @var array $bundles + * @psalm-suppress UndefinedDocblockClass - UnitEnum is added in PHP 8.1 and therefore throws in PHP 7.4. + */ + $bundles = $container->getParameter('kernel.bundles'); + if (in_array($class, $bundles, true)) { return true; } diff --git a/src/FormType/InspectMappingFormType.php b/src/FormType/InspectMappingFormType.php index 80e2b90..fcc7b84 100644 --- a/src/FormType/InspectMappingFormType.php +++ b/src/FormType/InspectMappingFormType.php @@ -1,23 +1,6 @@ - * @copyright 2018 CyberSpectrum. - * @license https://github.com/cyberspectrum/i18n-contao-bundle/blob/master/LICENSE MIT - * @filesource - */ - -declare(strict_types = 1); +declare(strict_types=1); namespace CyberSpectrum\I18N\ContaoBundle\FormType; @@ -33,19 +16,11 @@ */ class InspectMappingFormType extends AbstractType { - /** - * The Contao map builder. - * - * @var MapBuilderInterface - */ - private $mapBuilder; + /** The Contao map builder. */ + private MapBuilderInterface $mapBuilder; - /** - * The Contao token name. - * - * @var string - */ - private $tokenName; + /** The Contao token name. */ + private string $tokenName; /** * Create a new instance. @@ -62,7 +37,7 @@ public function __construct(MapBuilderInterface $mapBuilder, string $tokenName) /** * {@inheritDoc} */ - public function buildForm(FormBuilderInterface $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options): void { $languages = []; foreach ($this->mapBuilder->getSupportedLanguages() as $language) { @@ -78,7 +53,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'csrf_field_name' => 'REQUEST_TOKEN', @@ -86,10 +61,7 @@ public function configureOptions(OptionsResolver $resolver) ]); } - /** - * {@inheritDoc} - */ - public function getBlockPrefix() + public function getBlockPrefix(): string { return ''; } diff --git a/tests/ContaoManager/PluginTest.php b/tests/ContaoManager/PluginTest.php index a55913e..6164168 100644 --- a/tests/ContaoManager/PluginTest.php +++ b/tests/ContaoManager/PluginTest.php @@ -1,23 +1,6 @@ - * @copyright 2018 CyberSpectrum. - * @license https://github.com/cyberspectrum/i18n-contao-bundle/blob/master/LICENSE MIT - * @filesource - */ - -declare(strict_types = 1); +declare(strict_types=1); namespace CyberSpectrum\I18N\ContaoBundle\Test\ContaoManager; @@ -35,28 +18,21 @@ use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Routing\RouteCollection; -/** - * This tests the plugin. - * - * @covers \CyberSpectrum\I18N\ContaoBundle\ContaoManager\Plugin - */ +use function realpath; + +/** @covers \CyberSpectrum\I18N\ContaoBundle\ContaoManager\Plugin */ class PluginTest extends TestCase { - /** - * Test - * - * @return void - */ public function testGetBundles(): void { $plugin = new Plugin(); $bundles = $plugin->getBundles($this->getMockForAbstractClass(ParserInterface::class)); - $this->assertCount(2, $bundles); + self::assertCount(2, $bundles); /** @var ConfigInterface $bundle */ $bundle = $bundles[0]; - $this->assertSame(CyberSpectrumI18NContaoBundle::class, $bundle->getName()); - $this->assertSame( + self::assertSame(CyberSpectrumI18NContaoBundle::class, $bundle->getName()); + self::assertSame( [ ContaoCoreBundle::class, CyberSpectrumI18NBundle::class, @@ -66,14 +42,9 @@ public function testGetBundles(): void $bundle->getLoadAfter() ); $bundle = $bundles[1]; - $this->assertSame(CyberSpectrumI18NBundle::class, $bundle->getName()); + self::assertSame(CyberSpectrumI18NBundle::class, $bundle->getName()); } - /** - * Test - * - * @return void - */ public function testRegisterContainerConfiguration(): void { $plugin = new Plugin(); @@ -86,11 +57,6 @@ public function testRegisterContainerConfiguration(): void $plugin->registerContainerConfiguration($loader, []); } - /** - * Test - * - * @return void - */ public function testGetRouteCollection(): void { $plugin = new Plugin(); @@ -108,7 +74,7 @@ public function testGetRouteCollection(): void ->with($basePath . '/../Resources/config/contao/routing.yml') ->willReturn($collection = $this->getMockBuilder(RouteCollection::class)->getMock()); - $this->assertSame($collection, $plugin->getRouteCollection( + self::assertSame($collection, $plugin->getRouteCollection( $resolver, $this->getMockForAbstractClass(KernelInterface::class) )); diff --git a/tests/CyberSpectrumI18NContaoBundleTest.php b/tests/CyberSpectrumI18NContaoBundleTest.php index f4ed970..128acfd 100644 --- a/tests/CyberSpectrumI18NContaoBundleTest.php +++ b/tests/CyberSpectrumI18NContaoBundleTest.php @@ -1,23 +1,6 @@ - * @copyright 2018 CyberSpectrum. - * @license https://github.com/cyberspectrum/i18n-contao-bundle/blob/master/LICENSE MIT - * @filesource - */ - -declare(strict_types = 1); +declare(strict_types=1); namespace CyberSpectrum\I18N\ContaoBundle\Test; @@ -32,18 +15,16 @@ use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\DependencyInjection\ContainerBuilder; -/** - * This tests the bundle. - * - * @covers \CyberSpectrum\I18N\ContaoBundle\CyberSpectrumI18NContaoBundle - */ +use function func_get_args; + +/** @covers \CyberSpectrum\I18N\ContaoBundle\CyberSpectrumI18NContaoBundle */ class CyberSpectrumI18NContaoBundleTest extends TestCase { public function testBuild(): void { $container = $this ->getMockBuilder(ContainerBuilder::class) - ->setMethods(['addCompilerPass']) + ->onlyMethods(['addCompilerPass']) ->getMock(); $arguments = []; @@ -58,13 +39,13 @@ public function testBuild(): void $bundle->build($container); - $this->assertInstanceOf(CollectContaoExtractorsPass::class, $arguments[0][0]); - $this->assertInstanceOf(CollectExtractorConditionsPass::class, $arguments[1][0]); - $this->assertInstanceOf(CollectMetaModelAttributeHandlerPass::class, $arguments[2][0]); - $this->assertInstanceOf(SetDefaultsPass::class, $arguments[3][0]); - $this->assertInstanceOf(UpdateForRockSolidCustomElementPass::class, $arguments[4][0]); - $this->assertSame(PassConfig::TYPE_BEFORE_OPTIMIZATION, $arguments[4][1]); - $this->assertSame(10, $arguments[4][2]); - $this->assertInstanceOf(RegisterDictionaryTypesPass::class, $arguments[5][0]); + self::assertInstanceOf(CollectContaoExtractorsPass::class, $arguments[0][0]); + self::assertInstanceOf(CollectExtractorConditionsPass::class, $arguments[1][0]); + self::assertInstanceOf(CollectMetaModelAttributeHandlerPass::class, $arguments[2][0]); + self::assertInstanceOf(SetDefaultsPass::class, $arguments[3][0]); + self::assertInstanceOf(UpdateForRockSolidCustomElementPass::class, $arguments[4][0]); + self::assertSame(PassConfig::TYPE_BEFORE_OPTIMIZATION, $arguments[4][1]); + self::assertSame(10, $arguments[4][2]); + self::assertInstanceOf(RegisterDictionaryTypesPass::class, $arguments[5][0]); } } diff --git a/tests/DependencyInjection/CompilerPass/CollectContaoExtractorsPassTest.php b/tests/DependencyInjection/CompilerPass/CollectContaoExtractorsPassTest.php index 09d1406..d40ec90 100644 --- a/tests/DependencyInjection/CompilerPass/CollectContaoExtractorsPassTest.php +++ b/tests/DependencyInjection/CompilerPass/CollectContaoExtractorsPassTest.php @@ -1,23 +1,6 @@ - * @copyright 2018 CyberSpectrum. - * @license https://github.com/cyberspectrum/i18n-contao-bundle/blob/master/LICENSE MIT - * @filesource - */ - -declare(strict_types = 1); +declare(strict_types=1); namespace CyberSpectrum\I18N\ContaoBundle\Test\DependencyInjection\CompilerPass; @@ -25,23 +8,17 @@ use CyberSpectrum\I18N\Contao\ExtractorFactory; use CyberSpectrum\I18N\ContaoBundle\DependencyInjection\CompilerPass\CollectContaoExtractorsPass; use PHPUnit\Framework\TestCase; +use RuntimeException; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ServiceLocator; -/** - * This tests the service collector pass. - * - * @covers \CyberSpectrum\I18N\ContaoBundle\DependencyInjection\CompilerPass\CollectContaoExtractorsPass - */ +use function array_keys; + +/** @covers \CyberSpectrum\I18N\ContaoBundle\DependencyInjection\CompilerPass\CollectContaoExtractorsPass */ class CollectContaoExtractorsPassTest extends TestCase { - /** - * Test. - * - * @return void - */ public function testCollectExtractors(): void { $container = new ContainerBuilder(); @@ -70,20 +47,15 @@ public function testCollectExtractors(): void $extractorList = $extractorContainer->getArgument(0); - $this->assertSame( + self::assertSame( ['tl_something' => ['service']], $container->getParameter('cyberspectrum_i18n.contao.extractors') ); - $this->assertSame(['service'], \array_keys($extractorList)); - $this->assertInstanceOf(Reference::class, $extractorList['service']); - $this->assertSame('service', (string) $extractorList['service']); + self::assertSame(['service'], array_keys($extractorList)); + self::assertInstanceOf(Reference::class, $extractorList['service']); + self::assertSame('service', (string) $extractorList['service']); } - /** - * Test. - * - * @return void - */ public function testCollectExtractorsThrowsForServiceWithoutTableName(): void { $container = new ContainerBuilder(); @@ -103,7 +75,7 @@ public function testCollectExtractorsThrowsForServiceWithoutTableName(): void ] ); - $this->expectException(\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Tagged service "service" has no table name.'); $servicePass = new CollectContaoExtractorsPass(); diff --git a/tests/DependencyInjection/CompilerPass/CollectExtractorConditionsPassTest.php b/tests/DependencyInjection/CompilerPass/CollectExtractorConditionsPassTest.php index 3bcccbe..f899951 100644 --- a/tests/DependencyInjection/CompilerPass/CollectExtractorConditionsPassTest.php +++ b/tests/DependencyInjection/CompilerPass/CollectExtractorConditionsPassTest.php @@ -1,23 +1,6 @@ - * @copyright 2018 CyberSpectrum. - * @license https://github.com/cyberspectrum/i18n-contao-bundle/blob/master/LICENSE MIT - * @filesource - */ - -declare(strict_types = 1); +declare(strict_types=1); namespace CyberSpectrum\I18N\ContaoBundle\Test\DependencyInjection\CompilerPass; @@ -27,22 +10,16 @@ use CyberSpectrum\I18N\Contao\Extractor\StringExtractorInterface; use CyberSpectrum\I18N\ContaoBundle\DependencyInjection\CompilerPass\CollectExtractorConditionsPass; use PHPUnit\Framework\TestCase; +use RuntimeException; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; -/** - * This tests the service collector pass. - * - * @covers \CyberSpectrum\I18N\ContaoBundle\DependencyInjection\CompilerPass\CollectExtractorConditionsPass - */ +use function get_class; + +/** @covers \CyberSpectrum\I18N\ContaoBundle\DependencyInjection\CompilerPass\CollectExtractorConditionsPass */ class CollectExtractorConditionsPassTest extends TestCase { - /** - * Test. - * - * @return void - */ public function testCollectStringExtractorInterface(): void { $container = new ContainerBuilder(); @@ -60,18 +37,13 @@ public function testCollectStringExtractorInterface(): void $servicePass = new CollectExtractorConditionsPass(); $servicePass->process($container); - $this->assertTrue($container->has('service.conditional')); + self::assertTrue($container->has('service.conditional')); $service = $container->getDefinition('service.conditional'); - $this->assertSame(['service', null, 0], $service->getDecoratedService()); - $this->assertInstanceOf(Reference::class, $service->getArgument(0)); - $this->assertSame('service.conditional.inner', (string) $service->getArgument(0)); + self::assertSame(['service', null, 0], $service->getDecoratedService()); + self::assertInstanceOf(Reference::class, $service->getArgument(0)); + self::assertSame('service.conditional.inner', (string) $service->getArgument(0)); } - /** - * Test. - * - * @return void - */ public function testCollectMultiStringExtractorInterface(): void { $container = new ContainerBuilder(); @@ -89,18 +61,13 @@ public function testCollectMultiStringExtractorInterface(): void $servicePass = new CollectExtractorConditionsPass(); $servicePass->process($container); - $this->assertTrue($container->has('service.conditional')); + self::assertTrue($container->has('service.conditional')); $service = $container->getDefinition('service.conditional'); - $this->assertSame(['service', null, 0], $service->getDecoratedService()); - $this->assertInstanceOf(Reference::class, $service->getArgument(0)); - $this->assertSame('service.conditional.inner', (string) $service->getArgument(0)); + self::assertSame(['service', null, 0], $service->getDecoratedService()); + self::assertInstanceOf(Reference::class, $service->getArgument(0)); + self::assertSame('service.conditional.inner', (string) $service->getArgument(0)); } - /** - * Test. - * - * @return void - */ public function testCollectUnknownExtractorInterfaceThrows(): void { $container = new ContainerBuilder(); @@ -115,7 +82,7 @@ public function testCollectUnknownExtractorInterfaceThrows(): void $container->addDefinitions(['service' => $tagged]); unset($tagged); - $this->expectException(\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Class ' . $class . ' does not implement ' . ConditionalExtractorInterface::class . ' - can not apply conditions (service: service).'); @@ -123,11 +90,6 @@ public function testCollectUnknownExtractorInterfaceThrows(): void $servicePass->process($container); } - /** - * Test. - * - * @return void - */ public function testDoesNotDecorateTwice(): void { $container = new ContainerBuilder(); @@ -146,14 +108,9 @@ public function testDoesNotDecorateTwice(): void $servicePass = new CollectExtractorConditionsPass(); $servicePass->process($container); - $this->assertSame($definition, $container->getDefinition('service.conditional')); + self::assertSame($definition, $container->getDefinition('service.conditional')); } - /** - * Test. - * - * @return void - */ public function testDoesNotDecorateConditionalService(): void { $container = new ContainerBuilder(); @@ -168,18 +125,13 @@ public function testDoesNotDecorateConditionalService(): void $servicePass = new CollectExtractorConditionsPass(); $servicePass->process($container); - $this->assertFalse($container->hasDefinition('service.conditional')); - $this->assertSame($tagged, $container->getDefinition('service')); - $this->assertCount(1, $calls = $container->getDefinition('service')->getMethodCalls()); - $this->assertSame('setCondition', $calls[0][0]); - $this->assertInstanceOf(Reference::class, $calls[0][1][0]); + self::assertFalse($container->hasDefinition('service.conditional')); + self::assertSame($tagged, $container->getDefinition('service')); + self::assertCount(1, $calls = $container->getDefinition('service')->getMethodCalls()); + self::assertSame('setCondition', $calls[0][0]); + self::assertInstanceOf(Reference::class, $calls[0][1][0]); } - /** - * Test. - * - * @return void - */ public function testCollectExtractorsThrowsForTagWithoutConditionType(): void { $container = new ContainerBuilder(); @@ -188,18 +140,13 @@ public function testCollectExtractorsThrowsForTagWithoutConditionType(): void $tagged->addTag(CollectExtractorConditionsPass::TAG_CONTAO_EXTRACTOR_CONDITION); $container->addDefinitions(['service' => $tagged]); - $this->expectException(\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('No type given for condition of service: service.'); $servicePass = new CollectExtractorConditionsPass(); $servicePass->process($container); } - /** - * Test. - * - * @return void - */ public function testCollectExtractorsThrowsForTagWithoutExpression(): void { $container = new ContainerBuilder(); @@ -208,18 +155,13 @@ public function testCollectExtractorsThrowsForTagWithoutExpression(): void $tagged->addTag(CollectExtractorConditionsPass::TAG_CONTAO_EXTRACTOR_CONDITION, ['type' => 'expression']); $container->addDefinitions(['service' => $tagged]); - $this->expectException(\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Expression missing in tag for: service'); $servicePass = new CollectExtractorConditionsPass(); $servicePass->process($container); } - /** - * Test. - * - * @return void - */ public function testCollectExtractorsThrowsForTagWithUnknownType(): void { $container = new ContainerBuilder(); @@ -228,7 +170,7 @@ public function testCollectExtractorsThrowsForTagWithUnknownType(): void $tagged->addTag(CollectExtractorConditionsPass::TAG_CONTAO_EXTRACTOR_CONDITION, ['type' => '-unknown-']); $container->addDefinitions(['service' => $tagged]); - $this->expectException(\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Unknown condition tag: {"type":"-unknown-"}'); $servicePass = new CollectExtractorConditionsPass(); diff --git a/tests/DependencyInjection/CyberSpectrumI18NContaoExtensionTest.php b/tests/DependencyInjection/CyberSpectrumI18NContaoExtensionTest.php index 0da36af..fed79e0 100644 --- a/tests/DependencyInjection/CyberSpectrumI18NContaoExtensionTest.php +++ b/tests/DependencyInjection/CyberSpectrumI18NContaoExtensionTest.php @@ -1,23 +1,6 @@ - * @copyright 2018 CyberSpectrum. - * @license https://github.com/cyberspectrum/i18n-contao-bundle/blob/master/LICENSE MIT - * @filesource - */ - -declare(strict_types = 1); +declare(strict_types=1); namespace CyberSpectrum\I18N\ContaoBundle\Test\DependencyInjection; @@ -68,14 +51,14 @@ public function testLoad(): void $class = $serviceId; } - $this->assertTrue( + self::assertTrue( class_exists($class) || interface_exists($class), 'Class ' . $class . ' does not exist for ' . $serviceId ); } // Assert we get all files loaded. - $this->assertSame([ + self::assertSame([ realpath(__DIR__ . '/../../src/Resources/config/contao/services.yml'), realpath(__DIR__ . '/../../src/Resources/config/contao/extractor.yml'), realpath(__DIR__ . '/../../src/Resources/config/contao/rock-solid-custom-elements.yml'), @@ -105,7 +88,7 @@ public function testLoadSkipsConfigForUnknownBundles(): void } } - $this->assertSame([ + self::assertSame([ realpath(__DIR__ . '/../../src/Resources/config/contao/services.yml'), realpath(__DIR__ . '/../../src/Resources/config/contao/extractor.yml'), ], $files);