This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
Check for nulls being passed to functions/methods that do not accept null.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | declare(strict_types=1); |
||
3 | |||
4 | /** |
||
5 | * This file is part of phpDocumentor. |
||
6 | * |
||
7 | * For the full copyright and license information, please view the LICENSE |
||
8 | * file that was distributed with this source code. |
||
9 | * |
||
10 | * @author Mike van Riel <[email protected]> |
||
11 | * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) |
||
12 | * @license http://www.opensource.org/licenses/mit-license.php MIT |
||
13 | * @link http://phpdoc.org |
||
14 | */ |
||
15 | |||
16 | namespace phpDocumentor\Descriptor\Builder\Reflector; |
||
17 | |||
18 | use phpDocumentor\Descriptor\ArgumentDescriptor; |
||
19 | use phpDocumentor\Descriptor\MethodDescriptor; |
||
20 | use phpDocumentor\Reflection\DocBlock\Tags\Param; |
||
21 | use phpDocumentor\Reflection\Php\Argument; |
||
22 | use phpDocumentor\Reflection\Php\Method; |
||
23 | |||
24 | /** |
||
25 | * Assembles a MethodDescriptor from a MethodReflector. |
||
26 | */ |
||
27 | class MethodAssembler extends AssemblerAbstract |
||
28 | { |
||
29 | /** @var ArgumentAssembler */ |
||
30 | protected $argumentAssembler; |
||
31 | |||
32 | /** |
||
33 | * Initializes this assembler with its dependencies. |
||
34 | */ |
||
35 | 3 | public function __construct(ArgumentAssembler $argumentAssembler) |
|
36 | { |
||
37 | 3 | $this->argumentAssembler = $argumentAssembler; |
|
38 | 3 | } |
|
39 | |||
40 | /** |
||
41 | * Creates a Descriptor from the provided data. |
||
42 | * |
||
43 | * @param Method $data |
||
44 | * |
||
45 | * @return MethodDescriptor |
||
46 | */ |
||
47 | 3 | public function create($data) |
|
48 | { |
||
49 | 3 | $methodDescriptor = new MethodDescriptor(); |
|
50 | 3 | $methodDescriptor->setNamespace( |
|
51 | 3 | substr( |
|
52 | 3 | (string) $data->getFqsen(), |
|
53 | 3 | 0, |
|
54 | 3 | -strlen($data->getName()) - 4 |
|
55 | ) |
||
56 | ); |
||
57 | 3 | $this->mapReflectorToDescriptor($data, $methodDescriptor); |
|
58 | |||
59 | 3 | $this->assembleDocBlock($data->getDocBlock(), $methodDescriptor); |
|
60 | 3 | $this->addArguments($data, $methodDescriptor); |
|
61 | 3 | $this->addVariadicArgument($data, $methodDescriptor); |
|
62 | |||
63 | 3 | return $methodDescriptor; |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * Maps the fields to the reflector to the descriptor. |
||
68 | */ |
||
69 | 3 | protected function mapReflectorToDescriptor(Method $reflector, MethodDescriptor $descriptor): void |
|
70 | { |
||
71 | 3 | $descriptor->setFullyQualifiedStructuralElementName($reflector->getFqsen()); |
|
72 | 3 | $descriptor->setName($reflector->getName()); |
|
73 | 3 | $descriptor->setVisibility((string) $reflector->getVisibility() ?: 'public'); |
|
74 | 3 | $descriptor->setFinal($reflector->isFinal()); |
|
75 | 3 | $descriptor->setAbstract($reflector->isAbstract()); |
|
76 | 3 | $descriptor->setStatic($reflector->isStatic()); |
|
77 | 3 | $descriptor->setLine($reflector->getLocation()->getLineNumber()); |
|
78 | 3 | $descriptor->setReturnType($reflector->getReturnType()); |
|
79 | 3 | } |
|
80 | |||
81 | /** |
||
82 | * Adds the reflected Arguments to the Descriptor. |
||
83 | */ |
||
84 | 3 | protected function addArguments(Method $reflector, MethodDescriptor $descriptor): void |
|
85 | { |
||
86 | 3 | foreach ($reflector->getArguments() as $argument) { |
|
87 | 3 | $this->addArgument($argument, $descriptor); |
|
88 | } |
||
89 | 3 | } |
|
90 | |||
91 | /** |
||
92 | * Adds a single reflected Argument to the Method Descriptor. |
||
93 | */ |
||
94 | 3 | protected function addArgument(Argument $argument, MethodDescriptor $descriptor): void |
|
95 | { |
||
96 | 3 | $params = $descriptor->getTags()->get('param', []); |
|
97 | |||
98 | 3 | if (!$this->argumentAssembler->getBuilder()) { |
|
99 | 3 | $this->argumentAssembler->setBuilder($this->builder); |
|
0 ignored issues
–
show
|
|||
100 | } |
||
101 | |||
102 | 3 | $argumentDescriptor = $this->argumentAssembler->create($argument, $params); |
|
103 | |||
104 | 3 | $descriptor->addArgument($argumentDescriptor->getName(), $argumentDescriptor); |
|
105 | 3 | } |
|
106 | |||
107 | /** |
||
108 | * Checks if there is a variadic argument in the `@param` tags and adds it to the list of Arguments in |
||
109 | * the Descriptor unless there is already one present. |
||
110 | */ |
||
111 | 3 | protected function addVariadicArgument(Method $data, MethodDescriptor $methodDescriptor): void |
|
112 | { |
||
113 | 3 | if (!$data->getDocBlock()) { |
|
114 | 1 | return; |
|
115 | } |
||
116 | |||
117 | 2 | $paramTags = $data->getDocBlock()->getTagsByName('param'); |
|
118 | |||
119 | /** @var Param $lastParamTag */ |
||
120 | 2 | $lastParamTag = end($paramTags); |
|
121 | 2 | if (!$lastParamTag) { |
|
122 | 1 | return; |
|
123 | } |
||
124 | |||
125 | 1 | if ($lastParamTag->isVariadic() |
|
126 | 1 | && array_key_exists($lastParamTag->getVariableName(), $methodDescriptor->getArguments()->getAll()) |
|
127 | ) { |
||
128 | 1 | $types = $lastParamTag->getType(); |
|
129 | |||
130 | 1 | $argument = new ArgumentDescriptor(); |
|
131 | 1 | $argument->setName($lastParamTag->getVariableName()); |
|
132 | 1 | $argument->setType($types); |
|
133 | 1 | $argument->setDescription($lastParamTag->getDescription()); |
|
134 | 1 | $argument->setLine($methodDescriptor->getLine()); |
|
135 | 1 | $argument->setVariadic(true); |
|
136 | |||
137 | 1 | $methodDescriptor->getArguments()->set($argument->getName(), $argument); |
|
138 | } |
||
139 | 1 | } |
|
140 | } |
||
141 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: