From b384fff299dd18aae6773ab06212b1c235f60b85 Mon Sep 17 00:00:00 2001 From: Richard van Laak Date: Thu, 23 Jan 2020 09:48:52 +0100 Subject: [PATCH 1/4] remove extractors DI configuration duplication by using `_instanceof` on imported services --- Resources/config/extractors.yaml | 108 +++++++++++++------------------ 1 file changed, 45 insertions(+), 63 deletions(-) diff --git a/Resources/config/extractors.yaml b/Resources/config/extractors.yaml index 0f254dc3..c5a5f84a 100644 --- a/Resources/config/extractors.yaml +++ b/Resources/config/extractors.yaml @@ -1,67 +1,49 @@ services: - Translation\Extractor\FileExtractor\PHPFileExtractor: - tags: - - { name: 'php_translation.extractor', type: 'php' } - - Translation\Extractor\FileExtractor\TwigFileExtractor: - arguments: ["@twig"] - tags: - - { name: 'php_translation.extractor', type: 'twig' } - - # PHP Visitors: - Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTrans: - tags: - - { name: 'php_translation.visitor', type: 'php' } - - Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTransChoice: - tags: - - { name: 'php_translation.visitor', type: 'php' } - - Translation\Extractor\Visitor\Php\Symfony\FlashMessage: - tags: - - { name: 'php_translation.visitor', type: 'php' } - - Translation\Extractor\Visitor\Php\Symfony\FormTypeChoices: - tags: - - { name: 'php_translation.visitor', type: 'php' } - - Translation\Extractor\Visitor\Php\Symfony\FormTypeEmptyValue: - tags: - - { name: 'php_translation.visitor', type: 'php' } - - Translation\Extractor\Visitor\Php\Symfony\FormTypeHelp: - tags: - - { name: 'php_translation.visitor', type: 'php' } - - Translation\Extractor\Visitor\Php\Symfony\FormTypeInvalidMessage: - tags: - - { name: 'php_translation.visitor', type: 'php' } - - Translation\Extractor\Visitor\Php\Symfony\FormTypeLabelExplicit: - tags: - - { name: 'php_translation.visitor', type: 'php' } - - Translation\Extractor\Visitor\Php\Symfony\FormTypeLabelImplicit: - tags: - - { name: 'php_translation.visitor', type: 'php' } - - Translation\Extractor\Visitor\Php\Symfony\FormTypePlaceholder: - tags: - - { name: 'php_translation.visitor', type: 'php' } - - Translation\Extractor\Visitor\Php\Symfony\ValidationAnnotation: - arguments: ['@validator'] - tags: - - { name: 'php_translation.visitor', type: 'php' } - - Translation\Extractor\Visitor\Php\SourceLocationContainerVisitor: - tags: - - { name: 'php_translation.visitor', type: 'php' } - - # Twig Visitors: - Translation\Extractor\Visitor\Twig\TwigVisitor: - tags: - - { name: 'php_translation.visitor', type: 'twig' } + _defaults: + autowire: true + + _instanceof: + PhpParser\NodeVisitor: + tags: + - { name: 'php_translation.visitor', type: 'php' } + + Translation\Extractor\FileExtractor\PHPFileExtractor: + tags: + - { name: 'php_translation.extractor', type: 'php' } + + Translation\Extractor\FileExtractor\TwigFileExtractor: + tags: + - { name: 'php_translation.extractor', type: 'twig' } + + # PHP Visitors: + Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTrans: ~ + + Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTransChoice: ~ + + Translation\Extractor\Visitor\Php\Symfony\FlashMessage: ~ + + Translation\Extractor\Visitor\Php\Symfony\FormTypeChoices: ~ + + Translation\Extractor\Visitor\Php\Symfony\FormTypeEmptyValue: ~ + + Translation\Extractor\Visitor\Php\Symfony\FormTypeHelp: ~ + + Translation\Extractor\Visitor\Php\Symfony\FormTypeInvalidMessage: ~ + + Translation\Extractor\Visitor\Php\Symfony\FormTypeLabelExplicit: ~ + + Translation\Extractor\Visitor\Php\Symfony\FormTypeLabelImplicit: ~ + + Translation\Extractor\Visitor\Php\Symfony\FormTypePlaceholder: ~ + + Translation\Extractor\Visitor\Php\Symfony\ValidationAnnotation: ~ + + Translation\Extractor\Visitor\Php\SourceLocationContainerVisitor: ~ + + # Twig Visitors: + Translation\Extractor\Visitor\Twig\TwigVisitor: + tags: + - { name: 'php_translation.visitor', type: 'twig' } # To remove in next major release php_translation.extractor.php: From d8bbd3d7ea27afa22205f4d52408a14d9fce3322 Mon Sep 17 00:00:00 2001 From: Richard van Laak Date: Thu, 23 Jan 2020 09:49:24 +0100 Subject: [PATCH 2/4] make deprecated service an actual alias instead of extending a parent --- Resources/config/extractors.yaml | 92 ++++++++++++++++---------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/Resources/config/extractors.yaml b/Resources/config/extractors.yaml index c5a5f84a..b6f57aa1 100644 --- a/Resources/config/extractors.yaml +++ b/Resources/config/extractors.yaml @@ -45,49 +45,49 @@ services: tags: - { name: 'php_translation.visitor', type: 'twig' } - # To remove in next major release - php_translation.extractor.php: - parent: Translation\Extractor\FileExtractor\PHPFileExtractor - deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.' - php_translation.extractor.twig: - parent: Translation\Extractor\FileExtractor\TwigFileExtractor - deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.' - php_translation.extractor.php.visitor.ContainerAwareTrans: - parent: Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTrans - deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.' - php_translation.extractor.php.visitor.ContainerAwareTransChoice: - parent: Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTransChoice - deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.' - php_translation.extractor.php.visitor.FlashMessage: - parent: Translation\Extractor\Visitor\Php\Symfony\FlashMessage - deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.' - php_translation.extractor.php.visitor.FormTypeChoices: - parent: Translation\Extractor\Visitor\Php\Symfony\FormTypeChoices - deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.' - php_translation.extractor.php.visitor.FormTypeEmptyValue: - parent: Translation\Extractor\Visitor\Php\Symfony\FormTypeEmptyValue - deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.' - php_translation.extractor.php.visitor.FormTypeHelp: - parent: Translation\Extractor\Visitor\Php\Symfony\FormTypeHelp - deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.' - php_translation.extractor.php.visitor.FormTypeInvalidMessage: - parent: Translation\Extractor\Visitor\Php\Symfony\FormTypeInvalidMessage - deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.' - php_translation.extractor.php.visitor.FormTypeLabelExplicit: - parent: Translation\Extractor\Visitor\Php\Symfony\FormTypeLabelExplicit - deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.' - php_translation.extractor.php.visitor.FormTypeLabelImplicit: - parent: Translation\Extractor\Visitor\Php\Symfony\FormTypeLabelImplicit - deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.' - php_translation.extractor.php.visitor.FormTypePlaceholder: - parent: Translation\Extractor\Visitor\Php\Symfony\FormTypePlaceholder - deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.' - php_translation.extractor.php.visitor.ValidationAnnotation: - parent: Translation\Extractor\Visitor\Php\Symfony\ValidationAnnotation - deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.' - php_translation.extractor.php.visitor.SourceLocationContainerVisitor: - parent: Translation\Extractor\Visitor\Php\SourceLocationContainerVisitor - deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.' - php_translation.extractor.twig.factory.twig: - parent: Translation\Extractor\Visitor\Twig\TwigVisitor - deprecated: 'The "%service_id%" service is deprecated. You should stop using it, as it will be removed in the future.' + # To remove in next major release + php_translation.extractor.php: + alias: Translation\Extractor\FileExtractor\PHPFileExtractor + deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.' + php_translation.extractor.twig: + alias: Translation\Extractor\FileExtractor\TwigFileExtractor + deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.' + php_translation.extractor.php.visitor.ContainerAwareTrans: + alias: Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTrans + deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.' + php_translation.extractor.php.visitor.ContainerAwareTransChoice: + alias: Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTransChoice + deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.' + php_translation.extractor.php.visitor.FlashMessage: + alias: Translation\Extractor\Visitor\Php\Symfony\FlashMessage + deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.' + php_translation.extractor.php.visitor.FormTypeChoices: + alias: Translation\Extractor\Visitor\Php\Symfony\FormTypeChoices + deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.' + php_translation.extractor.php.visitor.FormTypeEmptyValue: + alias: Translation\Extractor\Visitor\Php\Symfony\FormTypeEmptyValue + deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.' + php_translation.extractor.php.visitor.FormTypeHelp: + alias: Translation\Extractor\Visitor\Php\Symfony\FormTypeHelp + deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.' + php_translation.extractor.php.visitor.FormTypeInvalidMessage: + alias: Translation\Extractor\Visitor\Php\Symfony\FormTypeInvalidMessage + deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.' + php_translation.extractor.php.visitor.FormTypeLabelExplicit: + alias: Translation\Extractor\Visitor\Php\Symfony\FormTypeLabelExplicit + deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.' + php_translation.extractor.php.visitor.FormTypeLabelImplicit: + alias: Translation\Extractor\Visitor\Php\Symfony\FormTypeLabelImplicit + deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.' + php_translation.extractor.php.visitor.FormTypePlaceholder: + alias: Translation\Extractor\Visitor\Php\Symfony\FormTypePlaceholder + deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.' + php_translation.extractor.php.visitor.ValidationAnnotation: + alias: Translation\Extractor\Visitor\Php\Symfony\ValidationAnnotation + deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.' + php_translation.extractor.php.visitor.SourceLocationContainerVisitor: + alias: Translation\Extractor\Visitor\Php\SourceLocationContainerVisitor + deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.' + php_translation.extractor.twig.factory.twig: + alias: Translation\Extractor\Visitor\Twig\TwigVisitor + deprecated: 'The "%service_id%" service is deprecated. You should use "%alias_id%" instead, as it will be removed in the future.' From 9da14dbc1e2574c4a736a1dcea3b026425afa900 Mon Sep 17 00:00:00 2001 From: Richard van Laak Date: Thu, 23 Jan 2020 10:37:31 +0100 Subject: [PATCH 3/4] import resource over requiring classes separately --- DependencyInjection/TranslationExtension.php | 9 +++++++ Resources/config/extractors.yaml | 25 ++++---------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/DependencyInjection/TranslationExtension.php b/DependencyInjection/TranslationExtension.php index b7c1aab0..3a47e080 100644 --- a/DependencyInjection/TranslationExtension.php +++ b/DependencyInjection/TranslationExtension.php @@ -42,6 +42,8 @@ class TranslationExtension extends Extension */ public function load(array $configs, ContainerBuilder $container): void { + $container->setParameter('extractor_vendor_dir', $this->getExtractorVendorDirectory()); + $configuration = new Configuration($container); $config = $this->processConfiguration($configuration, $configs); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); @@ -232,4 +234,11 @@ public function getConfiguration(array $config, ContainerBuilder $container): Co { return new Configuration($container); } + + private function getExtractorVendorDirectory(): string + { + $vendorReflection = new \ReflectionClass(FormTypeChoices::class); + + return dirname($vendorReflection->getFileName(), 4); + } } diff --git a/Resources/config/extractors.yaml b/Resources/config/extractors.yaml index b6f57aa1..54cf5fe4 100644 --- a/Resources/config/extractors.yaml +++ b/Resources/config/extractors.yaml @@ -1,6 +1,8 @@ services: _defaults: autowire: true + bind: + $metadataFactory: '@validator' _instanceof: PhpParser\NodeVisitor: @@ -16,27 +18,8 @@ services: - { name: 'php_translation.extractor', type: 'twig' } # PHP Visitors: - Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTrans: ~ - - Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTransChoice: ~ - - Translation\Extractor\Visitor\Php\Symfony\FlashMessage: ~ - - Translation\Extractor\Visitor\Php\Symfony\FormTypeChoices: ~ - - Translation\Extractor\Visitor\Php\Symfony\FormTypeEmptyValue: ~ - - Translation\Extractor\Visitor\Php\Symfony\FormTypeHelp: ~ - - Translation\Extractor\Visitor\Php\Symfony\FormTypeInvalidMessage: ~ - - Translation\Extractor\Visitor\Php\Symfony\FormTypeLabelExplicit: ~ - - Translation\Extractor\Visitor\Php\Symfony\FormTypeLabelImplicit: ~ - - Translation\Extractor\Visitor\Php\Symfony\FormTypePlaceholder: ~ - - Translation\Extractor\Visitor\Php\Symfony\ValidationAnnotation: ~ + Translation\Extractor\Visitor\Php\Symfony\: + resource: "%extractor_vendor_dir%/Visitor/Php/Symfony/*" Translation\Extractor\Visitor\Php\SourceLocationContainerVisitor: ~ From e761adf6f066abc00a128b9238fb7cf5757ea142 Mon Sep 17 00:00:00 2001 From: Richard van Laak Date: Thu, 23 Jan 2020 10:49:14 +0100 Subject: [PATCH 4/4] fix CI --- DependencyInjection/TranslationExtension.php | 2 +- phpstan-baseline.neon | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/DependencyInjection/TranslationExtension.php b/DependencyInjection/TranslationExtension.php index 3a47e080..11ed972e 100644 --- a/DependencyInjection/TranslationExtension.php +++ b/DependencyInjection/TranslationExtension.php @@ -239,6 +239,6 @@ private function getExtractorVendorDirectory(): string { $vendorReflection = new \ReflectionClass(FormTypeChoices::class); - return dirname($vendorReflection->getFileName(), 4); + return \dirname($vendorReflection->getFileName(), 4); } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index e26ad678..be1f1d6d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -25,11 +25,6 @@ parameters: count: 1 path: Command/StatusCommand.php - - - message: "#^Call to method getValue\\(\\) on an unknown class Symfony\\\\Component\\\\Translation\\\\DataCollector\\\\Data\\.$#" - count: 1 - path: Controller/SymfonyProfilerController.php - - message: "#^Call to an undefined static method Symfony\\\\Component\\\\Intl\\\\Intl\\:\\:getLocaleBundle\\(\\)\\.$#" count: 1