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\Tags; |
17
|
|
|
|
18
|
|
|
use phpDocumentor\Descriptor\ArgumentDescriptor; |
19
|
|
|
use phpDocumentor\Descriptor\Builder\Reflector\AssemblerAbstract; |
20
|
|
|
use phpDocumentor\Descriptor\Tag\MethodDescriptor; |
21
|
|
|
use phpDocumentor\Descriptor\Tag\ReturnDescriptor; |
22
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Method; |
23
|
|
|
use phpDocumentor\Reflection\Type; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Constructs a new descriptor from the Reflector for an `@method` tag. |
27
|
|
|
* |
28
|
|
|
* This object will read the reflected information for the `@method` tag and create a {@see MethodDescriptor} object |
29
|
|
|
* that can be used in the rest of the application and templates. |
30
|
|
|
*/ |
31
|
|
|
class MethodAssembler extends AssemblerAbstract |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Creates a new Descriptor from the given Reflector. |
35
|
|
|
* |
36
|
|
|
* @param Method $data |
37
|
|
|
* |
38
|
|
|
* @return MethodDescriptor |
39
|
|
|
*/ |
40
|
6 |
|
public function create($data) |
41
|
|
|
{ |
42
|
6 |
|
$descriptor = new MethodDescriptor($data->getName()); |
43
|
6 |
|
$descriptor->setDescription($data->getDescription()); |
44
|
6 |
|
$descriptor->setMethodName($data->getMethodName()); |
45
|
6 |
|
$descriptor->setStatic($data->isStatic()); |
46
|
|
|
|
47
|
6 |
|
$response = new ReturnDescriptor('return'); |
48
|
6 |
|
$response->setType($data->getReturnType()); |
49
|
6 |
|
$descriptor->setResponse($response); |
50
|
|
|
|
51
|
6 |
|
foreach ($data->getArguments() as $argument) { |
52
|
5 |
|
if (array_key_exists('name', $argument) && array_key_exists('type', $argument)) { |
53
|
5 |
|
$argumentDescriptor = $this->createArgumentDescriptorForMagicMethod( |
54
|
5 |
|
$argument['name'], |
55
|
5 |
|
$argument['type'] |
|
|
|
|
56
|
|
|
); |
57
|
5 |
|
$descriptor->getArguments()->set($argumentDescriptor->getName(), $argumentDescriptor); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
6 |
|
return $descriptor; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Construct an argument descriptor given the array representing an argument with a Method Tag in the Reflection |
66
|
|
|
* component. |
67
|
|
|
*/ |
68
|
5 |
|
private function createArgumentDescriptorForMagicMethod(string $name, Type $type): ArgumentDescriptor |
69
|
|
|
{ |
70
|
5 |
|
$argumentDescriptor = new ArgumentDescriptor(); |
71
|
5 |
|
$argumentDescriptor->setType(AssemblerAbstract::deduplicateTypes($type)); |
72
|
5 |
|
$argumentDescriptor->setName($name); |
73
|
|
|
|
74
|
5 |
|
return $argumentDescriptor; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: