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

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