vendor/shopware/core/Framework/Compatibility/DocParser.php line 749

Open in your IDE?
  1. <?php
  2. namespace Shopware\Core\Framework\Compatibility;
  3. use Shopware\Core\Framework\Log\Package;
  4. use Doctrine\Common\Annotations\Annotation\Attribute;
  5. use Doctrine\Common\Annotations\Annotation\Attributes;
  6. use Doctrine\Common\Annotations\Annotation\Enum;
  7. use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
  8. use Doctrine\Common\Annotations\Annotation\Target;
  9. use Doctrine\Common\Annotations\AnnotationException;
  10. use Doctrine\Common\Annotations\AnnotationRegistry;
  11. use Doctrine\Common\Annotations\DocLexer;
  12. use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;
  13. use ReflectionClass;
  14. use ReflectionException;
  15. use ReflectionProperty;
  16. use RuntimeException;
  17. use stdClass;
  18. use Doctrine\Common\Annotations\Annotation as Annotation;
  19. use function array_keys;
  20. use function array_map;
  21. use function array_pop;
  22. use function array_values;
  23. use function class_exists;
  24. use function constant;
  25. use function count;
  26. use function defined;
  27. use function explode;
  28. use function gettype;
  29. use function implode;
  30. use function in_array;
  31. use function interface_exists;
  32. use function is_array;
  33. use function is_object;
  34. use function json_encode;
  35. use function ltrim;
  36. use function preg_match;
  37. use function reset;
  38. use function rtrim;
  39. use function sprintf;
  40. use function stripos;
  41. use function strlen;
  42. use function strpos;
  43. use function strrpos;
  44. use function strtolower;
  45. use function substr;
  46. use function trim;
  47. use const PHP_VERSION_ID;
  48. /**
  49.  * @package core
  50.  * @deprecated tag:v6.5.0 - Remove compatibility bridge to make parameters case insensitive
  51.  * @see https://github.com/doctrine/annotations/issues/421
  52.  */
  53. #[Package('core')]
  54. class DocParser
  55. {
  56.     /**
  57.      * An array of all valid tokens for a class name.
  58.      *
  59.      * @phpstan-var list<int>
  60.      */
  61.     private static $classIdentifiers = [
  62.         DocLexer::T_IDENTIFIER,
  63.         DocLexer::T_TRUE,
  64.         DocLexer::T_FALSE,
  65.         DocLexer::T_NULL,
  66.     ];
  67.     /**
  68.      * The lexer.
  69.      *
  70.      * @var DocLexer
  71.      */
  72.     private $lexer;
  73.     /**
  74.      * Current target context.
  75.      *
  76.      * @var int
  77.      */
  78.     private $target;
  79.     /**
  80.      * Doc parser used to collect annotation target.
  81.      *
  82.      * @var \Doctrine\Common\Annotations\DocParser
  83.      */
  84.     private static $metadataParser;
  85.     /**
  86.      * Flag to control if the current annotation is nested or not.
  87.      *
  88.      * @var bool
  89.      */
  90.     private $isNestedAnnotation false;
  91.     /**
  92.      * Hashmap containing all use-statements that are to be used when parsing
  93.      * the given doc block.
  94.      *
  95.      * @var array<string, class-string>
  96.      */
  97.     private $imports = [];
  98.     /**
  99.      * This hashmap is used internally to cache results of class_exists()
  100.      * look-ups.
  101.      *
  102.      * @var array<class-string, bool>
  103.      */
  104.     private $classExists = [];
  105.     /**
  106.      * Whether annotations that have not been imported should be ignored.
  107.      *
  108.      * @var bool
  109.      */
  110.     private $ignoreNotImportedAnnotations false;
  111.     /**
  112.      * An array of default namespaces if operating in simple mode.
  113.      *
  114.      * @var array<string>
  115.      */
  116.     private $namespaces = [];
  117.     /**
  118.      * A list with annotations that are not causing exceptions when not resolved to an annotation class.
  119.      *
  120.      * The names must be the raw names as used in the class, not the fully qualified
  121.      *
  122.      * @var bool[] indexed by annotation name
  123.      */
  124.     private $ignoredAnnotationNames = [];
  125.     /**
  126.      * A list with annotations in namespaced format
  127.      * that are not causing exceptions when not resolved to an annotation class.
  128.      *
  129.      * @var bool[] indexed by namespace name
  130.      */
  131.     private $ignoredAnnotationNamespaces = [];
  132.     /** @var string */
  133.     private $context '';
  134.     /**
  135.      * Hash-map for caching annotation metadata.
  136.      *
  137.      * @var array<class-string, mixed[]>
  138.      */
  139.     private static $annotationMetadata = [
  140.         Target::class => [
  141.             'is_annotation'                  => true,
  142.             'has_constructor'                => true,
  143.             'has_named_argument_constructor' => false,
  144.             'properties'                     => [],
  145.             'targets_literal'                => 'ANNOTATION_CLASS',
  146.             'targets'                        => Target::TARGET_CLASS,
  147.             'default_property'               => 'value',
  148.             'attribute_types'                => [
  149.                 'value'  => [
  150.                     'required'   => false,
  151.                     'type'       => 'array',
  152.                     'array_type' => 'string',
  153.                     'value'      => 'array<string>',
  154.                 ],
  155.             ],
  156.         ],
  157.         Attribute::class => [
  158.             'is_annotation'                  => true,
  159.             'has_constructor'                => false,
  160.             'has_named_argument_constructor' => false,
  161.             'targets_literal'                => 'ANNOTATION_ANNOTATION',
  162.             'targets'                        => Target::TARGET_ANNOTATION,
  163.             'default_property'               => 'name',
  164.             'properties'                     => [
  165.                 'name'      => 'name',
  166.                 'type'      => 'type',
  167.                 'required'  => 'required',
  168.             ],
  169.             'attribute_types'                => [
  170.                 'value'  => [
  171.                     'required'  => true,
  172.                     'type'      => 'string',
  173.                     'value'     => 'string',
  174.                 ],
  175.                 'type'  => [
  176.                     'required'  => true,
  177.                     'type'      => 'string',
  178.                     'value'     => 'string',
  179.                 ],
  180.                 'required'  => [
  181.                     'required'  => false,
  182.                     'type'      => 'boolean',
  183.                     'value'     => 'boolean',
  184.                 ],
  185.             ],
  186.         ],
  187.         Attributes::class => [
  188.             'is_annotation'                  => true,
  189.             'has_constructor'                => false,
  190.             'has_named_argument_constructor' => false,
  191.             'targets_literal'                => 'ANNOTATION_CLASS',
  192.             'targets'                        => Target::TARGET_CLASS,
  193.             'default_property'               => 'value',
  194.             'properties'                     => ['value' => 'value'],
  195.             'attribute_types'                => [
  196.                 'value' => [
  197.                     'type'      => 'array',
  198.                     'required'  => true,
  199.                     'array_type' => Attribute::class,
  200.                     'value'     => 'array<' Attribute::class . '>',
  201.                 ],
  202.             ],
  203.         ],
  204.         Enum::class => [
  205.             'is_annotation'                  => true,
  206.             'has_constructor'                => true,
  207.             'has_named_argument_constructor' => false,
  208.             'targets_literal'                => 'ANNOTATION_PROPERTY',
  209.             'targets'                        => Target::TARGET_PROPERTY,
  210.             'default_property'               => 'value',
  211.             'properties'                     => ['value' => 'value'],
  212.             'attribute_types'                => [
  213.                 'value' => [
  214.                     'type'      => 'array',
  215.                     'required'  => true,
  216.                 ],
  217.                 'literal' => [
  218.                     'type'      => 'array',
  219.                     'required'  => false,
  220.                 ],
  221.             ],
  222.         ],
  223.         NamedArgumentConstructor::class => [
  224.             'is_annotation'                  => true,
  225.             'has_constructor'                => false,
  226.             'has_named_argument_constructor' => false,
  227.             'targets_literal'                => 'ANNOTATION_CLASS',
  228.             'targets'                        => Target::TARGET_CLASS,
  229.             'default_property'               => null,
  230.             'properties'                     => [],
  231.             'attribute_types'                => [],
  232.         ],
  233.     ];
  234.     /**
  235.      * Hash-map for handle types declaration.
  236.      *
  237.      * @var array<string, string>
  238.      */
  239.     private static $typeMap = [
  240.         'float'     => 'double',
  241.         'bool'      => 'boolean',
  242.         // allow uppercase Boolean in honor of George Boole
  243.         'Boolean'   => 'boolean',
  244.         'int'       => 'integer',
  245.     ];
  246.     /**
  247.      * Constructs a new DocParser.
  248.      */
  249.     public function __construct()
  250.     {
  251.         $this->lexer = new DocLexer();
  252.     }
  253.     /**
  254.      * Sets the annotation names that are ignored during the parsing process.
  255.      *
  256.      * The names are supposed to be the raw names as used in the class, not the
  257.      * fully qualified class names.
  258.      *
  259.      * @param bool[] $names indexed by annotation name
  260.      *
  261.      * @return void
  262.      */
  263.     public function setIgnoredAnnotationNames(array $names)
  264.     {
  265.         $this->ignoredAnnotationNames $names;
  266.     }
  267.     /**
  268.      * Sets the annotation namespaces that are ignored during the parsing process.
  269.      *
  270.      * @param bool[] $ignoredAnnotationNamespaces indexed by annotation namespace name
  271.      *
  272.      * @return void
  273.      */
  274.     public function setIgnoredAnnotationNamespaces($ignoredAnnotationNamespaces)
  275.     {
  276.         $this->ignoredAnnotationNamespaces $ignoredAnnotationNamespaces;
  277.     }
  278.     /**
  279.      * Sets ignore on not-imported annotations.
  280.      *
  281.      * @param bool $bool
  282.      *
  283.      * @return void
  284.      */
  285.     public function setIgnoreNotImportedAnnotations($bool)
  286.     {
  287.         $this->ignoreNotImportedAnnotations = (bool) $bool;
  288.     }
  289.     /**
  290.      * Sets the default namespaces.
  291.      *
  292.      * @param string $namespace
  293.      *
  294.      * @return void
  295.      *
  296.      * @throws RuntimeException
  297.      */
  298.     public function addNamespace($namespace)
  299.     {
  300.         if ($this->imports) {
  301.             throw new RuntimeException('You must either use addNamespace(), or setImports(), but not both.');
  302.         }
  303.         $this->namespaces[] = $namespace;
  304.     }
  305.     /**
  306.      * Sets the imports.
  307.      *
  308.      * @param array<string, class-string> $imports
  309.      *
  310.      * @return void
  311.      *
  312.      * @throws RuntimeException
  313.      */
  314.     public function setImports(array $imports)
  315.     {
  316.         if ($this->namespaces) {
  317.             throw new RuntimeException('You must either use addNamespace(), or setImports(), but not both.');
  318.         }
  319.         $this->imports $imports;
  320.     }
  321.     /**
  322.      * Sets current target context as bitmask.
  323.      *
  324.      * @param int $target
  325.      *
  326.      * @return void
  327.      */
  328.     public function setTarget($target)
  329.     {
  330.         $this->target $target;
  331.     }
  332.     /**
  333.      * Parses the given docblock string for annotations.
  334.      *
  335.      * @param string $input   The docblock string to parse.
  336.      * @param string $context The parsing context.
  337.      *
  338.      * @throws AnnotationException
  339.      * @throws ReflectionException
  340.      *
  341.      * @phpstan-return list<object> Array of annotations. If no annotations are found, an empty array is returned.
  342.      */
  343.     public function parse($input$context '')
  344.     {
  345.         $pos $this->findInitialTokenPosition($input);
  346.         if ($pos === null) {
  347.             return [];
  348.         }
  349.         $this->context $context;
  350.         $this->lexer->setInput(trim(substr($input$pos), '* /'));
  351.         $this->lexer->moveNext();
  352.         return $this->Annotations();
  353.     }
  354.     /**
  355.      * Finds the first valid annotation
  356.      *
  357.      * @param string $input The docblock string to parse
  358.      */
  359.     private function findInitialTokenPosition($input): ?int
  360.     {
  361.         $pos 0;
  362.         // search for first valid annotation
  363.         while (($pos strpos($input'@'$pos)) !== false) {
  364.             $preceding substr($input$pos 11);
  365.             // if the @ is preceded by a space, a tab or * it is valid
  366.             if ($pos === || $preceding === ' ' || $preceding === '*' || $preceding === "\t") {
  367.                 return $pos;
  368.             }
  369.             $pos++;
  370.         }
  371.         return null;
  372.     }
  373.     /**
  374.      * Attempts to match the given token with the current lookahead token.
  375.      * If they match, updates the lookahead token; otherwise raises a syntax error.
  376.      *
  377.      * @param int $token Type of token.
  378.      *
  379.      * @return bool True if tokens match; false otherwise.
  380.      *
  381.      * @throws AnnotationException
  382.      */
  383.     private function match(int $token): bool
  384.     {
  385.         if (! $this->lexer->isNextToken($token)) {
  386.             throw $this->syntaxError($this->lexer->getLiteral($token));
  387.         }
  388.         return $this->lexer->moveNext();
  389.     }
  390.     /**
  391.      * Attempts to match the current lookahead token with any of the given tokens.
  392.      *
  393.      * If any of them matches, this method updates the lookahead token; otherwise
  394.      * a syntax error is raised.
  395.      *
  396.      * @throws AnnotationException
  397.      *
  398.      * @phpstan-param list<mixed[]> $tokens
  399.      */
  400.     private function matchAny(array $tokens): bool
  401.     {
  402.         if (! $this->lexer->isNextTokenAny($tokens)) {
  403.             throw $this->syntaxError(implode(' or 'array_map([$this->lexer'getLiteral'], $tokens)));
  404.         }
  405.         return $this->lexer->moveNext();
  406.     }
  407.     /**
  408.      * Generates a new syntax error.
  409.      *
  410.      * @param string       $expected Expected string.
  411.      * @param mixed[]|null $token    Optional token.
  412.      */
  413.     private function syntaxError(string $expected, ?array $token null): AnnotationException
  414.     {
  415.         if ($token === null) {
  416.             $token $this->lexer->lookahead;
  417.         }
  418.         $message  sprintf('Expected %s, got '$expected);
  419.         $message .= $this->lexer->lookahead === null
  420.             'end of string'
  421.             sprintf("'%s' at position %s"$token['value'], $token['position']);
  422.         if (strlen($this->context)) {
  423.             $message .= ' in ' $this->context;
  424.         }
  425.         $message .= '.';
  426.         return AnnotationException::syntaxError($message);
  427.     }
  428.     /**
  429.      * Attempts to check if a class exists or not. This never goes through the PHP autoloading mechanism
  430.      * but uses the {@link AnnotationRegistry} to load classes.
  431.      *
  432.      * @param class-string $fqcn
  433.      */
  434.     private function classExists(string $fqcn): bool
  435.     {
  436.         if (isset($this->classExists[$fqcn])) {
  437.             return $this->classExists[$fqcn];
  438.         }
  439.         // first check if the class already exists, maybe loaded through another AnnotationReader
  440.         if (class_exists($fqcnfalse)) {
  441.             return $this->classExists[$fqcn] = true;
  442.         }
  443.         // final check, does this class exist?
  444.         return $this->classExists[$fqcn] = AnnotationRegistry::loadAnnotationClass($fqcn);
  445.     }
  446.     /**
  447.      * Collects parsing metadata for a given annotation class
  448.      *
  449.      * @param class-string $name The annotation name
  450.      *
  451.      * @throws AnnotationException
  452.      * @throws ReflectionException
  453.      */
  454.     private function collectAnnotationMetadata(string $name): void
  455.     {
  456.         if (self::$metadataParser === null) {
  457.             self::$metadataParser = new self();
  458.             self::$metadataParser->setIgnoreNotImportedAnnotations(true);
  459.             self::$metadataParser->setIgnoredAnnotationNames($this->ignoredAnnotationNames);
  460.             self::$metadataParser->setImports([
  461.                 'enum'                     => Enum::class,
  462.                 'target'                   => Target::class,
  463.                 'attribute'                => Attribute::class,
  464.                 'attributes'               => Attributes::class,
  465.                 'namedargumentconstructor' => NamedArgumentConstructor::class,
  466.             ]);
  467.             // Make sure that annotations from metadata are loaded
  468.             class_exists(Enum::class);
  469.             class_exists(Target::class);
  470.             class_exists(Attribute::class);
  471.             class_exists(Attributes::class);
  472.             class_exists(NamedArgumentConstructor::class);
  473.         }
  474.         $class      = new ReflectionClass($name);
  475.         $docComment $class->getDocComment();
  476.         // Sets default values for annotation metadata
  477.         $constructor $class->getConstructor();
  478.         $metadata    = [
  479.             'default_property' => null,
  480.             'has_constructor'  => $constructor !== null && $constructor->getNumberOfParameters() > 0,
  481.             'constructor_args' => [],
  482.             'properties'       => [],
  483.             'property_types'   => [],
  484.             'attribute_types'  => [],
  485.             'targets_literal'  => null,
  486.             'targets'          => Target::TARGET_ALL,
  487.             'is_annotation'    => strpos($docComment'@Annotation') !== false,
  488.         ];
  489.         $metadata['has_named_argument_constructor'] = $metadata['has_constructor']
  490.             && $class->implementsInterface(NamedArgumentConstructorAnnotation::class);
  491.         // verify that the class is really meant to be an annotation
  492.         if ($metadata['is_annotation']) {
  493.             self::$metadataParser->setTarget(Target::TARGET_CLASS);
  494.             foreach (self::$metadataParser->parse($docComment'class @' $name) as $annotation) {
  495.                 if ($annotation instanceof Target) {
  496.                     $metadata['targets']         = $annotation->targets;
  497.                     $metadata['targets_literal'] = $annotation->literal;
  498.                     continue;
  499.                 }
  500.                 if ($annotation instanceof NamedArgumentConstructor) {
  501.                     $metadata['has_named_argument_constructor'] = $metadata['has_constructor'];
  502.                     if ($metadata['has_named_argument_constructor']) {
  503.                         // choose the first argument as the default property
  504.                         $metadata['default_property'] = $constructor->getParameters()[0]->getName();
  505.                     }
  506.                 }
  507.                 if (! ($annotation instanceof Attributes)) {
  508.                     continue;
  509.                 }
  510.                 foreach ($annotation->value as $attribute) {
  511.                     $this->collectAttributeTypeMetadata($metadata$attribute);
  512.                 }
  513.             }
  514.             // if not has a constructor will inject values into public properties
  515.             if ($metadata['has_constructor'] === false) {
  516.                 // collect all public properties
  517.                 foreach ($class->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
  518.                     $metadata['properties'][$property->name] = $property->name;
  519.                     $propertyComment $property->getDocComment();
  520.                     if ($propertyComment === false) {
  521.                         continue;
  522.                     }
  523.                     $attribute = new Attribute();
  524.                     $attribute->required = (strpos($propertyComment'@Required') !== false);
  525.                     $attribute->name     $property->name;
  526.                     $attribute->type     = (strpos($propertyComment'@var') !== false &&
  527.                         preg_match('/@var\s+([^\s]+)/'$propertyComment$matches))
  528.                         ? $matches[1]
  529.                         : 'mixed';
  530.                     $this->collectAttributeTypeMetadata($metadata$attribute);
  531.                     // checks if the property has @Enum
  532.                     if (strpos($propertyComment'@Enum') === false) {
  533.                         continue;
  534.                     }
  535.                     $context 'property ' $class->name '::$' $property->name;
  536.                     self::$metadataParser->setTarget(Target::TARGET_PROPERTY);
  537.                     foreach (self::$metadataParser->parse($propertyComment$context) as $annotation) {
  538.                         if (! $annotation instanceof Enum) {
  539.                             continue;
  540.                         }
  541.                         $metadata['enum'][$property->name]['value']   = $annotation->value;
  542.                         $metadata['enum'][$property->name]['literal'] = (! empty($annotation->literal))
  543.                             ? $annotation->literal
  544.                             $annotation->value;
  545.                     }
  546.                 }
  547.                 // choose the first property as default property
  548.                 $metadata['default_property'] = reset($metadata['properties']);
  549.             } elseif ($metadata['has_named_argument_constructor']) {
  550.                 foreach ($constructor->getParameters() as $parameter) {
  551.                     $metadata['constructor_args'][$parameter->getName()] = [
  552.                         'position' => $parameter->getPosition(),
  553.                         'default' => $parameter->isOptional() ? $parameter->getDefaultValue() : null,
  554.                     ];
  555.                 }
  556.             }
  557.         }
  558.         self::$annotationMetadata[$name] = $metadata;
  559.     }
  560.     /**
  561.      * Collects parsing metadata for a given attribute.
  562.      *
  563.      * @param mixed[] $metadata
  564.      */
  565.     private function collectAttributeTypeMetadata(array &$metadataAttribute $attribute): void
  566.     {
  567.         // handle internal type declaration
  568.         $type self::$typeMap[$attribute->type] ?? $attribute->type;
  569.         // handle the case if the property type is mixed
  570.         if ($type === 'mixed') {
  571.             return;
  572.         }
  573.         // Evaluate type
  574.         $pos strpos($type'<');
  575.         if ($pos !== false) {
  576.             // Checks if the property has array<type>
  577.             $arrayType substr($type$pos 1, -1);
  578.             $type      'array';
  579.             if (isset(self::$typeMap[$arrayType])) {
  580.                 $arrayType self::$typeMap[$arrayType];
  581.             }
  582.             $metadata['attribute_types'][$attribute->name]['array_type'] = $arrayType;
  583.         } else {
  584.             // Checks if the property has type[]
  585.             $pos strrpos($type'[');
  586.             if ($pos !== false) {
  587.                 $arrayType substr($type0$pos);
  588.                 $type      'array';
  589.                 if (isset(self::$typeMap[$arrayType])) {
  590.                     $arrayType self::$typeMap[$arrayType];
  591.                 }
  592.                 $metadata['attribute_types'][$attribute->name]['array_type'] = $arrayType;
  593.             }
  594.         }
  595.         $metadata['attribute_types'][$attribute->name]['type']     = $type;
  596.         $metadata['attribute_types'][$attribute->name]['value']    = $attribute->type;
  597.         $metadata['attribute_types'][$attribute->name]['required'] = $attribute->required;
  598.     }
  599.     /**
  600.      * Annotations ::= Annotation {[ "*" ]* [Annotation]}*
  601.      *
  602.      * @throws AnnotationException
  603.      * @throws ReflectionException
  604.      *
  605.      * @phpstan-return list<object>
  606.      */
  607.     private function Annotations(): array
  608.     {
  609.         $annotations = [];
  610.         while ($this->lexer->lookahead !== null) {
  611.             if ($this->lexer->lookahead['type'] !== DocLexer::T_AT) {
  612.                 $this->lexer->moveNext();
  613.                 continue;
  614.             }
  615.             // make sure the @ is preceded by non-catchable pattern
  616.             if (
  617.                 $this->lexer->token !== null &&
  618.                 $this->lexer->lookahead['position'] === $this->lexer->token['position'] + strlen(
  619.                     $this->lexer->token['value']
  620.                 )
  621.             ) {
  622.                 $this->lexer->moveNext();
  623.                 continue;
  624.             }
  625.             // make sure the @ is followed by either a namespace separator, or
  626.             // an identifier token
  627.             $peek $this->lexer->glimpse();
  628.             if (
  629.                 ($peek === null)
  630.                 || ($peek['type'] !== DocLexer::T_NAMESPACE_SEPARATOR && ! in_array(
  631.                         $peek['type'],
  632.                         self::$classIdentifiers,
  633.                         true
  634.                     ))
  635.                 || $peek['position'] !== $this->lexer->lookahead['position'] + 1
  636.             ) {
  637.                 $this->lexer->moveNext();
  638.                 continue;
  639.             }
  640.             $this->isNestedAnnotation false;
  641.             $annot                    $this->Annotation();
  642.             if ($annot === false) {
  643.                 continue;
  644.             }
  645.             $annotations[] = $annot;
  646.         }
  647.         return $annotations;
  648.     }
  649.     /**
  650.      * Annotation     ::= "@" AnnotationName MethodCall
  651.      * AnnotationName ::= QualifiedName | SimpleName
  652.      * QualifiedName  ::= NameSpacePart "\" {NameSpacePart "\"}* SimpleName
  653.      * NameSpacePart  ::= identifier | null | false | true
  654.      * SimpleName     ::= identifier | null | false | true
  655.      *
  656.      * @return object|false False if it is not a valid annotation.
  657.      *
  658.      * @throws AnnotationException
  659.      * @throws ReflectionException
  660.      */
  661.     private function Annotation()
  662.     {
  663.         $this->match(DocLexer::T_AT);
  664.         // check if we have an annotation
  665.         $name $this->Identifier();
  666.         if (
  667.             $this->lexer->isNextToken(DocLexer::T_MINUS)
  668.             && $this->lexer->nextTokenIsAdjacent()
  669.         ) {
  670.             // Annotations with dashes, such as "@foo-" or "@foo-bar", are to be discarded
  671.             return false;
  672.         }
  673.         // only process names which are not fully qualified, yet
  674.         // fully qualified names must start with a \
  675.         $originalName $name;
  676.         if ($name[0] !== '\\') {
  677.             $pos          strpos($name'\\');
  678.             $alias        = ($pos === false) ? $name substr($name0$pos);
  679.             $found        false;
  680.             $loweredAlias strtolower($alias);
  681.             if ($this->namespaces) {
  682.                 foreach ($this->namespaces as $namespace) {
  683.                     if ($this->classExists($namespace '\\' $name)) {
  684.                         $name  $namespace '\\' $name;
  685.                         $found true;
  686.                         break;
  687.                     }
  688.                 }
  689.             } elseif (isset($this->imports[$loweredAlias])) {
  690.                 $namespace ltrim($this->imports[$loweredAlias], '\\');
  691.                 $name      = ($pos !== false)
  692.                     ? $namespace substr($name$pos)
  693.                     : $namespace;
  694.                 $found     $this->classExists($name);
  695.             } elseif (
  696.                 ! isset($this->ignoredAnnotationNames[$name])
  697.                 && isset($this->imports['__NAMESPACE__'])
  698.                 && $this->classExists($this->imports['__NAMESPACE__'] . '\\' $name)
  699.             ) {
  700.                 $name  $this->imports['__NAMESPACE__'] . '\\' $name;
  701.                 $found true;
  702.             } elseif (! isset($this->ignoredAnnotationNames[$name]) && $this->classExists($name)) {
  703.                 $found true;
  704.             }
  705.             if (! $found) {
  706.                 if ($this->isIgnoredAnnotation($name)) {
  707.                     return false;
  708.                 }
  709.                 throw AnnotationException::semanticalError(sprintf(
  710.                     <<<'EXCEPTION'
  711. The annotation "@%s" in %s was never imported. Did you maybe forget to add a "use" statement for this annotation?
  712. EXCEPTION
  713.                     ,
  714.                     $name,
  715.                     $this->context
  716.                 ));
  717.             }
  718.         }
  719.         $name ltrim($name'\\');
  720.         if (! $this->classExists($name)) {
  721.             throw AnnotationException::semanticalError(sprintf(
  722.                 'The annotation "@%s" in %s does not exist, or could not be auto-loaded.',
  723.                 $name,
  724.                 $this->context
  725.             ));
  726.         }
  727.         // at this point, $name contains the fully qualified class name of the
  728.         // annotation, and it is also guaranteed that this class exists, and
  729.         // that it is loaded
  730.         // collects the metadata annotation only if there is not yet
  731.         if (! isset(self::$annotationMetadata[$name])) {
  732.             $this->collectAnnotationMetadata($name);
  733.         }
  734.         // verify that the class is really meant to be an annotation and not just any ordinary class
  735.         if (self::$annotationMetadata[$name]['is_annotation'] === false) {
  736.             if ($this->isIgnoredAnnotation($originalName) || $this->isIgnoredAnnotation($name)) {
  737.                 return false;
  738.             }
  739.             throw AnnotationException::semanticalError(sprintf(
  740.                 <<<'EXCEPTION'
  741. The class "%s" is not annotated with @Annotation.
  742. Are you sure this class can be used as annotation?
  743. If so, then you need to add @Annotation to the _class_ doc comment of "%s".
  744. If it is indeed no annotation, then you need to add @IgnoreAnnotation("%s") to the _class_ doc comment of %s.
  745. EXCEPTION
  746.                 ,
  747.                 $name,
  748.                 $name,
  749.                 $originalName,
  750.                 $this->context
  751.             ));
  752.         }
  753.         //if target is nested annotation
  754.         $target $this->isNestedAnnotation Target::TARGET_ANNOTATION $this->target;
  755.         // Next will be nested
  756.         $this->isNestedAnnotation true;
  757.         //if annotation does not support current target
  758.         if ((self::$annotationMetadata[$name]['targets'] & $target) === && $target) {
  759.             throw AnnotationException::semanticalError(
  760.                 sprintf(
  761.                     <<<'EXCEPTION'
  762. Annotation @%s is not allowed to be declared on %s. You may only use this annotation on these code elements: %s.
  763. EXCEPTION
  764.                     ,
  765.                     $originalName,
  766.                     $this->context,
  767.                     self::$annotationMetadata[$name]['targets_literal']
  768.                 )
  769.             );
  770.         }
  771.         $arguments $this->MethodCall();
  772.         $values    $this->resolvePositionalValues($arguments$name);
  773.         if (isset(self::$annotationMetadata[$name]['enum'])) {
  774.             // checks all declared attributes
  775.             foreach (self::$annotationMetadata[$name]['enum'] as $property => $enum) {
  776.                 // checks if the attribute is a valid enumerator
  777.                 if (isset($values[$property]) && ! in_array($values[$property], $enum['value'])) {
  778.                     throw AnnotationException::enumeratorError(
  779.                         $property,
  780.                         $name,
  781.                         $this->context,
  782.                         $enum['literal'],
  783.                         $values[$property]
  784.                     );
  785.                 }
  786.             }
  787.         }
  788.         // checks all declared attributes
  789.         foreach (self::$annotationMetadata[$name]['attribute_types'] as $property => $type) {
  790.             if (
  791.                 $property === self::$annotationMetadata[$name]['default_property']
  792.                 && ! isset($values[$property]) && isset($values['value'])
  793.             ) {
  794.                 $property 'value';
  795.             }
  796.             // handle a not given attribute or null value
  797.             if (! isset($values[$property])) {
  798.                 if ($type['required']) {
  799.                     throw AnnotationException::requiredError(
  800.                         $property,
  801.                         $originalName,
  802.                         $this->context,
  803.                         'a(n) ' $type['value']
  804.                     );
  805.                 }
  806.                 continue;
  807.             }
  808.             if ($type['type'] === 'array') {
  809.                 // handle the case of a single value
  810.                 if (! is_array($values[$property])) {
  811.                     $values[$property] = [$values[$property]];
  812.                 }
  813.                 // checks if the attribute has array type declaration, such as "array<string>"
  814.                 if (isset($type['array_type'])) {
  815.                     foreach ($values[$property] as $item) {
  816.                         if (gettype($item) !== $type['array_type'] && ! $item instanceof $type['array_type']) {
  817.                             throw AnnotationException::attributeTypeError(
  818.                                 $property,
  819.                                 $originalName,
  820.                                 $this->context,
  821.                                 'either a(n) ' $type['array_type'] . ', or an array of ' $type['array_type'] . 's',
  822.                                 $item
  823.                             );
  824.                         }
  825.                     }
  826.                 }
  827.             } elseif (gettype($values[$property]) !== $type['type'] && ! $values[$property] instanceof $type['type']) {
  828.                 throw AnnotationException::attributeTypeError(
  829.                     $property,
  830.                     $originalName,
  831.                     $this->context,
  832.                     'a(n) ' $type['value'],
  833.                     $values[$property]
  834.                 );
  835.             }
  836.         }
  837.         if (self::$annotationMetadata[$name]['has_named_argument_constructor']) {
  838.             if (PHP_VERSION_ID >= 80000) {
  839.                 $refClass = new ReflectionClass($name);
  840.                 foreach ($refClass->getConstructor()->getParameters() as $parameter) {
  841.                     foreach ($values as $key => $val) {
  842.                         if ($parameter->getName() === $key) {
  843.                             continue;
  844.                         }
  845.                         if (strtolower($parameter->getName()) === strtolower($key)) {
  846.                             $values[$parameter->getName()] = $val;
  847.                             unset($values[$key]);
  848.                         }
  849.                     }
  850.                 }
  851.                 return new $name(...$values);
  852.             }
  853.             $positionalValues = [];
  854.             foreach (self::$annotationMetadata[$name]['constructor_args'] as $property => $parameter) {
  855.                 $positionalValues[$parameter['position']] = $parameter['default'];
  856.             }
  857.             $refClass = new ReflectionClass($name);
  858.             foreach ($refClass->getConstructor()->getParameters() as $parameter) {
  859.                 foreach ($values as $key => $val) {
  860.                     if ($parameter->getName() === $key) {
  861.                         continue;
  862.                     }
  863.                     if (strtolower($parameter->getName()) === strtolower($key)) {
  864.                         $values[$parameter->getName()] = $val;
  865.                         unset($values[$key]);
  866.                     }
  867.                 }
  868.             }
  869.             foreach ($values as $property => $value) {
  870.                 if (! isset(self::$annotationMetadata[$name]['constructor_args'][$property])) {
  871.                     throw AnnotationException::creationError(sprintf(
  872.                         <<<'EXCEPTION'
  873. The annotation @%s declared on %s does not have a property named "%s"
  874. that can be set through its named arguments constructor.
  875. Available named arguments: %s
  876. EXCEPTION
  877.                         ,
  878.                         $originalName,
  879.                         $this->context,
  880.                         $property,
  881.                         implode(', 'array_keys(self::$annotationMetadata[$name]['constructor_args']))
  882.                     ));
  883.                 }
  884.                 $positionalValues[self::$annotationMetadata[$name]['constructor_args'][$property]['position']] = $value;
  885.             }
  886.             return new $name(...$positionalValues);
  887.         }
  888.         // check if the annotation expects values via the constructor,
  889.         // or directly injected into public properties
  890.         if (self::$annotationMetadata[$name]['has_constructor'] === true) {
  891.             return new $name($values);
  892.         }
  893.         $instance = new $name();
  894.         foreach ($values as $property => $value) {
  895.             if (! isset(self::$annotationMetadata[$name]['properties'][$property])) {
  896.                 if ($property !== 'value') {
  897.                     throw AnnotationException::creationError(sprintf(
  898.                         <<<'EXCEPTION'
  899. The annotation @%s declared on %s does not have a property named "%s".
  900. Available properties: %s
  901. EXCEPTION
  902.                         ,
  903.                         $originalName,
  904.                         $this->context,
  905.                         $property,
  906.                         implode(', 'self::$annotationMetadata[$name]['properties'])
  907.                     ));
  908.                 }
  909.                 // handle the case if the property has no annotations
  910.                 $property self::$annotationMetadata[$name]['default_property'];
  911.                 if (! $property) {
  912.                     throw AnnotationException::creationError(sprintf(
  913.                         'The annotation @%s declared on %s does not accept any values, but got %s.',
  914.                         $originalName,
  915.                         $this->context,
  916.                         json_encode($values)
  917.                     ));
  918.                 }
  919.             }
  920.             $instance->{$property} = $value;
  921.         }
  922.         return $instance;
  923.     }
  924.     /**
  925.      * MethodCall ::= ["(" [Values] ")"]
  926.      *
  927.      * @return mixed[]
  928.      *
  929.      * @throws AnnotationException
  930.      * @throws ReflectionException
  931.      */
  932.     private function MethodCall(): array
  933.     {
  934.         $values = [];
  935.         if (! $this->lexer->isNextToken(DocLexer::T_OPEN_PARENTHESIS)) {
  936.             return $values;
  937.         }
  938.         $this->match(DocLexer::T_OPEN_PARENTHESIS);
  939.         if (! $this->lexer->isNextToken(DocLexer::T_CLOSE_PARENTHESIS)) {
  940.             $values $this->Values();
  941.         }
  942.         $this->match(DocLexer::T_CLOSE_PARENTHESIS);
  943.         return $values;
  944.     }
  945.     /**
  946.      * Values ::= Array | Value {"," Value}* [","]
  947.      *
  948.      * @return mixed[]
  949.      *
  950.      * @throws AnnotationException
  951.      * @throws ReflectionException
  952.      */
  953.     private function Values(): array
  954.     {
  955.         $values = [$this->Value()];
  956.         while ($this->lexer->isNextToken(DocLexer::T_COMMA)) {
  957.             $this->match(DocLexer::T_COMMA);
  958.             if ($this->lexer->isNextToken(DocLexer::T_CLOSE_PARENTHESIS)) {
  959.                 break;
  960.             }
  961.             $token $this->lexer->lookahead;
  962.             $value $this->Value();
  963.             $values[] = $value;
  964.         }
  965.         $namedArguments      = [];
  966.         $positionalArguments = [];
  967.         foreach ($values as $k => $value) {
  968.             if (is_object($value) && $value instanceof stdClass) {
  969.                 $namedArguments[$value->name] = $value->value;
  970.             } else {
  971.                 $positionalArguments[$k] = $value;
  972.             }
  973.         }
  974.         return ['named_arguments' => $namedArguments'positional_arguments' => $positionalArguments];
  975.     }
  976.     /**
  977.      * Constant ::= integer | string | float | boolean
  978.      *
  979.      * @return mixed
  980.      *
  981.      * @throws AnnotationException
  982.      */
  983.     private function Constant()
  984.     {
  985.         $identifier $this->Identifier();
  986.         if (! defined($identifier) && strpos($identifier'::') !== false && $identifier[0] !== '\\') {
  987.             [$className$const] = explode('::'$identifier);
  988.             $pos          strpos($className'\\');
  989.             $alias        = ($pos === false) ? $className substr($className0$pos);
  990.             $found        false;
  991.             $loweredAlias strtolower($alias);
  992.             switch (true) {
  993.                 case ! empty($this->namespaces):
  994.                     foreach ($this->namespaces as $ns) {
  995.                         if (class_exists($ns '\\' $className) || interface_exists($ns '\\' $className)) {
  996.                             $className $ns '\\' $className;
  997.                             $found     true;
  998.                             break;
  999.                         }
  1000.                     }
  1001.                     break;
  1002.                 case isset($this->imports[$loweredAlias]):
  1003.                     $found     true;
  1004.                     $className = ($pos !== false)
  1005.                         ? $this->imports[$loweredAlias] . substr($className$pos)
  1006.                         : $this->imports[$loweredAlias];
  1007.                     break;
  1008.                 default:
  1009.                     if (isset($this->imports['__NAMESPACE__'])) {
  1010.                         $ns $this->imports['__NAMESPACE__'];
  1011.                         if (class_exists($ns '\\' $className) || interface_exists($ns '\\' $className)) {
  1012.                             $className $ns '\\' $className;
  1013.                             $found     true;
  1014.                         }
  1015.                     }
  1016.                     break;
  1017.             }
  1018.             if ($found) {
  1019.                 $identifier $className '::' $const;
  1020.             }
  1021.         }
  1022.         /**
  1023.          * Checks if identifier ends with ::class and remove the leading backslash if it exists.
  1024.          */
  1025.         if (
  1026.             $this->identifierEndsWithClassConstant($identifier) &&
  1027.             ! $this->identifierStartsWithBackslash($identifier)
  1028.         ) {
  1029.             return substr($identifier0$this->getClassConstantPositionInIdentifier($identifier));
  1030.         }
  1031.         if ($this->identifierEndsWithClassConstant($identifier) && $this->identifierStartsWithBackslash($identifier)) {
  1032.             return substr($identifier1$this->getClassConstantPositionInIdentifier($identifier) - 1);
  1033.         }
  1034.         if (! defined($identifier)) {
  1035.             throw AnnotationException::semanticalErrorConstants($identifier$this->context);
  1036.         }
  1037.         return constant($identifier);
  1038.     }
  1039.     private function identifierStartsWithBackslash(string $identifier): bool
  1040.     {
  1041.         return $identifier[0] === '\\';
  1042.     }
  1043.     private function identifierEndsWithClassConstant(string $identifier): bool
  1044.     {
  1045.         return $this->getClassConstantPositionInIdentifier($identifier) === strlen($identifier) - strlen('::class');
  1046.     }
  1047.     /**
  1048.      * @return int|false
  1049.      */
  1050.     private function getClassConstantPositionInIdentifier(string $identifier)
  1051.     {
  1052.         return stripos($identifier'::class');
  1053.     }
  1054.     /**
  1055.      * Identifier ::= string
  1056.      *
  1057.      * @throws AnnotationException
  1058.      */
  1059.     private function Identifier(): string
  1060.     {
  1061.         // check if we have an annotation
  1062.         if (! $this->lexer->isNextTokenAny(self::$classIdentifiers)) {
  1063.             throw $this->syntaxError('namespace separator or identifier');
  1064.         }
  1065.         $this->lexer->moveNext();
  1066.         $className $this->lexer->token['value'];
  1067.         while (
  1068.             $this->lexer->lookahead !== null &&
  1069.             $this->lexer->lookahead['position'] === ($this->lexer->token['position'] +
  1070.                 strlen($this->lexer->token['value'])) &&
  1071.             $this->lexer->isNextToken(DocLexer::T_NAMESPACE_SEPARATOR)
  1072.         ) {
  1073.             $this->match(DocLexer::T_NAMESPACE_SEPARATOR);
  1074.             $this->matchAny(self::$classIdentifiers);
  1075.             $className .= '\\' $this->lexer->token['value'];
  1076.         }
  1077.         return $className;
  1078.     }
  1079.     /**
  1080.      * Value ::= PlainValue | FieldAssignment
  1081.      *
  1082.      * @return mixed
  1083.      *
  1084.      * @throws AnnotationException
  1085.      * @throws ReflectionException
  1086.      */
  1087.     private function Value()
  1088.     {
  1089.         $peek $this->lexer->glimpse();
  1090.         if ($peek['type'] === DocLexer::T_EQUALS) {
  1091.             return $this->FieldAssignment();
  1092.         }
  1093.         return $this->PlainValue();
  1094.     }
  1095.     /**
  1096.      * PlainValue ::= integer | string | float | boolean | Array | Annotation
  1097.      *
  1098.      * @return mixed
  1099.      *
  1100.      * @throws AnnotationException
  1101.      * @throws ReflectionException
  1102.      */
  1103.     private function PlainValue()
  1104.     {
  1105.         if ($this->lexer->isNextToken(DocLexer::T_OPEN_CURLY_BRACES)) {
  1106.             return $this->Arrayx();
  1107.         }
  1108.         if ($this->lexer->isNextToken(DocLexer::T_AT)) {
  1109.             return $this->Annotation();
  1110.         }
  1111.         if ($this->lexer->isNextToken(DocLexer::T_IDENTIFIER)) {
  1112.             return $this->Constant();
  1113.         }
  1114.         switch ($this->lexer->lookahead['type']) {
  1115.             case DocLexer::T_STRING:
  1116.                 $this->match(DocLexer::T_STRING);
  1117.                 return $this->lexer->token['value'];
  1118.             case DocLexer::T_INTEGER:
  1119.                 $this->match(DocLexer::T_INTEGER);
  1120.                 return (int) $this->lexer->token['value'];
  1121.             case DocLexer::T_FLOAT:
  1122.                 $this->match(DocLexer::T_FLOAT);
  1123.                 return (float) $this->lexer->token['value'];
  1124.             case DocLexer::T_TRUE:
  1125.                 $this->match(DocLexer::T_TRUE);
  1126.                 return true;
  1127.             case DocLexer::T_FALSE:
  1128.                 $this->match(DocLexer::T_FALSE);
  1129.                 return false;
  1130.             case DocLexer::T_NULL:
  1131.                 $this->match(DocLexer::T_NULL);
  1132.                 return null;
  1133.             default:
  1134.                 throw $this->syntaxError('PlainValue');
  1135.         }
  1136.     }
  1137.     /**
  1138.      * FieldAssignment ::= FieldName "=" PlainValue
  1139.      * FieldName ::= identifier
  1140.      *
  1141.      * @throws AnnotationException
  1142.      * @throws ReflectionException
  1143.      */
  1144.     private function FieldAssignment(): stdClass
  1145.     {
  1146.         $this->match(DocLexer::T_IDENTIFIER);
  1147.         $fieldName $this->lexer->token['value'];
  1148.         $this->match(DocLexer::T_EQUALS);
  1149.         $item        = new stdClass();
  1150.         $item->name  $fieldName;
  1151.         $item->value $this->PlainValue();
  1152.         return $item;
  1153.     }
  1154.     /**
  1155.      * Array ::= "{" ArrayEntry {"," ArrayEntry}* [","] "}"
  1156.      *
  1157.      * @return mixed[]
  1158.      *
  1159.      * @throws AnnotationException
  1160.      * @throws ReflectionException
  1161.      */
  1162.     private function Arrayx(): array
  1163.     {
  1164.         $array $values = [];
  1165.         $this->match(DocLexer::T_OPEN_CURLY_BRACES);
  1166.         // If the array is empty, stop parsing and return.
  1167.         if ($this->lexer->isNextToken(DocLexer::T_CLOSE_CURLY_BRACES)) {
  1168.             $this->match(DocLexer::T_CLOSE_CURLY_BRACES);
  1169.             return $array;
  1170.         }
  1171.         $values[] = $this->ArrayEntry();
  1172.         while ($this->lexer->isNextToken(DocLexer::T_COMMA)) {
  1173.             $this->match(DocLexer::T_COMMA);
  1174.             // optional trailing comma
  1175.             if ($this->lexer->isNextToken(DocLexer::T_CLOSE_CURLY_BRACES)) {
  1176.                 break;
  1177.             }
  1178.             $values[] = $this->ArrayEntry();
  1179.         }
  1180.         $this->match(DocLexer::T_CLOSE_CURLY_BRACES);
  1181.         foreach ($values as $value) {
  1182.             [$key$val] = $value;
  1183.             if ($key !== null) {
  1184.                 $array[$key] = $val;
  1185.             } else {
  1186.                 $array[] = $val;
  1187.             }
  1188.         }
  1189.         return $array;
  1190.     }
  1191.     /**
  1192.      * ArrayEntry ::= Value | KeyValuePair
  1193.      * KeyValuePair ::= Key ("=" | ":") PlainValue | Constant
  1194.      * Key ::= string | integer | Constant
  1195.      *
  1196.      * @throws AnnotationException
  1197.      * @throws ReflectionException
  1198.      *
  1199.      * @phpstan-return array{mixed, mixed}
  1200.      */
  1201.     private function ArrayEntry(): array
  1202.     {
  1203.         $peek $this->lexer->glimpse();
  1204.         if (
  1205.             $peek['type'] === DocLexer::T_EQUALS
  1206.             || $peek['type'] === DocLexer::T_COLON
  1207.         ) {
  1208.             if ($this->lexer->isNextToken(DocLexer::T_IDENTIFIER)) {
  1209.                 $key $this->Constant();
  1210.             } else {
  1211.                 $this->matchAny([DocLexer::T_INTEGERDocLexer::T_STRING]);
  1212.                 $key $this->lexer->token['value'];
  1213.             }
  1214.             $this->matchAny([DocLexer::T_EQUALSDocLexer::T_COLON]);
  1215.             return [$key$this->PlainValue()];
  1216.         }
  1217.         return [null$this->Value()];
  1218.     }
  1219.     /**
  1220.      * Checks whether the given $name matches any ignored annotation name or namespace
  1221.      */
  1222.     private function isIgnoredAnnotation(string $name): bool
  1223.     {
  1224.         if ($this->ignoreNotImportedAnnotations || isset($this->ignoredAnnotationNames[$name])) {
  1225.             return true;
  1226.         }
  1227.         foreach (array_keys($this->ignoredAnnotationNamespaces) as $ignoredAnnotationNamespace) {
  1228.             $ignoredAnnotationNamespace rtrim($ignoredAnnotationNamespace'\\') . '\\';
  1229.             if (stripos(rtrim($name'\\') . '\\'$ignoredAnnotationNamespace) === 0) {
  1230.                 return true;
  1231.             }
  1232.         }
  1233.         return false;
  1234.     }
  1235.     /**
  1236.      * Resolve positional arguments (without name) to named ones
  1237.      *
  1238.      * @param array<string,mixed> $arguments
  1239.      *
  1240.      * @return array<string,mixed>
  1241.      */
  1242.     private function resolvePositionalValues(array $argumentsstring $name): array
  1243.     {
  1244.         $positionalArguments $arguments['positional_arguments'] ?? [];
  1245.         $values              $arguments['named_arguments'] ?? [];
  1246.         if (
  1247.             self::$annotationMetadata[$name]['has_named_argument_constructor']
  1248.             && self::$annotationMetadata[$name]['default_property'] !== null
  1249.         ) {
  1250.             // We must ensure that we don't have positional arguments after named ones
  1251.             $positions    array_keys($positionalArguments);
  1252.             $lastPosition null;
  1253.             foreach ($positions as $position) {
  1254.                 if (
  1255.                     ($lastPosition === null && $position !== 0) ||
  1256.                     ($lastPosition !== null && $position !== $lastPosition 1)
  1257.                 ) {
  1258.                     throw $this->syntaxError('Positional arguments after named arguments is not allowed');
  1259.                 }
  1260.                 $lastPosition $position;
  1261.             }
  1262.             foreach (self::$annotationMetadata[$name]['constructor_args'] as $property => $parameter) {
  1263.                 $position $parameter['position'];
  1264.                 if (isset($values[$property]) || ! isset($positionalArguments[$position])) {
  1265.                     continue;
  1266.                 }
  1267.                 $values[$property] = $positionalArguments[$position];
  1268.             }
  1269.         } else {
  1270.             if (count($positionalArguments) > && ! isset($values['value'])) {
  1271.                 if (count($positionalArguments) === 1) {
  1272.                     $value array_pop($positionalArguments);
  1273.                 } else {
  1274.                     $value array_values($positionalArguments);
  1275.                 }
  1276.                 $values['value'] = $value;
  1277.             }
  1278.         }
  1279.         return $values;
  1280.     }
  1281. }