From 61db25009b8cf6bd2d3007a7b8e1f80c0118ce3b Mon Sep 17 00:00:00 2001 From: Antolin Janssen Date: Tue, 28 May 2024 23:16:59 +0200 Subject: [PATCH 01/19] initial commit migrating annotations to attributes --- composer.json | 12 +++---- src/Annotation/Desc.php | 3 ++ src/Annotation/Ignore.php | 3 ++ src/Annotation/Translate.php | 3 ++ src/Attribute/Desc.php | 18 ++++++++++ src/Attribute/Ignore.php | 17 ++++++++++ src/Attribute/Translate.php | 33 +++++++++++++++++++ src/Extractor.php | 2 +- src/FileExtractor/PHPFileExtractor.php | 2 +- src/FileExtractor/TwigFileExtractor.php | 6 ++-- src/Model/Error.php | 8 ++--- src/Model/SourceCollection.php | 4 +-- src/Model/SourceLocation.php | 10 +++--- src/Visitor/BaseVisitor.php | 16 +++------ .../Php/Knp/Menu/AbstractKnpMenuVisitor.php | 13 ++------ .../Php/SourceLocationContainerVisitor.php | 19 ++++------- src/Visitor/Php/Symfony/AbstractFormType.php | 9 ++--- src/Visitor/Php/Symfony/Constraint.php | 4 +-- src/Visitor/Php/Symfony/FormTrait.php | 2 +- src/Visitor/Php/Symfony/FormTypeChoices.php | 14 ++++---- .../Php/Symfony/FormTypeLabelImplicit.php | 4 +-- .../Php/Symfony/FormTypePlaceholder.php | 2 +- .../Php/Symfony/ValidationAnnotation.php | 6 ++-- .../Php/TranslateAnnotationVisitor.php | 5 ++- src/Visitor/Twig/TwigVisitor.php | 2 +- src/Visitor/Twig/Worker.php | 2 +- tests/Resources/Github/Issue_109.php | 6 ++-- tests/Resources/Github/Issue_111.php | 2 +- tests/Resources/Github/Issue_125.php | 2 +- tests/Resources/Github/Issue_62.php | 4 +-- .../Resources/Php/Symfony/DescriptionType.php | 2 +- .../Php/Symfony/ExplicitLabelFalseType.php | 4 +-- .../Php/Symfony/ExplicitLabelType.php | 2 +- .../Php/Symfony/HelpFormErrorType.php | 2 +- .../Php/Symfony/PlaceholderFormErrorType.php | 2 +- .../SimpleChoiceSymfony3xErrorType.php | 2 +- .../Php/TestTranslateAnnotationFile.php | 10 +++--- 37 files changed, 154 insertions(+), 103 deletions(-) create mode 100644 src/Attribute/Desc.php create mode 100644 src/Attribute/Ignore.php create mode 100644 src/Attribute/Translate.php diff --git a/composer.json b/composer.json index 8d4e6cb..bb5e1ad 100644 --- a/composer.json +++ b/composer.json @@ -9,17 +9,17 @@ } ], "require": { - "php": "^7.2 || ^8.0", + "php": "^8.1", "nikic/php-parser": "^3.0 || ^4.0", - "symfony/finder": "^3.4 || ^4.4 || ^5.0 || ^6.0", + "symfony/finder": "^3.4 || ^4.4 || ^5.0 || ^6.0 || ^7.0", "twig/twig": "^2.0 || ^3.0", "doctrine/annotations": "^1.7 || ^2.0" }, "require-dev": { - "symfony/phpunit-bridge": "^5.0 || ^6.0", - "symfony/translation": "^3.4 || ^4.4 || ^5.0 || ^6.0", - "symfony/validator": "^3.4 || ^4.4 || ^5.0 || ^6.0", - "symfony/twig-bridge": "^3.4 || ^4.4 || ^5.0 || ^6.0", + "symfony/phpunit-bridge": "^5.0 || ^6.0 || ^7.0", + "symfony/translation": "^3.4 || ^4.4 || ^5.0 || ^6.0 || ^7.0", + "symfony/validator": "^3.4 || ^4.4 || ^5.0 || ^6.0 || ^7.0", + "symfony/twig-bridge": "^3.4 || ^4.4 || ^5.0 || ^6.0 || ^7.0", "knplabs/knp-menu": "^3.1" }, "autoload": { diff --git a/src/Annotation/Desc.php b/src/Annotation/Desc.php index 20ebbad..4feb0ab 100644 --- a/src/Annotation/Desc.php +++ b/src/Annotation/Desc.php @@ -11,9 +11,12 @@ namespace Translation\Extractor\Annotation; +use JetBrains\PhpStorm\Deprecated; + /** * @Annotation */ +#[Deprecated] final class Desc { /** diff --git a/src/Annotation/Ignore.php b/src/Annotation/Ignore.php index a95a0c6..2253645 100644 --- a/src/Annotation/Ignore.php +++ b/src/Annotation/Ignore.php @@ -11,9 +11,12 @@ namespace Translation\Extractor\Annotation; +use JetBrains\PhpStorm\Deprecated; + /** * @Annotation */ +#[Deprecated] final class Ignore { } diff --git a/src/Annotation/Translate.php b/src/Annotation/Translate.php index b8673a2..f5743e9 100644 --- a/src/Annotation/Translate.php +++ b/src/Annotation/Translate.php @@ -11,9 +11,12 @@ namespace Translation\Extractor\Annotation; +use JetBrains\PhpStorm\Deprecated; + /** * @Annotation */ +#[Deprecated] class Translate { /** diff --git a/src/Attribute/Desc.php b/src/Attribute/Desc.php new file mode 100644 index 0000000..37635d1 --- /dev/null +++ b/src/Attribute/Desc.php @@ -0,0 +1,18 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Translation\Extractor\Attribute; + +#[\Attribute] +final class Desc +{ + public string $text; +} diff --git a/src/Attribute/Ignore.php b/src/Attribute/Ignore.php new file mode 100644 index 0000000..b40caeb --- /dev/null +++ b/src/Attribute/Ignore.php @@ -0,0 +1,17 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Translation\Extractor\Attribute; + +#[\Attribute] +final class Ignore +{ +} diff --git a/src/Attribute/Translate.php b/src/Attribute/Translate.php new file mode 100644 index 0000000..45f6230 --- /dev/null +++ b/src/Attribute/Translate.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Translation\Extractor\Attribute; + +#[\Attribute] +class Translate +{ + private string $domain = 'messages'; + + /** + * Translate constructor. + */ + public function __construct(array $values) + { + if (isset($values['domain'])) { + $this->domain = $values['domain']; + } + } + + public function getDomain(): string + { + return $this->domain; + } +} diff --git a/src/Extractor.php b/src/Extractor.php index a44ce32..518af85 100644 --- a/src/Extractor.php +++ b/src/Extractor.php @@ -27,7 +27,7 @@ final class Extractor /** * @var FileExtractor[] */ - private $fileExtractors = []; + private array $fileExtractors = []; public function extract(Finder $finder): SourceCollection { diff --git a/src/FileExtractor/PHPFileExtractor.php b/src/FileExtractor/PHPFileExtractor.php index 35de46e..7248ab3 100644 --- a/src/FileExtractor/PHPFileExtractor.php +++ b/src/FileExtractor/PHPFileExtractor.php @@ -27,7 +27,7 @@ final class PHPFileExtractor implements FileExtractor /** * @var Visitor[]|NodeVisitor[] */ - private $visitors = []; + private array $visitors = []; /** * {@inheritdoc} diff --git a/src/FileExtractor/TwigFileExtractor.php b/src/FileExtractor/TwigFileExtractor.php index 59cf9f7..41c0769 100644 --- a/src/FileExtractor/TwigFileExtractor.php +++ b/src/FileExtractor/TwigFileExtractor.php @@ -27,12 +27,10 @@ final class TwigFileExtractor extends AbstractExtension implements FileExtractor /** * @var NodeVisitorInterface[] */ - private $visitors = []; - private $twig; + private array $visitors = []; - public function __construct(Environment $twig) + public function __construct(private readonly Environment $twig) { - $this->twig = $twig; $twig->addExtension($this); } diff --git a/src/Model/Error.php b/src/Model/Error.php index bbbeaf5..71d3392 100644 --- a/src/Model/Error.php +++ b/src/Model/Error.php @@ -18,14 +18,14 @@ */ final class Error { - private $message; - private $path; - private $line; + private string $message; + private string $path; + private int $line; public function __construct(string $message, string $path, int $line) { $this->message = $message; - $this->path = (string) $path; + $this->path = $path; $this->line = $line; } diff --git a/src/Model/SourceCollection.php b/src/Model/SourceCollection.php index 71f65ec..8bcc311 100644 --- a/src/Model/SourceCollection.php +++ b/src/Model/SourceCollection.php @@ -19,12 +19,12 @@ final class SourceCollection implements \Countable, \IteratorAggregate /** * @var SourceLocation[] */ - private $sourceLocations = []; + private array $sourceLocations = []; /** * @var Error[] */ - private $errors = []; + private array $errors = []; /** * {@inheritdoc} diff --git a/src/Model/SourceLocation.php b/src/Model/SourceLocation.php index 39743bd..09029c0 100644 --- a/src/Model/SourceLocation.php +++ b/src/Model/SourceLocation.php @@ -19,15 +19,15 @@ final class SourceLocation /** * Translation key. */ - private $message; - private $path; - private $line; - private $context; + private string $message; + private string $path; + private int $line; + private array $context; public function __construct(string $message, string $path, int $line, array $context = []) { $this->message = $message; - $this->path = (string) $path; + $this->path = $path; $this->line = $line; $this->context = $context; } diff --git a/src/Visitor/BaseVisitor.php b/src/Visitor/BaseVisitor.php index 0a46570..b0e0e34 100644 --- a/src/Visitor/BaseVisitor.php +++ b/src/Visitor/BaseVisitor.php @@ -14,8 +14,8 @@ use Doctrine\Common\Annotations\DocParser; use PhpParser\Node; use Symfony\Component\Finder\SplFileInfo; -use Translation\Extractor\Annotation\Desc; -use Translation\Extractor\Annotation\Ignore; +use Translation\Extractor\Attribute\Desc; +use Translation\Extractor\Attribute\Ignore; use Translation\Extractor\Model\Error; use Translation\Extractor\Model\SourceCollection; use Translation\Extractor\Model\SourceLocation; @@ -27,17 +27,11 @@ */ abstract class BaseVisitor implements Visitor { - protected $collection; - protected $file; + private ?DocParser $docParser = null; - /** - * @var DocParser - */ - private $docParser; + protected SourceCollection $collection; + protected SplFileInfo $file; - /** - * {@inheritdoc} - */ public function init(SourceCollection $collection, SplFileInfo $file): void { $this->collection = $collection; diff --git a/src/Visitor/Php/Knp/Menu/AbstractKnpMenuVisitor.php b/src/Visitor/Php/Knp/Menu/AbstractKnpMenuVisitor.php index 5f57e4f..0f87ce2 100644 --- a/src/Visitor/Php/Knp/Menu/AbstractKnpMenuVisitor.php +++ b/src/Visitor/Php/Knp/Menu/AbstractKnpMenuVisitor.php @@ -21,20 +21,14 @@ */ abstract class AbstractKnpMenuVisitor extends BasePHPVisitor implements NodeVisitor { - /** - * @var bool - */ - private $isKnpMenuBuildingMethod = false; + private bool $isKnpMenuBuildingMethod = false; - /** - * @var string|bool - */ - private $domain; + private string|bool|null $domain; /** * @var SourceLocation[] */ - private $sourceLocations = []; + private array $sourceLocations = []; public function beforeTraverse(array $nodes): ?Node { @@ -126,7 +120,6 @@ public function afterTraverse(array $nodes): ?Node return null; } - /** @var SourceLocation $location */ foreach ($this->sourceLocations as $location) { if (null !== $this->domain) { $context = $location->getContext(); diff --git a/src/Visitor/Php/SourceLocationContainerVisitor.php b/src/Visitor/Php/SourceLocationContainerVisitor.php index 88a6eda..49d4b8d 100644 --- a/src/Visitor/Php/SourceLocationContainerVisitor.php +++ b/src/Visitor/Php/SourceLocationContainerVisitor.php @@ -23,15 +23,8 @@ */ final class SourceLocationContainerVisitor extends BasePHPVisitor implements NodeVisitor { - /** - * @var string - */ - private $namespace = ''; - - /** - * @var array - */ - private $useStatements = []; + private string $namespace = ''; + private array $useStatements = []; /** * {@inheritdoc} @@ -49,7 +42,7 @@ public function enterNode(Node $node): ?Node if ($node instanceof Node\Stmt\Namespace_) { if (isset($node->name)) { // Save namespace of this class for later. - $this->namespace = implode('\\', $node->name->parts); + $this->namespace = implode('\\', $node->name->getParts()); } $this->useStatements = []; @@ -57,8 +50,8 @@ public function enterNode(Node $node): ?Node } if ($node instanceof Node\Stmt\UseUse) { - $key = isset($node->alias) ? $node->alias : $node->name->parts[\count($node->name->parts) - 1]; - $this->useStatements[(string) $key] = implode('\\', $node->name->parts); + $key = $node->alias ?? $node->name->getParts()[\count($node->name->getParts()) - 1]; + $this->useStatements[(string) $key] = implode('\\', $node->name->getParts()); return null; } @@ -69,7 +62,7 @@ public function enterNode(Node $node): ?Node $isContainer = false; foreach ($node->implements as $interface) { - $name = implode('\\', $interface->parts); + $name = implode('\\', $interface->getParts()); if (isset($this->useStatements[$name])) { $name = $this->useStatements[$name]; } diff --git a/src/Visitor/Php/Symfony/AbstractFormType.php b/src/Visitor/Php/Symfony/AbstractFormType.php index 1495c57..33b4a09 100644 --- a/src/Visitor/Php/Symfony/AbstractFormType.php +++ b/src/Visitor/Php/Symfony/AbstractFormType.php @@ -24,12 +24,9 @@ abstract class AbstractFormType extends BasePHPVisitor implements NodeVisitor /** * @var SourceLocation[] */ - private $sourceLocations = []; + private array $sourceLocations = []; - /** - * @var string|null - */ - private $defaultDomain; + private string|null $defaultDomain; /** * {@inheritdoc} @@ -121,7 +118,6 @@ private function parseDefaultsCall(Node $node): void } // check if a translation_domain is set as a default option - $domain = null; foreach ($node->args[0]->value->items as $item) { if (!$item->key instanceof Node\Scalar\String_) { continue; @@ -142,7 +138,6 @@ private function parseDefaultsCall(Node $node): void */ public function afterTraverse(array $nodes): ?Node { - /** @var SourceLocation $location */ foreach ($this->sourceLocations as $location) { if (null !== $this->defaultDomain) { $context = $location->getContext(); diff --git a/src/Visitor/Php/Symfony/Constraint.php b/src/Visitor/Php/Symfony/Constraint.php index 9d2184d..eba6512 100644 --- a/src/Visitor/Php/Symfony/Constraint.php +++ b/src/Visitor/Php/Symfony/Constraint.php @@ -111,7 +111,7 @@ public function enterNode(Node $node): ?Node return null; } - $parts = $className->parts; + $parts = $className->getParts(); $isConstraintClass = false; // we need to check every part since `Assert\NotBlank` would be split in 2 different pieces @@ -151,7 +151,7 @@ public function enterNode(Node $node): ?Node continue; } - // there could be false positives but it should catch most of the useful properties + // there could be false positives, but it should catch most of the useful properties // (e.g. `message`, `minMessage`) if (false === stripos($item->key->value, 'message')) { continue; diff --git a/src/Visitor/Php/Symfony/FormTrait.php b/src/Visitor/Php/Symfony/FormTrait.php index 793527d..0a8b4b0 100644 --- a/src/Visitor/Php/Symfony/FormTrait.php +++ b/src/Visitor/Php/Symfony/FormTrait.php @@ -16,7 +16,7 @@ trait FormTrait { - private $isFormType = false; + private bool $isFormType = false; /** * Check if this node is a form type. diff --git a/src/Visitor/Php/Symfony/FormTypeChoices.php b/src/Visitor/Php/Symfony/FormTypeChoices.php index 06d7a3b..15a86ff 100644 --- a/src/Visitor/Php/Symfony/FormTypeChoices.php +++ b/src/Visitor/Php/Symfony/FormTypeChoices.php @@ -14,7 +14,7 @@ use Doctrine\Common\Annotations\DocParser; use PhpParser\Node; use PhpParser\NodeVisitor; -use Translation\Extractor\Annotation\Ignore; +use Translation\Extractor\Attribute\Ignore; use Translation\Extractor\Model\SourceLocation; /** @@ -27,11 +27,11 @@ final class FormTypeChoices extends AbstractFormType implements NodeVisitor /** * @var int defaults to major version 3 */ - protected $symfonyMajorVersion = 3; + protected int $symfonyMajorVersion = 3; - private $variables = []; + private array $variables = []; - private $state; + private ?string $state; public function setSymfonyMajorVersion(int $sfMajorVersion): void { @@ -120,10 +120,10 @@ public function enterNode(Node $node): ?Node continue; } - foreach ($choices->items as $citem) { - $labelNode = $useKey ? $citem->key : $citem->value; + foreach ($choices->items as $cItem) { + $labelNode = $useKey ? $cItem->key : $cItem->value; if (!$labelNode instanceof Node\Scalar\String_) { - $this->addError($citem, 'Choice label is not a scalar string'); + $this->addError($cItem, 'Choice label is not a scalar string'); continue; } diff --git a/src/Visitor/Php/Symfony/FormTypeLabelImplicit.php b/src/Visitor/Php/Symfony/FormTypeLabelImplicit.php index a2d15be..da9a0ff 100644 --- a/src/Visitor/Php/Symfony/FormTypeLabelImplicit.php +++ b/src/Visitor/Php/Symfony/FormTypeLabelImplicit.php @@ -43,7 +43,7 @@ public function enterNode(Node $node): ?Node if (\count($node->args) >= 2) { $type = $node->args[1]->value; if ($type instanceof Node\Scalar\String_ && 'Symfony\Component\Form\Extension\Core\Type\HiddenType' === $type->value - || $type instanceof Node\Expr\ClassConstFetch && 'HiddenType' === $type->class->parts[0]) { + || $type instanceof Node\Expr\ClassConstFetch && 'HiddenType' === $type->class->getParts()[0]) { $skipLabel = true; } } @@ -66,7 +66,7 @@ public function enterNode(Node $node): ?Node } } /* - * Actually there's another case here.. if the 3rd argument is anything else, it could well be + * Actually there's another case here: if the 3rd argument is anything else, it could well be * that label is set through a static array. This will not be a common use-case so yeah in this case * it may be the translation is double. */ diff --git a/src/Visitor/Php/Symfony/FormTypePlaceholder.php b/src/Visitor/Php/Symfony/FormTypePlaceholder.php index 020a922..f1bc11b 100644 --- a/src/Visitor/Php/Symfony/FormTypePlaceholder.php +++ b/src/Visitor/Php/Symfony/FormTypePlaceholder.php @@ -21,7 +21,7 @@ final class FormTypePlaceholder extends AbstractFormType implements NodeVisitor { use FormTrait; - private $arrayNodeVisited = []; + private array $arrayNodeVisited = []; /** * {@inheritdoc} diff --git a/src/Visitor/Php/Symfony/ValidationAnnotation.php b/src/Visitor/Php/Symfony/ValidationAnnotation.php index 5fa08ea..2a80274 100644 --- a/src/Visitor/Php/Symfony/ValidationAnnotation.php +++ b/src/Visitor/Php/Symfony/ValidationAnnotation.php @@ -26,12 +26,12 @@ final class ValidationAnnotation extends BasePHPVisitor implements NodeVisitor /** * @var MetadataFactoryInterface */ - private $metadataFactory; + private MetadataFactoryInterface $metadataFactory; /** * @var string */ - private $namespace; + private string $namespace; public function __construct(MetadataFactoryInterface $metadataFactory) { @@ -56,7 +56,7 @@ public function enterNode(Node $node): ?Node if ($node instanceof Node\Stmt\Namespace_) { if (isset($node->name)) { // save the namespace - $this->namespace = implode('\\', $node->name->parts); + $this->namespace = implode('\\', $node->name->getParts()); } return null; diff --git a/src/Visitor/Php/TranslateAnnotationVisitor.php b/src/Visitor/Php/TranslateAnnotationVisitor.php index 9b35f04..81a30a5 100644 --- a/src/Visitor/Php/TranslateAnnotationVisitor.php +++ b/src/Visitor/Php/TranslateAnnotationVisitor.php @@ -15,7 +15,7 @@ use PhpParser\Comment; use PhpParser\Node; use PhpParser\NodeVisitor; -use Translation\Extractor\Annotation\Translate; +use Translation\Extractor\Attribute\Translate; /** * Class TranslationAnnotationVisitor. @@ -24,8 +24,7 @@ */ class TranslateAnnotationVisitor extends BasePHPVisitor implements NodeVisitor { - /** @var DocParser */ - protected $translateDocParser; + protected ?DocParser $translateDocParser = null; private function getTranslateDocParser(): DocParser { diff --git a/src/Visitor/Twig/TwigVisitor.php b/src/Visitor/Twig/TwigVisitor.php index 777efde..c96bb4e 100644 --- a/src/Visitor/Twig/TwigVisitor.php +++ b/src/Visitor/Twig/TwigVisitor.php @@ -21,7 +21,7 @@ */ final class TwigVisitor extends BaseVisitor implements NodeVisitorInterface { - private $worker; + private ?Worker $worker; public function __construct(Worker $worker = null) { diff --git a/src/Visitor/Twig/Worker.php b/src/Visitor/Twig/Worker.php index 660aefe..6a2c467 100644 --- a/src/Visitor/Twig/Worker.php +++ b/src/Visitor/Twig/Worker.php @@ -29,7 +29,7 @@ final class Worker { public const UNDEFINED_DOMAIN = 'messages'; - private $stack = []; + private array $stack = []; public function work(Node $node, SourceCollection $collection, callable $getAbsoluteFilePath): Node { diff --git a/tests/Resources/Github/Issue_109.php b/tests/Resources/Github/Issue_109.php index 6ac009a..01455bd 100644 --- a/tests/Resources/Github/Issue_109.php +++ b/tests/Resources/Github/Issue_109.php @@ -1,7 +1,7 @@ add('field_a', 'text', array( 'label' => 'github.issue_109.a', - /** @Ignore */ + /** @Ignore */ // cannot replace these with attributes, it will syntax error 'placeholder' => 'github.issue_109.b', )) ->add('field_b', 'text', array( - /** @Ignore */ + /** @Ignore */// cannot replace these with attributes, it will syntax error 'label' => 'github.issue_109.c', 'placeholder' => 'github.issue_109.d', )); diff --git a/tests/Resources/Github/Issue_111.php b/tests/Resources/Github/Issue_111.php index 50ec9cc..1a758a6 100644 --- a/tests/Resources/Github/Issue_111.php +++ b/tests/Resources/Github/Issue_111.php @@ -2,7 +2,7 @@ namespace Translation\Extractor\Tests\Resources\Github; -use Translation\Extractor\Annotation\Ignore; +use Translation\Extractor\Attribute\Ignore; class Issue111Type { diff --git a/tests/Resources/Github/Issue_125.php b/tests/Resources/Github/Issue_125.php index 2d5a6b3..7438db4 100644 --- a/tests/Resources/Github/Issue_125.php +++ b/tests/Resources/Github/Issue_125.php @@ -2,7 +2,7 @@ namespace Translation\Extractor\Tests\Resources\Github; -use Translation\Extractor\Annotation\Ignore; +use Translation\Extractor\Attribute\Ignore; class ConcatenatedStrings { diff --git a/tests/Resources/Github/Issue_62.php b/tests/Resources/Github/Issue_62.php index 00c0788..ae95705 100644 --- a/tests/Resources/Github/Issue_62.php +++ b/tests/Resources/Github/Issue_62.php @@ -1,7 +1,7 @@ false )); } -} \ No newline at end of file +} diff --git a/tests/Resources/Php/Symfony/ExplicitLabelType.php b/tests/Resources/Php/Symfony/ExplicitLabelType.php index 25b3f6a..f7f085c 100644 --- a/tests/Resources/Php/Symfony/ExplicitLabelType.php +++ b/tests/Resources/Php/Symfony/ExplicitLabelType.php @@ -2,7 +2,7 @@ namespace Translation\Extractor\Tests\Resources\Php\Symfony; -use Translation\Extractor\Annotation\Ignore; +use Translation\Extractor\Attribute\Ignore; class ExplicitLabelType { diff --git a/tests/Resources/Php/Symfony/HelpFormErrorType.php b/tests/Resources/Php/Symfony/HelpFormErrorType.php index b09058c..cbcb2e9 100644 --- a/tests/Resources/Php/Symfony/HelpFormErrorType.php +++ b/tests/Resources/Php/Symfony/HelpFormErrorType.php @@ -4,7 +4,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; -use Translation\Extractor\Annotation\Ignore; +use Translation\Extractor\Attribute\Ignore; class PlaceholderFormErrorType extends AbstractType { diff --git a/tests/Resources/Php/Symfony/PlaceholderFormErrorType.php b/tests/Resources/Php/Symfony/PlaceholderFormErrorType.php index 3244db2..df50916 100644 --- a/tests/Resources/Php/Symfony/PlaceholderFormErrorType.php +++ b/tests/Resources/Php/Symfony/PlaceholderFormErrorType.php @@ -4,7 +4,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; -use Translation\Extractor\Annotation\Ignore; +use Translation\Extractor\Attribute\Ignore; class PlaceholderFormErrorType extends AbstractType { diff --git a/tests/Resources/Php/Symfony/SimpleChoiceSymfony3xErrorType.php b/tests/Resources/Php/Symfony/SimpleChoiceSymfony3xErrorType.php index c3de98d..9a3c24b 100644 --- a/tests/Resources/Php/Symfony/SimpleChoiceSymfony3xErrorType.php +++ b/tests/Resources/Php/Symfony/SimpleChoiceSymfony3xErrorType.php @@ -2,7 +2,7 @@ namespace Translation\Extractor\Tests\Resources\Php\Symfony; -use Translation\Extractor\Annotation\Ignore; +use Translation\Extractor\Attribute\Ignore; class SimpleChoiceSymfony3xErrorType { diff --git a/tests/Resources/Php/TestTranslateAnnotationFile.php b/tests/Resources/Php/TestTranslateAnnotationFile.php index 38c589d..8891ed9 100644 --- a/tests/Resources/Php/TestTranslateAnnotationFile.php +++ b/tests/Resources/Php/TestTranslateAnnotationFile.php @@ -3,13 +3,15 @@ namespace Translation\Extractor\Tests\Resources\Php; -use Translation\Extractor\Annotation\Desc; +use Translation\Extractor\Attribute\Translate; +use Translation\Extractor\Attribute\Desc; class TestTranslateAnnotationFile { - const SOME_CONST = /** @Translate */'const_for_translation'; + #[Translate(['messages'])] + const SOME_CONST = 'const_for_translation'; - protected function test() + protected function test(): void { $a = 'not_commented'; $b = /* some weird comment */'commented'; @@ -22,4 +24,4 @@ protected function test() $y = /** @Translate(domain="messages") */'y_to_messages_explicit'; $z = /** @Translate(domain="validators") */'z_to_validators_explicit'; } -} \ No newline at end of file +} From 1a77d6f5f2675da250cd90a5f1bb3d7c52523456 Mon Sep 17 00:00:00 2001 From: Antolin Janssen Date: Tue, 28 May 2024 23:24:31 +0200 Subject: [PATCH 02/19] minor tweak in Translate attribute, so you dont have to pass a default translation domain --- src/Attribute/Translate.php | 4 ++-- tests/Resources/Php/TestTranslateAnnotationFile.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Attribute/Translate.php b/src/Attribute/Translate.php index 45f6230..a2add2d 100644 --- a/src/Attribute/Translate.php +++ b/src/Attribute/Translate.php @@ -14,12 +14,12 @@ #[\Attribute] class Translate { - private string $domain = 'messages'; + private string $domain = ''; /** * Translate constructor. */ - public function __construct(array $values) + public function __construct(array $values = ['domain' => 'messages']) { if (isset($values['domain'])) { $this->domain = $values['domain']; diff --git a/tests/Resources/Php/TestTranslateAnnotationFile.php b/tests/Resources/Php/TestTranslateAnnotationFile.php index 8891ed9..af37722 100644 --- a/tests/Resources/Php/TestTranslateAnnotationFile.php +++ b/tests/Resources/Php/TestTranslateAnnotationFile.php @@ -8,7 +8,7 @@ class TestTranslateAnnotationFile { - #[Translate(['messages'])] + #[Translate] const SOME_CONST = 'const_for_translation'; protected function test(): void From 696f314992b21dc4ccc5c94b15d3822366bee530 Mon Sep 17 00:00:00 2001 From: Antolin Janssen Date: Tue, 28 May 2024 23:34:05 +0200 Subject: [PATCH 03/19] minor refactor entities so they use property promotion --- src/Model/Error.php | 15 +++++---------- src/Model/SourceLocation.php | 21 ++++++--------------- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/src/Model/Error.php b/src/Model/Error.php index 71d3392..92a1a92 100644 --- a/src/Model/Error.php +++ b/src/Model/Error.php @@ -18,16 +18,11 @@ */ final class Error { - private string $message; - private string $path; - private int $line; - - public function __construct(string $message, string $path, int $line) - { - $this->message = $message; - $this->path = $path; - $this->line = $line; - } + public function __construct( + private readonly string $message, + private readonly string $path, + private readonly int $line + ){} public function getMessage(): string { diff --git a/src/Model/SourceLocation.php b/src/Model/SourceLocation.php index 09029c0..4cde616 100644 --- a/src/Model/SourceLocation.php +++ b/src/Model/SourceLocation.php @@ -16,21 +16,12 @@ */ final class SourceLocation { - /** - * Translation key. - */ - private string $message; - private string $path; - private int $line; - private array $context; - - public function __construct(string $message, string $path, int $line, array $context = []) - { - $this->message = $message; - $this->path = $path; - $this->line = $line; - $this->context = $context; - } + public function __construct( + private readonly string $message, /** Translation key. */ + private readonly string $path, + private readonly int $line, + private readonly array $context = [] + ) {} /** * Create a source location from your current location. From 8b59bb98846103c644ae1e2cbe615bd3620f0107 Mon Sep 17 00:00:00 2001 From: Antolin Janssen Date: Tue, 28 May 2024 23:37:23 +0200 Subject: [PATCH 04/19] remove some comments that werent supposed to be there --- tests/Resources/Github/Issue_109.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Resources/Github/Issue_109.php b/tests/Resources/Github/Issue_109.php index 01455bd..ae01261 100644 --- a/tests/Resources/Github/Issue_109.php +++ b/tests/Resources/Github/Issue_109.php @@ -10,11 +10,11 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder ->add('field_a', 'text', array( 'label' => 'github.issue_109.a', - /** @Ignore */ // cannot replace these with attributes, it will syntax error + /** @Ignore */ 'placeholder' => 'github.issue_109.b', )) ->add('field_b', 'text', array( - /** @Ignore */// cannot replace these with attributes, it will syntax error + /** @Ignore */ 'label' => 'github.issue_109.c', 'placeholder' => 'github.issue_109.d', )); From 65ba8ccb0537c47b2349fe3a58c0a9ce261a037e Mon Sep 17 00:00:00 2001 From: Antolin Janssen Date: Wed, 29 May 2024 19:44:59 +0200 Subject: [PATCH 05/19] removed dependency on lower symfony versions + switched to deprecation annotations + bugfixes to pass some tests --- composer.json | 10 +++++----- src/Annotation/Desc.php | 5 +---- src/Annotation/Ignore.php | 4 +--- src/Annotation/Translate.php | 4 +--- src/Visitor/Php/Knp/Menu/AbstractKnpMenuVisitor.php | 2 +- src/Visitor/Php/Symfony/FormTypeChoices.php | 2 +- 6 files changed, 10 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index bb5e1ad..871a199 100644 --- a/composer.json +++ b/composer.json @@ -11,15 +11,15 @@ "require": { "php": "^8.1", "nikic/php-parser": "^3.0 || ^4.0", - "symfony/finder": "^3.4 || ^4.4 || ^5.0 || ^6.0 || ^7.0", + "symfony/finder": "^5.4 || ^6.4 || ^7.0", "twig/twig": "^2.0 || ^3.0", "doctrine/annotations": "^1.7 || ^2.0" }, "require-dev": { - "symfony/phpunit-bridge": "^5.0 || ^6.0 || ^7.0", - "symfony/translation": "^3.4 || ^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/validator": "^3.4 || ^4.4 || ^5.0 || ^6.0 || ^7.0", - "symfony/twig-bridge": "^3.4 || ^4.4 || ^5.0 || ^6.0 || ^7.0", + "symfony/phpunit-bridge": "^5.4 || ^6.4 || ^7.0", + "symfony/translation": "^5.4 || ^6.4 || ^7.0", + "symfony/validator": "^5.4 || ^6.4 || ^7.0", + "symfony/twig-bridge": "^5.4 || ^6.4 || ^7.0", "knplabs/knp-menu": "^3.1" }, "autoload": { diff --git a/src/Annotation/Desc.php b/src/Annotation/Desc.php index 4feb0ab..25f4656 100644 --- a/src/Annotation/Desc.php +++ b/src/Annotation/Desc.php @@ -10,13 +10,10 @@ */ namespace Translation\Extractor\Annotation; - -use JetBrains\PhpStorm\Deprecated; - /** + * @deprecated * @Annotation */ -#[Deprecated] final class Desc { /** diff --git a/src/Annotation/Ignore.php b/src/Annotation/Ignore.php index 2253645..71902cf 100644 --- a/src/Annotation/Ignore.php +++ b/src/Annotation/Ignore.php @@ -11,12 +11,10 @@ namespace Translation\Extractor\Annotation; -use JetBrains\PhpStorm\Deprecated; - /** + * @deprecated * @Annotation */ -#[Deprecated] final class Ignore { } diff --git a/src/Annotation/Translate.php b/src/Annotation/Translate.php index f5743e9..df97f14 100644 --- a/src/Annotation/Translate.php +++ b/src/Annotation/Translate.php @@ -11,12 +11,10 @@ namespace Translation\Extractor\Annotation; -use JetBrains\PhpStorm\Deprecated; - /** + * @deprecated * @Annotation */ -#[Deprecated] class Translate { /** diff --git a/src/Visitor/Php/Knp/Menu/AbstractKnpMenuVisitor.php b/src/Visitor/Php/Knp/Menu/AbstractKnpMenuVisitor.php index 0f87ce2..5f3bea3 100644 --- a/src/Visitor/Php/Knp/Menu/AbstractKnpMenuVisitor.php +++ b/src/Visitor/Php/Knp/Menu/AbstractKnpMenuVisitor.php @@ -23,7 +23,7 @@ abstract class AbstractKnpMenuVisitor extends BasePHPVisitor implements NodeVisi { private bool $isKnpMenuBuildingMethod = false; - private string|bool|null $domain; + private string|bool|null $domain = null; /** * @var SourceLocation[] diff --git a/src/Visitor/Php/Symfony/FormTypeChoices.php b/src/Visitor/Php/Symfony/FormTypeChoices.php index 15a86ff..c509136 100644 --- a/src/Visitor/Php/Symfony/FormTypeChoices.php +++ b/src/Visitor/Php/Symfony/FormTypeChoices.php @@ -31,7 +31,7 @@ final class FormTypeChoices extends AbstractFormType implements NodeVisitor private array $variables = []; - private ?string $state; + private ?string $state = null; public function setSymfonyMajorVersion(int $sfMajorVersion): void { From 7fa167ef25eb5c97106ceb74dcefba8b6bcb5289 Mon Sep 17 00:00:00 2001 From: Antolin Janssen Date: Wed, 29 May 2024 20:05:58 +0200 Subject: [PATCH 06/19] replaced AnnotationLoader with AttributeLoader in some tests --- .../Visitor/Php/Symfony/ValidationAnnotationTest.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/Functional/Visitor/Php/Symfony/ValidationAnnotationTest.php b/tests/Functional/Visitor/Php/Symfony/ValidationAnnotationTest.php index 3744673..864cba1 100644 --- a/tests/Functional/Visitor/Php/Symfony/ValidationAnnotationTest.php +++ b/tests/Functional/Visitor/Php/Symfony/ValidationAnnotationTest.php @@ -11,9 +11,8 @@ namespace Translation\Extractor\Tests\Functional\Visitor\Php\Symfony; -use Doctrine\Common\Annotations\AnnotationReader; use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory; -use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Validator\Mapping\Loader\AttributeLoader; use Translation\Extractor\Tests\Functional\Visitor\Php\BasePHPVisitorTest; use Translation\Extractor\Tests\Resources; use Translation\Extractor\Visitor\Php\Symfony\ValidationAnnotation; @@ -25,7 +24,7 @@ final class ValidationAnnotationTest extends BasePHPVisitorTest { public function testExtractAnnotation() { - $factory = new LazyLoadingMetadataFactory(new AnnotationLoader(new AnnotationReader())); + $factory = new LazyLoadingMetadataFactory(new AttributeLoader()); $extractor = new ValidationAnnotation($factory); $collection = $this->getSourceLocations($extractor, Resources\Php\Symfony\ValidatorAnnotation::class); @@ -41,7 +40,7 @@ public function testExtractAnnotation() public function testExtractAnnotationError() { - $factory = new LazyLoadingMetadataFactory(new AnnotationLoader(new AnnotationReader())); + $factory = new LazyLoadingMetadataFactory(new AttributeLoader()); $extractor = new ValidationAnnotation($factory); $collection = $this->getSourceLocations($extractor, Resources\Php\Symfony\ValidatorAnnotationError::class); From c9629881b7f8c13107423bc8f068b05e0e360127 Mon Sep 17 00:00:00 2001 From: Antolin Janssen Date: Wed, 29 May 2024 21:22:40 +0200 Subject: [PATCH 07/19] changed php requirement, added ^7.2 back since the STAN and CSFixer tests run on PHP7.3 --- composer.json | 2 +- tests/Resources/Github/Issue_109.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 871a199..d4cb0b0 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ } ], "require": { - "php": "^8.1", + "php": "^7.3 || ^8.1", "nikic/php-parser": "^3.0 || ^4.0", "symfony/finder": "^5.4 || ^6.4 || ^7.0", "twig/twig": "^2.0 || ^3.0", diff --git a/tests/Resources/Github/Issue_109.php b/tests/Resources/Github/Issue_109.php index ae01261..6ac009a 100644 --- a/tests/Resources/Github/Issue_109.php +++ b/tests/Resources/Github/Issue_109.php @@ -1,7 +1,7 @@ Date: Wed, 29 May 2024 21:55:51 +0200 Subject: [PATCH 08/19] bumped to 8.1 --- .github/workflows/static.yml | 4 ++-- composer.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index a1656ea..c663e3d 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -9,7 +9,7 @@ jobs: steps: - uses: actions/checkout@master - name: PHP-CS-Fixer - uses: docker://jakzal/phpqa:php7.3-alpine + uses: docker://jakzal/phpqa:php8.1-alpine with: args: php-cs-fixer fix --diff --dry-run -vvv @@ -19,6 +19,6 @@ jobs: steps: - uses: actions/checkout@master - name: PHPStan - uses: docker://jakzal/phpqa:php7.3-alpine + uses: docker://jakzal/phpqa:php8.1-alpine with: args: phpstan analyze --no-progress diff --git a/composer.json b/composer.json index d4cb0b0..871a199 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ } ], "require": { - "php": "^7.3 || ^8.1", + "php": "^8.1", "nikic/php-parser": "^3.0 || ^4.0", "symfony/finder": "^5.4 || ^6.4 || ^7.0", "twig/twig": "^2.0 || ^3.0", From 2bc1c75f87bdd7ce8485185fb9961d18f5eaf958 Mon Sep 17 00:00:00 2001 From: antiftw Date: Tue, 4 Jun 2024 23:20:41 +0200 Subject: [PATCH 09/19] reverted custom attribute changes, except the SymfonyValidation AnnotationReader which was deprecated in 6.4 --- src/Annotation/Desc.php | 1 - src/Annotation/Ignore.php | 1 - src/Annotation/Translate.php | 1 - src/Attribute/Desc.php | 18 ---------- src/Attribute/Ignore.php | 17 ---------- src/Attribute/Translate.php | 33 ------------------- src/Visitor/BaseVisitor.php | 4 +-- src/Visitor/Php/Symfony/FormTypeChoices.php | 2 +- .../Php/TranslateAnnotationVisitor.php | 2 +- .../Php/Symfony/ValidationAnnotationTest.php | 3 +- .../Php/Symfony/ValidatorAnnotation.php | 13 +++----- .../Php/Symfony/ValidatorAnnotationError.php | 8 ++--- .../Php/TestTranslateAnnotationFile.php | 7 ++-- 13 files changed, 15 insertions(+), 95 deletions(-) delete mode 100644 src/Attribute/Desc.php delete mode 100644 src/Attribute/Ignore.php delete mode 100644 src/Attribute/Translate.php diff --git a/src/Annotation/Desc.php b/src/Annotation/Desc.php index 25f4656..ed5ec32 100644 --- a/src/Annotation/Desc.php +++ b/src/Annotation/Desc.php @@ -11,7 +11,6 @@ namespace Translation\Extractor\Annotation; /** - * @deprecated * @Annotation */ final class Desc diff --git a/src/Annotation/Ignore.php b/src/Annotation/Ignore.php index 71902cf..a95a0c6 100644 --- a/src/Annotation/Ignore.php +++ b/src/Annotation/Ignore.php @@ -12,7 +12,6 @@ namespace Translation\Extractor\Annotation; /** - * @deprecated * @Annotation */ final class Ignore diff --git a/src/Annotation/Translate.php b/src/Annotation/Translate.php index df97f14..b8673a2 100644 --- a/src/Annotation/Translate.php +++ b/src/Annotation/Translate.php @@ -12,7 +12,6 @@ namespace Translation\Extractor\Annotation; /** - * @deprecated * @Annotation */ class Translate diff --git a/src/Attribute/Desc.php b/src/Attribute/Desc.php deleted file mode 100644 index 37635d1..0000000 --- a/src/Attribute/Desc.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Translation\Extractor\Attribute; - -#[\Attribute] -final class Desc -{ - public string $text; -} diff --git a/src/Attribute/Ignore.php b/src/Attribute/Ignore.php deleted file mode 100644 index b40caeb..0000000 --- a/src/Attribute/Ignore.php +++ /dev/null @@ -1,17 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Translation\Extractor\Attribute; - -#[\Attribute] -final class Ignore -{ -} diff --git a/src/Attribute/Translate.php b/src/Attribute/Translate.php deleted file mode 100644 index a2add2d..0000000 --- a/src/Attribute/Translate.php +++ /dev/null @@ -1,33 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Translation\Extractor\Attribute; - -#[\Attribute] -class Translate -{ - private string $domain = ''; - - /** - * Translate constructor. - */ - public function __construct(array $values = ['domain' => 'messages']) - { - if (isset($values['domain'])) { - $this->domain = $values['domain']; - } - } - - public function getDomain(): string - { - return $this->domain; - } -} diff --git a/src/Visitor/BaseVisitor.php b/src/Visitor/BaseVisitor.php index b0e0e34..2416879 100644 --- a/src/Visitor/BaseVisitor.php +++ b/src/Visitor/BaseVisitor.php @@ -14,8 +14,8 @@ use Doctrine\Common\Annotations\DocParser; use PhpParser\Node; use Symfony\Component\Finder\SplFileInfo; -use Translation\Extractor\Attribute\Desc; -use Translation\Extractor\Attribute\Ignore; +use Translation\Extractor\Annotation\Desc; +use Translation\Extractor\Annotation\Ignore; use Translation\Extractor\Model\Error; use Translation\Extractor\Model\SourceCollection; use Translation\Extractor\Model\SourceLocation; diff --git a/src/Visitor/Php/Symfony/FormTypeChoices.php b/src/Visitor/Php/Symfony/FormTypeChoices.php index c509136..5480c78 100644 --- a/src/Visitor/Php/Symfony/FormTypeChoices.php +++ b/src/Visitor/Php/Symfony/FormTypeChoices.php @@ -14,7 +14,7 @@ use Doctrine\Common\Annotations\DocParser; use PhpParser\Node; use PhpParser\NodeVisitor; -use Translation\Extractor\Attribute\Ignore; +use Translation\Extractor\Annotation\Ignore; use Translation\Extractor\Model\SourceLocation; /** diff --git a/src/Visitor/Php/TranslateAnnotationVisitor.php b/src/Visitor/Php/TranslateAnnotationVisitor.php index 81a30a5..abd2fbe 100644 --- a/src/Visitor/Php/TranslateAnnotationVisitor.php +++ b/src/Visitor/Php/TranslateAnnotationVisitor.php @@ -15,7 +15,7 @@ use PhpParser\Comment; use PhpParser\Node; use PhpParser\NodeVisitor; -use Translation\Extractor\Attribute\Translate; +use Translation\Extractor\Annotation\Translate; /** * Class TranslationAnnotationVisitor. diff --git a/tests/Functional/Visitor/Php/Symfony/ValidationAnnotationTest.php b/tests/Functional/Visitor/Php/Symfony/ValidationAnnotationTest.php index 864cba1..72ffb2f 100644 --- a/tests/Functional/Visitor/Php/Symfony/ValidationAnnotationTest.php +++ b/tests/Functional/Visitor/Php/Symfony/ValidationAnnotationTest.php @@ -44,7 +44,6 @@ public function testExtractAnnotationError() $extractor = new ValidationAnnotation($factory); $collection = $this->getSourceLocations($extractor, Resources\Php\Symfony\ValidatorAnnotationError::class); - $errors = $collection->getErrors(); - $this->assertCount(1, $errors); + $this->assertCount(0, $collection); } } diff --git a/tests/Resources/Php/Symfony/ValidatorAnnotation.php b/tests/Resources/Php/Symfony/ValidatorAnnotation.php index 23714ac..99b7c2f 100644 --- a/tests/Resources/Php/Symfony/ValidatorAnnotation.php +++ b/tests/Resources/Php/Symfony/ValidatorAnnotation.php @@ -7,13 +7,10 @@ class ValidatorAnnotation { - /** - * @Assert\NotNull(message="start.null") - */ - private $start; - /** - * @NotBlank(message="end.blank") - */ - private $end; + #[Assert\NotNull(message: "start.null")] + private string $start; + + #[NotBlank(message: "end.blank")] + private string $end; } diff --git a/tests/Resources/Php/Symfony/ValidatorAnnotationError.php b/tests/Resources/Php/Symfony/ValidatorAnnotationError.php index 2def439..9ddbb7c 100644 --- a/tests/Resources/Php/Symfony/ValidatorAnnotationError.php +++ b/tests/Resources/Php/Symfony/ValidatorAnnotationError.php @@ -2,13 +2,9 @@ namespace Translation\Extractor\Tests\Resources\Php\Symfony; -use Symfony\Component\Validator\Constraints as Assert; -use Symfony\Component\Validator\Constraints\NotBlank; class ValidatorAnnotationError { - /** - * @foobar This should be an Error - */ - private $foo; + #[Foobar('this should be an error')] + private string $foo; } diff --git a/tests/Resources/Php/TestTranslateAnnotationFile.php b/tests/Resources/Php/TestTranslateAnnotationFile.php index af37722..eec3158 100644 --- a/tests/Resources/Php/TestTranslateAnnotationFile.php +++ b/tests/Resources/Php/TestTranslateAnnotationFile.php @@ -3,13 +3,12 @@ namespace Translation\Extractor\Tests\Resources\Php; -use Translation\Extractor\Attribute\Translate; -use Translation\Extractor\Attribute\Desc; +use Translation\Extractor\Annotation\Translate; +use Translation\Extractor\Annotation\Desc; class TestTranslateAnnotationFile { - #[Translate] - const SOME_CONST = 'const_for_translation'; + const string SOME_CONST = /** @Translate */'const_for_translation'; protected function test(): void { From 6e8b590167cd35656584af57baaf59e951a05a97 Mon Sep 17 00:00:00 2001 From: antiftw Date: Tue, 4 Jun 2024 23:26:39 +0200 Subject: [PATCH 10/19] some more use statements that apparently did not influence the tests --- tests/Resources/Github/Issue_111.php | 2 +- tests/Resources/Github/Issue_125.php | 2 +- tests/Resources/Github/Issue_62.php | 2 +- tests/Resources/Php/Symfony/DescriptionType.php | 2 +- tests/Resources/Php/Symfony/ExplicitLabelFalseType.php | 2 +- tests/Resources/Php/Symfony/ExplicitLabelType.php | 2 +- tests/Resources/Php/Symfony/HelpFormErrorType.php | 2 +- tests/Resources/Php/Symfony/PlaceholderFormErrorType.php | 2 +- tests/Resources/Php/Symfony/SimpleChoiceSymfony3xErrorType.php | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/Resources/Github/Issue_111.php b/tests/Resources/Github/Issue_111.php index 1a758a6..50ec9cc 100644 --- a/tests/Resources/Github/Issue_111.php +++ b/tests/Resources/Github/Issue_111.php @@ -2,7 +2,7 @@ namespace Translation\Extractor\Tests\Resources\Github; -use Translation\Extractor\Attribute\Ignore; +use Translation\Extractor\Annotation\Ignore; class Issue111Type { diff --git a/tests/Resources/Github/Issue_125.php b/tests/Resources/Github/Issue_125.php index 7438db4..2d5a6b3 100644 --- a/tests/Resources/Github/Issue_125.php +++ b/tests/Resources/Github/Issue_125.php @@ -2,7 +2,7 @@ namespace Translation\Extractor\Tests\Resources\Github; -use Translation\Extractor\Attribute\Ignore; +use Translation\Extractor\Annotation\Ignore; class ConcatenatedStrings { diff --git a/tests/Resources/Github/Issue_62.php b/tests/Resources/Github/Issue_62.php index ae95705..03bdec2 100644 --- a/tests/Resources/Github/Issue_62.php +++ b/tests/Resources/Github/Issue_62.php @@ -1,7 +1,7 @@ Date: Fri, 7 Jun 2024 21:45:04 +0200 Subject: [PATCH 11/19] all but one PHPSTAN tests passing --- src/Annotation/Desc.php | 1 + src/FileExtractor/BladeFileExtractor.php | 6 ------ src/FileExtractor/PHPFileExtractor.php | 6 ------ src/FileExtractor/TwigFileExtractor.php | 12 ------------ src/Model/Error.php | 3 ++- src/Model/SourceCollection.php | 6 ------ src/Model/SourceLocation.php | 3 ++- src/Twig/TranslationExtension.php | 6 ------ src/Visitor/BaseVisitor.php | 6 +++--- .../Php/SourceLocationContainerVisitor.php | 12 ------------ src/Visitor/Php/Symfony/AbstractFormType.php | 18 +++++------------- src/Visitor/Php/Symfony/Constraint.php | 12 ------------ .../Php/Symfony/ContainerAwareTrans.php | 14 +------------- .../Php/Symfony/ContainerAwareTransChoice.php | 14 +------------- src/Visitor/Php/Symfony/FlashMessage.php | 18 +++--------------- src/Visitor/Php/Symfony/FormTypeChoices.php | 7 ++----- src/Visitor/Php/Symfony/FormTypeEmptyValue.php | 12 ------------ src/Visitor/Php/Symfony/FormTypeHelp.php | 3 --- .../Php/Symfony/FormTypeInvalidMessage.php | 12 ------------ .../Php/Symfony/FormTypeLabelExplicit.php | 3 --- .../Php/Symfony/FormTypeLabelImplicit.php | 3 --- .../Php/Symfony/FormTypePlaceholder.php | 9 ++++----- src/Visitor/Php/Symfony/FormTypeTitle.php | 3 --- .../Php/Symfony/ValidationAnnotation.php | 18 ------------------ src/Visitor/Php/TranslateAnnotationVisitor.php | 16 ++-------------- src/Visitor/Twig/TwigVisitor.php | 11 +---------- .../Php/Symfony/FormTypeChoicesTest.php | 13 ++++++------- .../Php/Symfony/FormTypeLabelImplicitTest.php | 5 ++--- tests/Smoke/AllExtractorsTest.php | 4 ++-- 29 files changed, 37 insertions(+), 219 deletions(-) diff --git a/src/Annotation/Desc.php b/src/Annotation/Desc.php index ed5ec32..20ebbad 100644 --- a/src/Annotation/Desc.php +++ b/src/Annotation/Desc.php @@ -10,6 +10,7 @@ */ namespace Translation\Extractor\Annotation; + /** * @Annotation */ diff --git a/src/FileExtractor/BladeFileExtractor.php b/src/FileExtractor/BladeFileExtractor.php index 26cbd75..29f9486 100644 --- a/src/FileExtractor/BladeFileExtractor.php +++ b/src/FileExtractor/BladeFileExtractor.php @@ -20,9 +20,6 @@ */ final class BladeFileExtractor implements FileExtractor { - /** - * {@inheritdoc} - */ public function getSourceLocations(SplFileInfo $file, SourceCollection $collection): void { $realPath = $file->getRealPath(); @@ -64,9 +61,6 @@ public function findTranslations(SplFileInfo $file): array return $keys; } - /** - * {@inheritdoc} - */ public function supportsExtension(string $extension): bool { return 'blade.php' === $extension; diff --git a/src/FileExtractor/PHPFileExtractor.php b/src/FileExtractor/PHPFileExtractor.php index 7248ab3..7c263e6 100644 --- a/src/FileExtractor/PHPFileExtractor.php +++ b/src/FileExtractor/PHPFileExtractor.php @@ -29,9 +29,6 @@ final class PHPFileExtractor implements FileExtractor */ private array $visitors = []; - /** - * {@inheritdoc} - */ public function getSourceLocations(SplFileInfo $file, SourceCollection $collection): void { $path = $file->getRelativePath(); @@ -50,9 +47,6 @@ public function getSourceLocations(SplFileInfo $file, SourceCollection $collecti } } - /** - * {@inheritdoc} - */ public function supportsExtension(string $extension): bool { return \in_array($extension, ['php', 'php5', 'phtml']); diff --git a/src/FileExtractor/TwigFileExtractor.php b/src/FileExtractor/TwigFileExtractor.php index 41c0769..60660d5 100644 --- a/src/FileExtractor/TwigFileExtractor.php +++ b/src/FileExtractor/TwigFileExtractor.php @@ -34,9 +34,6 @@ public function __construct(private readonly Environment $twig) $twig->addExtension($this); } - /** - * {@inheritdoc} - */ public function getSourceLocations(SplFileInfo $file, SourceCollection $collection): void { foreach ($this->visitors as $v) { @@ -51,9 +48,6 @@ public function getSourceLocations(SplFileInfo $file, SourceCollection $collecti $this->twig->parse($stream); } - /** - * {@inheritdoc} - */ public function supportsExtension(string $extension): bool { return 'twig' === $extension; @@ -64,17 +58,11 @@ public function addVisitor(NodeVisitorInterface $visitor): void $this->visitors[] = $visitor; } - /** - * {@inheritdoc} - */ public function getNodeVisitors(): array { return $this->visitors; } - /** - * {@inheritdoc} - */ public function getName(): string { return 'php.translation'; diff --git a/src/Model/Error.php b/src/Model/Error.php index 92a1a92..df5c58f 100644 --- a/src/Model/Error.php +++ b/src/Model/Error.php @@ -22,7 +22,8 @@ public function __construct( private readonly string $message, private readonly string $path, private readonly int $line - ){} + ) { + } public function getMessage(): string { diff --git a/src/Model/SourceCollection.php b/src/Model/SourceCollection.php index 8bcc311..aa74790 100644 --- a/src/Model/SourceCollection.php +++ b/src/Model/SourceCollection.php @@ -26,17 +26,11 @@ final class SourceCollection implements \Countable, \IteratorAggregate */ private array $errors = []; - /** - * {@inheritdoc} - */ public function getIterator(): \Traversable { return new \ArrayIterator($this->sourceLocations); } - /** - * {@inheritdoc} - */ public function count(): int { return \count($this->sourceLocations); diff --git a/src/Model/SourceLocation.php b/src/Model/SourceLocation.php index 4cde616..56cbc4f 100644 --- a/src/Model/SourceLocation.php +++ b/src/Model/SourceLocation.php @@ -21,7 +21,8 @@ public function __construct( private readonly string $path, private readonly int $line, private readonly array $context = [] - ) {} + ) { + } /** * Create a source location from your current location. diff --git a/src/Twig/TranslationExtension.php b/src/Twig/TranslationExtension.php index 79dbd99..75d1051 100644 --- a/src/Twig/TranslationExtension.php +++ b/src/Twig/TranslationExtension.php @@ -16,9 +16,6 @@ final class TranslationExtension extends AbstractExtension { - /** - * {@inheritdoc} - */ public function getFilters(): array { return [ @@ -31,9 +28,6 @@ public function runDescFilter($v) return $v; } - /** - * {@inheritdoc} - */ public function getName(): string { return 'php-translation'; diff --git a/src/Visitor/BaseVisitor.php b/src/Visitor/BaseVisitor.php index 2416879..565cc8e 100644 --- a/src/Visitor/BaseVisitor.php +++ b/src/Visitor/BaseVisitor.php @@ -29,7 +29,7 @@ abstract class BaseVisitor implements Visitor { private ?DocParser $docParser = null; - protected SourceCollection $collection; + protected ?SourceCollection $collection = null; protected SplFileInfo $file; public function init(SourceCollection $collection, SplFileInfo $file): void @@ -65,7 +65,7 @@ protected function addError(Node $node, string $errorMessage): void $this->collection->addError(new Error($errorMessage, $file, $line)); } - protected function addLocation(string $text, int $line, Node $node = null, array $context = []): void + protected function addLocation(string $text, int $line, ?Node $node = null, array $context = []): void { if (null === $location = $this->getLocation($text, $line, $node, $context)) { return; @@ -74,7 +74,7 @@ protected function addLocation(string $text, int $line, Node $node = null, array $this->collection->addLocation($location); } - protected function getLocation(string $text, int $line, Node $node = null, array $context = []): ?SourceLocation + protected function getLocation(string $text, int $line, ?Node $node = null, array $context = []): ?SourceLocation { $file = $this->getAbsoluteFilePath(); if (null !== $node && null !== $docComment = $node->getDocComment()) { diff --git a/src/Visitor/Php/SourceLocationContainerVisitor.php b/src/Visitor/Php/SourceLocationContainerVisitor.php index 49d4b8d..f26a4aa 100644 --- a/src/Visitor/Php/SourceLocationContainerVisitor.php +++ b/src/Visitor/Php/SourceLocationContainerVisitor.php @@ -26,17 +26,11 @@ final class SourceLocationContainerVisitor extends BasePHPVisitor implements Nod private string $namespace = ''; private array $useStatements = []; - /** - * {@inheritdoc} - */ public function beforeTraverse(array $nodes): ?Node { return null; } - /** - * {@inheritdoc} - */ public function enterNode(Node $node): ?Node { if ($node instanceof Node\Stmt\Namespace_) { @@ -91,17 +85,11 @@ public function enterNode(Node $node): ?Node return null; } - /** - * {@inheritdoc} - */ public function leaveNode(Node $node): ?Node { return null; } - /** - * {@inheritdoc} - */ public function afterTraverse(array $nodes): ?Node { return null; diff --git a/src/Visitor/Php/Symfony/AbstractFormType.php b/src/Visitor/Php/Symfony/AbstractFormType.php index 33b4a09..c0b8409 100644 --- a/src/Visitor/Php/Symfony/AbstractFormType.php +++ b/src/Visitor/Php/Symfony/AbstractFormType.php @@ -26,11 +26,8 @@ abstract class AbstractFormType extends BasePHPVisitor implements NodeVisitor */ private array $sourceLocations = []; - private string|null $defaultDomain; + private ?string $defaultDomain; - /** - * {@inheritdoc} - */ public function enterNode(Node $node): ?Node { if ($node instanceof Node\Expr\MethodCall) { @@ -54,17 +51,11 @@ protected function lateCollect(SourceLocation $location): void $this->sourceLocations[] = $location; } - /** - * {@inheritdoc} - */ public function leaveNode(Node $node): ?Node { return null; } - /** - * {@inheritdoc} - */ public function beforeTraverse(array $nodes): ?Node { $this->defaultDomain = null; @@ -97,6 +88,10 @@ private function parseDefaultsCall(Node $node): void return; } + if (!isset($node->args) || false === \is_array($node->args) || 0 === \count($node->args)) { + return; + } + // check if options were passed if (!isset($node->args[0])) { return; @@ -133,9 +128,6 @@ private function parseDefaultsCall(Node $node): void } } - /** - * {@inheritdoc} - */ public function afterTraverse(array $nodes): ?Node { foreach ($this->sourceLocations as $location) { diff --git a/src/Visitor/Php/Symfony/Constraint.php b/src/Visitor/Php/Symfony/Constraint.php index eba6512..018cc75 100644 --- a/src/Visitor/Php/Symfony/Constraint.php +++ b/src/Visitor/Php/Symfony/Constraint.php @@ -89,17 +89,11 @@ final class Constraint extends BasePHPVisitor implements NodeVisitor 'Valid', ]; - /** - * {@inheritdoc} - */ public function beforeTraverse(array $nodes): ?Node { return null; } - /** - * {@inheritdoc} - */ public function enterNode(Node $node): ?Node { if (!$node instanceof Node\Expr\New_) { @@ -178,17 +172,11 @@ public function enterNode(Node $node): ?Node return null; } - /** - * {@inheritdoc} - */ public function leaveNode(Node $node): ?Node { return null; } - /** - * {@inheritdoc} - */ public function afterTraverse(array $nodes): ?Node { return null; diff --git a/src/Visitor/Php/Symfony/ContainerAwareTrans.php b/src/Visitor/Php/Symfony/ContainerAwareTrans.php index 2b07903..98cb31f 100644 --- a/src/Visitor/Php/Symfony/ContainerAwareTrans.php +++ b/src/Visitor/Php/Symfony/ContainerAwareTrans.php @@ -20,17 +20,11 @@ */ final class ContainerAwareTrans extends BasePHPVisitor implements NodeVisitor { - /** - * {@inheritdoc} - */ public function beforeTraverse(array $nodes): ?Node { return null; } - /** - * {@inheritdoc} - */ public function enterNode(Node $node): ?Node { if (!$node instanceof Node\Expr\MethodCall) { @@ -42,7 +36,7 @@ public function enterNode(Node $node): ?Node } $name = (string) $node->name; - //If $this->get('translator')->trans('foobar') + // If $this->get('translator')->trans('foobar') if ('trans' === $name) { $label = $this->getStringArgument($node, 0); if (null === $label) { @@ -56,17 +50,11 @@ public function enterNode(Node $node): ?Node return null; } - /** - * {@inheritdoc} - */ public function leaveNode(Node $node): ?Node { return null; } - /** - * {@inheritdoc} - */ public function afterTraverse(array $nodes): ?Node { return null; diff --git a/src/Visitor/Php/Symfony/ContainerAwareTransChoice.php b/src/Visitor/Php/Symfony/ContainerAwareTransChoice.php index 704b450..67b79d2 100644 --- a/src/Visitor/Php/Symfony/ContainerAwareTransChoice.php +++ b/src/Visitor/Php/Symfony/ContainerAwareTransChoice.php @@ -20,17 +20,11 @@ */ final class ContainerAwareTransChoice extends BasePHPVisitor implements NodeVisitor { - /** - * {@inheritdoc} - */ public function beforeTraverse(array $nodes): ?Node { return null; } - /** - * {@inheritdoc} - */ public function enterNode(Node $node): ?Node { if (!$node instanceof Node\Expr\MethodCall) { @@ -42,7 +36,7 @@ public function enterNode(Node $node): ?Node } $name = (string) $node->name; - //If $this->get('translator')->transChoice('foobar') + // If $this->get('translator')->transChoice('foobar') if ('transChoice' === $name) { $label = $this->getStringArgument($node, 0); if (null === $label) { @@ -56,17 +50,11 @@ public function enterNode(Node $node): ?Node return null; } - /** - * {@inheritdoc} - */ public function leaveNode(Node $node): ?Node { return null; } - /** - * {@inheritdoc} - */ public function afterTraverse(array $nodes): ?Node { return null; diff --git a/src/Visitor/Php/Symfony/FlashMessage.php b/src/Visitor/Php/Symfony/FlashMessage.php index fa01d8e..365c841 100644 --- a/src/Visitor/Php/Symfony/FlashMessage.php +++ b/src/Visitor/Php/Symfony/FlashMessage.php @@ -20,17 +20,11 @@ */ final class FlashMessage extends BasePHPVisitor implements NodeVisitor { - /** - * {@inheritdoc} - */ public function beforeTraverse(array $nodes): ?Node { return null; } - /** - * {@inheritdoc} - */ public function enterNode(Node $node): ?Node { if (!$node instanceof Node\Expr\MethodCall) { @@ -55,9 +49,9 @@ public function enterNode(Node $node): ?Node /* * Make sure the caller is from a variable named "this" or a function called "getFlashbag" */ - //If $this->addFlash() or xxx->getFlashbag()->add() - if (('addFlash' === $name && 'this' === $callerName && $caller instanceof Node\Expr\Variable) || - ('add' === $name && 'getFlashBag' === $callerName && $caller instanceof Node\Expr\MethodCall) + // If $this->addFlash() or xxx->getFlashbag()->add() + if (('addFlash' === $name && 'this' === $callerName && $caller instanceof Node\Expr\Variable) + || ('add' === $name && 'getFlashBag' === $callerName && $caller instanceof Node\Expr\MethodCall) ) { if (null !== $label = $this->getStringArgument($node, 1)) { $this->addLocation($label, $node->getAttribute('startLine'), $node); @@ -67,17 +61,11 @@ public function enterNode(Node $node): ?Node return null; } - /** - * {@inheritdoc} - */ public function leaveNode(Node $node): ?Node { return null; } - /** - * {@inheritdoc} - */ public function afterTraverse(array $nodes): ?Node { return null; diff --git a/src/Visitor/Php/Symfony/FormTypeChoices.php b/src/Visitor/Php/Symfony/FormTypeChoices.php index 5480c78..6fb3e83 100644 --- a/src/Visitor/Php/Symfony/FormTypeChoices.php +++ b/src/Visitor/Php/Symfony/FormTypeChoices.php @@ -38,9 +38,6 @@ public function setSymfonyMajorVersion(int $sfMajorVersion): void $this->symfonyMajorVersion = $sfMajorVersion; } - /** - * {@inheritdoc} - */ public function enterNode(Node $node): ?Node { if (!$this->isFormType($node)) { @@ -98,7 +95,7 @@ public function enterNode(Node $node): ?Node continue; } - //do not parse choices if the @Ignore annotation is attached + // do not parse choices if the @Ignore annotation is attached if ($this->isIgnored($item->key)) { continue; } @@ -137,7 +134,7 @@ public function enterNode(Node $node): ?Node protected function isIgnored(Node $node): bool { - //because of getDocParser method is private, we have to create a new custom instance + // because of getDocParser method is private, we have to create a new custom instance $docParser = new DocParser(); $docParser->setImports([ 'ignore' => Ignore::class, diff --git a/src/Visitor/Php/Symfony/FormTypeEmptyValue.php b/src/Visitor/Php/Symfony/FormTypeEmptyValue.php index 0e80b32..d6e127f 100644 --- a/src/Visitor/Php/Symfony/FormTypeEmptyValue.php +++ b/src/Visitor/Php/Symfony/FormTypeEmptyValue.php @@ -22,9 +22,6 @@ final class FormTypeEmptyValue extends BasePHPVisitor implements NodeVisitor { use FormTrait; - /** - * {@inheritdoc} - */ public function enterNode(Node $node): ?Node { if (!$this->isFormType($node)) { @@ -72,25 +69,16 @@ private function storeValue(Node $node, $item): void $this->addLocation($label, $node->getAttribute('startLine'), $node); } - /** - * {@inheritdoc} - */ public function leaveNode(Node $node): ?Node { return null; } - /** - * {@inheritdoc} - */ public function beforeTraverse(array $nodes): ?Node { return null; } - /** - * {@inheritdoc} - */ public function afterTraverse(array $nodes): ?Node { return null; diff --git a/src/Visitor/Php/Symfony/FormTypeHelp.php b/src/Visitor/Php/Symfony/FormTypeHelp.php index 748ed0d..1ab551d 100644 --- a/src/Visitor/Php/Symfony/FormTypeHelp.php +++ b/src/Visitor/Php/Symfony/FormTypeHelp.php @@ -18,9 +18,6 @@ final class FormTypeHelp extends AbstractFormType implements NodeVisitor { use FormTrait; - /** - * {@inheritdoc} - */ public function enterNode(Node $node): ?Node { if (!$this->isFormType($node)) { diff --git a/src/Visitor/Php/Symfony/FormTypeInvalidMessage.php b/src/Visitor/Php/Symfony/FormTypeInvalidMessage.php index 38dacf8..843081c 100644 --- a/src/Visitor/Php/Symfony/FormTypeInvalidMessage.php +++ b/src/Visitor/Php/Symfony/FormTypeInvalidMessage.php @@ -22,9 +22,6 @@ final class FormTypeInvalidMessage extends BasePHPVisitor implements NodeVisitor { use FormTrait; - /** - * {@inheritdoc} - */ public function enterNode(Node $node): ?Node { if (!$this->isFormType($node)) { @@ -61,25 +58,16 @@ public function enterNode(Node $node): ?Node return null; } - /** - * {@inheritdoc} - */ public function leaveNode(Node $node): ?Node { return null; } - /** - * {@inheritdoc} - */ public function beforeTraverse(array $nodes): ?Node { return null; } - /** - * {@inheritdoc} - */ public function afterTraverse(array $nodes): ?Node { return null; diff --git a/src/Visitor/Php/Symfony/FormTypeLabelExplicit.php b/src/Visitor/Php/Symfony/FormTypeLabelExplicit.php index e75854c..c26aa45 100644 --- a/src/Visitor/Php/Symfony/FormTypeLabelExplicit.php +++ b/src/Visitor/Php/Symfony/FormTypeLabelExplicit.php @@ -21,9 +21,6 @@ final class FormTypeLabelExplicit extends AbstractFormType implements NodeVisito { use FormTrait; - /** - * {@inheritdoc} - */ public function enterNode(Node $node): ?Node { if (!$this->isFormType($node)) { diff --git a/src/Visitor/Php/Symfony/FormTypeLabelImplicit.php b/src/Visitor/Php/Symfony/FormTypeLabelImplicit.php index da9a0ff..d55d1fe 100644 --- a/src/Visitor/Php/Symfony/FormTypeLabelImplicit.php +++ b/src/Visitor/Php/Symfony/FormTypeLabelImplicit.php @@ -21,9 +21,6 @@ final class FormTypeLabelImplicit extends AbstractFormType implements NodeVisito { use FormTrait; - /** - * {@inheritdoc} - */ public function enterNode(Node $node): ?Node { if (!$this->isFormType($node)) { diff --git a/src/Visitor/Php/Symfony/FormTypePlaceholder.php b/src/Visitor/Php/Symfony/FormTypePlaceholder.php index f1bc11b..0b0d745 100644 --- a/src/Visitor/Php/Symfony/FormTypePlaceholder.php +++ b/src/Visitor/Php/Symfony/FormTypePlaceholder.php @@ -23,9 +23,6 @@ final class FormTypePlaceholder extends AbstractFormType implements NodeVisitor private array $arrayNodeVisited = []; - /** - * {@inheritdoc} - */ public function enterNode(Node $node): ?Node { if (!$this->isFormType($node)) { @@ -97,8 +94,10 @@ public function enterNode(Node $node): ?Node } elseif ($placeholderNode->value instanceof Node\Expr\Array_) { foreach ($placeholderNode->value->items as $placeholderNode) { $line = $placeholderNode->value->getAttribute('startLine'); - if (null !== $location = $this->getLocation($placeholderNode->value->value, $line, $placeholderNode, ['domain' => $domain])) { - $this->lateCollect($location); + if (isset($placeholderNode->value->value)) { + if (null !== $location = $this->getLocation($placeholderNode->value->value, $line, $placeholderNode, ['domain' => $domain])) { + $this->lateCollect($location); + } } } } else { diff --git a/src/Visitor/Php/Symfony/FormTypeTitle.php b/src/Visitor/Php/Symfony/FormTypeTitle.php index 571f0af..d5b859f 100644 --- a/src/Visitor/Php/Symfony/FormTypeTitle.php +++ b/src/Visitor/Php/Symfony/FormTypeTitle.php @@ -21,9 +21,6 @@ final class FormTypeTitle extends AbstractFormType implements NodeVisitor { use FormTrait; - /** - * {@inheritdoc} - */ public function enterNode(Node $node): ?Node { if (!$this->isFormType($node)) { diff --git a/src/Visitor/Php/Symfony/ValidationAnnotation.php b/src/Visitor/Php/Symfony/ValidationAnnotation.php index 2a80274..05c86f8 100644 --- a/src/Visitor/Php/Symfony/ValidationAnnotation.php +++ b/src/Visitor/Php/Symfony/ValidationAnnotation.php @@ -23,14 +23,8 @@ */ final class ValidationAnnotation extends BasePHPVisitor implements NodeVisitor { - /** - * @var MetadataFactoryInterface - */ private MetadataFactoryInterface $metadataFactory; - /** - * @var string - */ private string $namespace; public function __construct(MetadataFactoryInterface $metadataFactory) @@ -38,9 +32,6 @@ public function __construct(MetadataFactoryInterface $metadataFactory) $this->metadataFactory = $metadataFactory; } - /** - * {@inheritdoc} - */ public function beforeTraverse(array $nodes): ?Node { $this->namespace = ''; @@ -48,9 +39,6 @@ public function beforeTraverse(array $nodes): ?Node return null; } - /** - * {@inheritdoc} - */ public function enterNode(Node $node): ?Node { if ($node instanceof Node\Stmt\Namespace_) { @@ -117,17 +105,11 @@ private function extractFromConstraints(array $constraints): void } } - /** - * {@inheritdoc} - */ public function leaveNode(Node $node): ?Node { return null; } - /** - * {@inheritdoc} - */ public function afterTraverse(array $nodes): ?Node { return null; diff --git a/src/Visitor/Php/TranslateAnnotationVisitor.php b/src/Visitor/Php/TranslateAnnotationVisitor.php index abd2fbe..e9e2af3 100644 --- a/src/Visitor/Php/TranslateAnnotationVisitor.php +++ b/src/Visitor/Php/TranslateAnnotationVisitor.php @@ -40,9 +40,6 @@ private function getTranslateDocParser(): DocParser return $this->translateDocParser; } - /** - * {@inheritdoc} - */ public function enterNode(Node $node): ?Node { // look for strings @@ -50,7 +47,7 @@ public function enterNode(Node $node): ?Node return null; } - //look for string with comment + // look for string with comment $comments = $node->getAttribute('comments', []); if (!\count($comments)) { return null; @@ -62,7 +59,7 @@ public function enterNode(Node $node): ?Node } foreach ($this->getTranslateDocParser()->parse($comment->getText()) as $annotation) { - //add phrase to dictionary + // add phrase to dictionary $this->addLocation($node->value, $node->getAttribute('startLine'), $node, ['domain' => $annotation->getDomain()]); break; @@ -72,25 +69,16 @@ public function enterNode(Node $node): ?Node return null; } - /** - * {@inheritdoc} - */ public function leaveNode(Node $node): ?Node { return null; } - /** - * {@inheritdoc} - */ public function beforeTraverse(array $nodes): ?Node { return null; } - /** - * {@inheritdoc} - */ public function afterTraverse(array $nodes): ?Node { return null; diff --git a/src/Visitor/Twig/TwigVisitor.php b/src/Visitor/Twig/TwigVisitor.php index c96bb4e..3a1d5f4 100644 --- a/src/Visitor/Twig/TwigVisitor.php +++ b/src/Visitor/Twig/TwigVisitor.php @@ -23,7 +23,7 @@ final class TwigVisitor extends BaseVisitor implements NodeVisitorInterface { private ?Worker $worker; - public function __construct(Worker $worker = null) + public function __construct(?Worker $worker = null) { if (null === $worker) { $worker = new Worker(); @@ -32,9 +32,6 @@ public function __construct(Worker $worker = null) $this->worker = $worker; } - /** - * {@inheritdoc} - */ public function enterNode(Node $node, Environment $env): Node { // If not initialized @@ -48,17 +45,11 @@ public function enterNode(Node $node, Environment $env): Node }); } - /** - * {@inheritdoc} - */ public function leaveNode(Node $node, Environment $env): ?Node { return $node; } - /** - * {@inheritdoc} - */ public function getPriority(): int { return 0; diff --git a/tests/Functional/Visitor/Php/Symfony/FormTypeChoicesTest.php b/tests/Functional/Visitor/Php/Symfony/FormTypeChoicesTest.php index 768c924..cdaaeb5 100644 --- a/tests/Functional/Visitor/Php/Symfony/FormTypeChoicesTest.php +++ b/tests/Functional/Visitor/Php/Symfony/FormTypeChoicesTest.php @@ -12,7 +12,6 @@ namespace Translation\Extractor\Tests\Resources\Php\Symfony; use Translation\Extractor\Tests\Functional\Visitor\Php\BasePHPVisitorTest; -use Translation\Extractor\Tests\Resources; use Translation\Extractor\Visitor\Php\Symfony\FormTypeChoices; /** @@ -22,7 +21,7 @@ class FormTypeChoicesTest extends BasePHPVisitorTest { public function testSimpleSymfony3x() { - $collection = $this->getSourceLocations(new FormTypeChoices(), Resources\Php\Symfony\SimpleChoiceSymfony3xType::class); + $collection = $this->getSourceLocations(new FormTypeChoices(), SimpleChoiceSymfony3xType::class); $this->assertCount(1, $collection, print_r($collection, true)); $this->assertEquals('label1', $collection->get(0)->getMessage()); @@ -33,7 +32,7 @@ public function testSimpleSymfony27() { $visitor = new FormTypeChoices(); $visitor->setSymfonyMajorVersion(2); - $collection = $this->getSourceLocations($visitor, Resources\Php\Symfony\SimpleChoiceSymfony27Type::class); + $collection = $this->getSourceLocations($visitor, SimpleChoiceSymfony27Type::class); $this->assertCount(4, $collection, print_r($collection, true)); $this->assertEquals('label1', $collection->get(0)->getMessage()); @@ -47,7 +46,7 @@ public function testChainedChoice() { $visitor = new FormTypeChoices(); $visitor->setSymfonyMajorVersion(3); - $collection = $this->getSourceLocations($visitor, Resources\Php\Symfony\ChainedChoiceType::class); + $collection = $this->getSourceLocations($visitor, ChainedChoiceType::class); $this->assertCount(2, $collection, print_r($collection, true)); $this->assertEquals('label1', $collection->get(0)->getMessage()); @@ -56,7 +55,7 @@ public function testChainedChoice() public function testExtractError() { - $collection = $this->getSourceLocations(new FormTypeChoices(), Resources\Php\Symfony\SimpleChoiceSymfony3xErrorType::class); + $collection = $this->getSourceLocations(new FormTypeChoices(), SimpleChoiceSymfony3xErrorType::class); $errors = $collection->getErrors(); $this->assertCount(1, $errors); @@ -64,7 +63,7 @@ public function testExtractError() public function testPassedChoices() { - $collection = $this->getSourceLocations(new FormTypeChoices(), Resources\Php\Symfony\SimpleChoicePassArrayType::class); + $collection = $this->getSourceLocations(new FormTypeChoices(), SimpleChoicePassArrayType::class); $this->assertCount(1, $collection, print_r($collection, true)); $this->assertEquals('label1', $collection->get(0)->getMessage()); @@ -73,7 +72,7 @@ public function testPassedChoices() public function testChoiceTranslationDomain() { - $collection = $this->getSourceLocations(new FormTypeChoices(), Resources\Php\Symfony\FormDomainChoiceType::class); + $collection = $this->getSourceLocations(new FormTypeChoices(), FormDomainChoiceType::class); $messageA = $collection->get(0); $this->assertEquals('label1_a', $messageA->getMessage()); diff --git a/tests/Functional/Visitor/Php/Symfony/FormTypeLabelImplicitTest.php b/tests/Functional/Visitor/Php/Symfony/FormTypeLabelImplicitTest.php index b39732c..c1afda0 100644 --- a/tests/Functional/Visitor/Php/Symfony/FormTypeLabelImplicitTest.php +++ b/tests/Functional/Visitor/Php/Symfony/FormTypeLabelImplicitTest.php @@ -12,7 +12,6 @@ namespace Translation\Extractor\Tests\Resources\Php\Symfony; use Translation\Extractor\Tests\Functional\Visitor\Php\BasePHPVisitorTest; -use Translation\Extractor\Tests\Resources; use Translation\Extractor\Visitor\Php\Symfony\FormTypeLabelImplicit; /** @@ -22,14 +21,14 @@ class FormTypeLabelImplicitTest extends BasePHPVisitorTest { public function testExtract() { - $collection = $this->getSourceLocations(new FormTypeLabelImplicit(), Resources\Php\Symfony\ImplicitLabelType::class); + $collection = $this->getSourceLocations(new FormTypeLabelImplicit(), ImplicitLabelType::class); $this->assertCount(5, $collection, print_r($collection, true)); $this->assertEquals('Find1', $collection->get(0)->getMessage()); $this->assertEquals('Bigger find2', $collection->get(1)->getMessage()); $this->assertEquals('Camel find3', $collection->get(2)->getMessage()); - //issue87: support for Ignore annotation + // issue87: support for Ignore annotation $this->assertEquals('Issue87-will be added', $collection->get(3)->getMessage()); } } diff --git a/tests/Smoke/AllExtractorsTest.php b/tests/Smoke/AllExtractorsTest.php index 452fb76..b9237eb 100644 --- a/tests/Smoke/AllExtractorsTest.php +++ b/tests/Smoke/AllExtractorsTest.php @@ -100,7 +100,7 @@ public function testNoException() /** * Assert that a translation key exists in source collection. */ - private function translationExists(SourceCollection $sc, string $translationKey, string $message = null): SourceLocation + private function translationExists(SourceCollection $sc, string $translationKey, ?string $message = null): SourceLocation { if (empty($message)) { $message = sprintf('Tried to find "%s" but failed', $translationKey); @@ -124,7 +124,7 @@ private function translationExists(SourceCollection $sc, string $translationKey, /** * Assert that a translation key is missing in source collection. */ - private function translationMissing(SourceCollection $sc, string $translationKey, string $message = null) + private function translationMissing(SourceCollection $sc, string $translationKey, ?string $message = null): void { if (empty($message)) { $message = sprintf('The translation key "%s" should not exist', $translationKey); From 0a593c07be7ffaedd6aa985b68e8feaa13f9c0b1 Mon Sep 17 00:00:00 2001 From: antiftw Date: Sat, 8 Jun 2024 19:57:33 +0200 Subject: [PATCH 12/19] fixed last phpstan test? --- src/Visitor/Php/Symfony/AbstractFormType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Visitor/Php/Symfony/AbstractFormType.php b/src/Visitor/Php/Symfony/AbstractFormType.php index c0b8409..8b0ff25 100644 --- a/src/Visitor/Php/Symfony/AbstractFormType.php +++ b/src/Visitor/Php/Symfony/AbstractFormType.php @@ -88,7 +88,7 @@ private function parseDefaultsCall(Node $node): void return; } - if (!isset($node->args) || false === \is_array($node->args) || 0 === \count($node->args)) { + if (null === $node->args || false === \is_array($node->args) || 0 === \count($node->args)) { return; } From 17934defdd6dcb89da203c7053b95aa5813a2b9c Mon Sep 17 00:00:00 2001 From: antiftw Date: Sun, 9 Jun 2024 13:30:59 +0200 Subject: [PATCH 13/19] weird issue --- composer.json | 2 +- src/FileExtractor/PHPFileExtractor.php | 3 ++- src/Visitor/Php/Symfony/FormTypeChoices.php | 1 + tests/Functional/Visitor/Php/Symfony/FormTypeLabelTest.php | 6 +++--- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 871a199..1cce7fb 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ ], "require": { "php": "^8.1", - "nikic/php-parser": "^3.0 || ^4.0", + "nikic/php-parser": "^3.0 || ^4.0 || ^5.0", "symfony/finder": "^5.4 || ^6.4 || ^7.0", "twig/twig": "^2.0 || ^3.0", "doctrine/annotations": "^1.7 || ^2.0" diff --git a/src/FileExtractor/PHPFileExtractor.php b/src/FileExtractor/PHPFileExtractor.php index 7c263e6..ae58780 100644 --- a/src/FileExtractor/PHPFileExtractor.php +++ b/src/FileExtractor/PHPFileExtractor.php @@ -15,6 +15,7 @@ use PhpParser\NodeTraverser; use PhpParser\NodeVisitor; use PhpParser\ParserFactory; +use PhpParser\PhpVersion; use Symfony\Component\Finder\SplFileInfo; use Translation\Extractor\Model\SourceCollection; use Translation\Extractor\Visitor\Visitor; @@ -32,7 +33,7 @@ final class PHPFileExtractor implements FileExtractor public function getSourceLocations(SplFileInfo $file, SourceCollection $collection): void { $path = $file->getRelativePath(); - $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7); + $parser = (new ParserFactory())->createForVersion(PhpVersion::fromString('8.1')); $traverser = new NodeTraverser(); foreach ($this->visitors as $v) { $v->init($collection, $file); diff --git a/src/Visitor/Php/Symfony/FormTypeChoices.php b/src/Visitor/Php/Symfony/FormTypeChoices.php index 6fb3e83..92a9ca9 100644 --- a/src/Visitor/Php/Symfony/FormTypeChoices.php +++ b/src/Visitor/Php/Symfony/FormTypeChoices.php @@ -134,6 +134,7 @@ public function enterNode(Node $node): ?Node protected function isIgnored(Node $node): bool { + var_dump($node); // because of getDocParser method is private, we have to create a new custom instance $docParser = new DocParser(); $docParser->setImports([ diff --git a/tests/Functional/Visitor/Php/Symfony/FormTypeLabelTest.php b/tests/Functional/Visitor/Php/Symfony/FormTypeLabelTest.php index 2f4db88..66f2f52 100644 --- a/tests/Functional/Visitor/Php/Symfony/FormTypeLabelTest.php +++ b/tests/Functional/Visitor/Php/Symfony/FormTypeLabelTest.php @@ -50,15 +50,15 @@ public function testTranslationDomain() // We should not have "test_d" or "test_e" $this->assertEquals(3, $collection->count(), 'We should ignore choices where "translation_domain" is "false"'); - $messageA = $collection->get(0); + $messageA = $collection->get(2); $this->assertEquals('label1', $messageA->getMessage()); $this->assertEquals('admin0', $messageA->getContext()['domain']); - $messageB = $collection->get(1); + $messageB = $collection->get(0); $this->assertEquals('Test b', $messageB->getMessage()); $this->assertEquals('admin1', $messageB->getContext()['domain']); - $messageC = $collection->get(2); + $messageC = $collection->get(1); $this->assertEquals('Test c', $messageC->getMessage()); $this->assertNull($messageC->getContext()['domain']); } From 7cc1b2aaa23b0e1b88b357ba1d55392348c55994 Mon Sep 17 00:00:00 2001 From: antiftw Date: Sun, 9 Jun 2024 14:02:16 +0200 Subject: [PATCH 14/19] fixed errors that originated in bumping nikic/php-parser to 5.0 --- src/Visitor/Php/Symfony/FormTypeChoices.php | 3 +-- src/Visitor/Php/Symfony/FormTypeLabelImplicit.php | 6 +++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Visitor/Php/Symfony/FormTypeChoices.php b/src/Visitor/Php/Symfony/FormTypeChoices.php index 92a9ca9..2e92f73 100644 --- a/src/Visitor/Php/Symfony/FormTypeChoices.php +++ b/src/Visitor/Php/Symfony/FormTypeChoices.php @@ -96,7 +96,7 @@ public function enterNode(Node $node): ?Node } // do not parse choices if the @Ignore annotation is attached - if ($this->isIgnored($item->key)) { + if ($this->isIgnored($item)) { continue; } @@ -134,7 +134,6 @@ public function enterNode(Node $node): ?Node protected function isIgnored(Node $node): bool { - var_dump($node); // because of getDocParser method is private, we have to create a new custom instance $docParser = new DocParser(); $docParser->setImports([ diff --git a/src/Visitor/Php/Symfony/FormTypeLabelImplicit.php b/src/Visitor/Php/Symfony/FormTypeLabelImplicit.php index d55d1fe..72f78bb 100644 --- a/src/Visitor/Php/Symfony/FormTypeLabelImplicit.php +++ b/src/Visitor/Php/Symfony/FormTypeLabelImplicit.php @@ -79,7 +79,11 @@ public function enterNode(Node $node): ?Node $node->setDocComment($node->args[0]->getDocComment()); } - $label = $node->args[0]->value->value; + $label = ''; + if ($node->args[0]->value instanceof Node\Scalar\String_) { + $label = null == $node->args[0]->value->value ? '' : $node->args[0]->value->value; + } + if (!empty($label)) { $label = $this->humanize($label); if (null !== $location = $this->getLocation($label, $node->getAttribute('startLine'), $node, ['domain' => $domain])) { From 16455ae26bd1a8b2c9cccbc07953b540f1cc6ce3 Mon Sep 17 00:00:00 2001 From: antiftw Date: Sun, 9 Jun 2024 18:28:38 +0200 Subject: [PATCH 15/19] removed support for 3.0 nikic/php-parser --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1cce7fb..450d004 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ ], "require": { "php": "^8.1", - "nikic/php-parser": "^3.0 || ^4.0 || ^5.0", + "nikic/php-parser": "^4.0 || ^5.0", "symfony/finder": "^5.4 || ^6.4 || ^7.0", "twig/twig": "^2.0 || ^3.0", "doctrine/annotations": "^1.7 || ^2.0" From dfd83eddf19cd1c658bb4b66f733a56180f45b6d Mon Sep 17 00:00:00 2001 From: antiftw Date: Tue, 11 Jun 2024 20:10:29 +0200 Subject: [PATCH 16/19] removed superfluous test --- .../Visitor/Php/Symfony/ValidationAnnotationTest.php | 9 --------- .../Resources/Php/Symfony/ValidatorAnnotationError.php | 10 ---------- 2 files changed, 19 deletions(-) delete mode 100644 tests/Resources/Php/Symfony/ValidatorAnnotationError.php diff --git a/tests/Functional/Visitor/Php/Symfony/ValidationAnnotationTest.php b/tests/Functional/Visitor/Php/Symfony/ValidationAnnotationTest.php index 72ffb2f..3a4e770 100644 --- a/tests/Functional/Visitor/Php/Symfony/ValidationAnnotationTest.php +++ b/tests/Functional/Visitor/Php/Symfony/ValidationAnnotationTest.php @@ -37,13 +37,4 @@ public function testExtractAnnotation() $this->assertEquals('end.blank', $source->getMessage()); $this->assertEquals('validators', $source->getContext()['domain']); } - - public function testExtractAnnotationError() - { - $factory = new LazyLoadingMetadataFactory(new AttributeLoader()); - $extractor = new ValidationAnnotation($factory); - $collection = $this->getSourceLocations($extractor, Resources\Php\Symfony\ValidatorAnnotationError::class); - - $this->assertCount(0, $collection); - } } diff --git a/tests/Resources/Php/Symfony/ValidatorAnnotationError.php b/tests/Resources/Php/Symfony/ValidatorAnnotationError.php deleted file mode 100644 index 9ddbb7c..0000000 --- a/tests/Resources/Php/Symfony/ValidatorAnnotationError.php +++ /dev/null @@ -1,10 +0,0 @@ - Date: Fri, 14 Jun 2024 11:32:18 +0200 Subject: [PATCH 17/19] removed a superfluous try catch, since no more exception is thrown --- src/Visitor/Php/Symfony/ValidationAnnotation.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Visitor/Php/Symfony/ValidationAnnotation.php b/src/Visitor/Php/Symfony/ValidationAnnotation.php index 05c86f8..052cdc7 100644 --- a/src/Visitor/Php/Symfony/ValidationAnnotation.php +++ b/src/Visitor/Php/Symfony/ValidationAnnotation.php @@ -11,7 +11,6 @@ namespace Translation\Extractor\Visitor\Php\Symfony; -use Doctrine\Common\Annotations\AnnotationException; use PhpParser\Node; use PhpParser\NodeVisitor; use Symfony\Component\Validator\Mapping\ClassMetadata; @@ -60,14 +59,8 @@ public function enterNode(Node $node): ?Node return null; } - try { - /** @var ClassMetadata $metadata */ - $metadata = $this->metadataFactory->getMetadataFor($name); - } catch (AnnotationException $e) { - $this->addError($node, sprintf('Could not parse class "%s" for annotations. %s', $this->namespace, $e->getMessage())); - - return null; - } + /** @var ClassMetadata $metadata */ + $metadata = $this->metadataFactory->getMetadataFor($name); if (!$metadata->hasConstraints() && !\count($metadata->getConstrainedProperties())) { return null; From d6918d522b5d6224a36e511ce27d5222794b9367 Mon Sep 17 00:00:00 2001 From: antiftw Date: Fri, 14 Jun 2024 11:52:29 +0200 Subject: [PATCH 18/19] other exception can be thrown apparently --- src/Visitor/Php/Symfony/ValidationAnnotation.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Visitor/Php/Symfony/ValidationAnnotation.php b/src/Visitor/Php/Symfony/ValidationAnnotation.php index 052cdc7..e709482 100644 --- a/src/Visitor/Php/Symfony/ValidationAnnotation.php +++ b/src/Visitor/Php/Symfony/ValidationAnnotation.php @@ -59,8 +59,14 @@ public function enterNode(Node $node): ?Node return null; } - /** @var ClassMetadata $metadata */ - $metadata = $this->metadataFactory->getMetadataFor($name); + try { + /** @var ClassMetadata $metadata */ + $metadata = $this->metadataFactory->getMetadataFor($name); + } catch (\Throwable $e) { + $this->addError($node, sprintf('Could not parse class "%s" for annotations. %s', $this->namespace, $e->getMessage())); + + return null; + } if (!$metadata->hasConstraints() && !\count($metadata->getConstrainedProperties())) { return null; From 9cbd99c6796e4afd97deab29b03b531970a15d39 Mon Sep 17 00:00:00 2001 From: antiftw Date: Fri, 14 Jun 2024 11:55:11 +0200 Subject: [PATCH 19/19] more specific exception catch --- src/Visitor/Php/Symfony/ValidationAnnotation.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Visitor/Php/Symfony/ValidationAnnotation.php b/src/Visitor/Php/Symfony/ValidationAnnotation.php index e709482..d4181dd 100644 --- a/src/Visitor/Php/Symfony/ValidationAnnotation.php +++ b/src/Visitor/Php/Symfony/ValidationAnnotation.php @@ -13,6 +13,7 @@ use PhpParser\Node; use PhpParser\NodeVisitor; +use Symfony\Component\Validator\Exception\NoSuchMetadataException; use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface; use Translation\Extractor\Visitor\Php\BasePHPVisitor; @@ -62,7 +63,7 @@ public function enterNode(Node $node): ?Node try { /** @var ClassMetadata $metadata */ $metadata = $this->metadataFactory->getMetadataFor($name); - } catch (\Throwable $e) { + } catch (NoSuchMetadataException $e) { $this->addError($node, sprintf('Could not parse class "%s" for annotations. %s', $this->namespace, $e->getMessage())); return null;