1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* phpDocumentor |
4
|
|
|
* |
5
|
|
|
* PHP Version 5.3 |
6
|
|
|
* |
7
|
|
|
* @copyright 2010-2014 Mike van Riel / Naenius (http://www.naenius.com) |
8
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
9
|
|
|
* @link http://phpdoc.org |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace phpDocumentor\Descriptor\Builder\Reflector\Tags; |
13
|
|
|
|
14
|
|
|
use phpDocumentor\Descriptor\ArgumentDescriptor; |
15
|
|
|
use phpDocumentor\Descriptor\Builder\Reflector\AssemblerAbstract; |
16
|
|
|
use phpDocumentor\Descriptor\Tag\MethodDescriptor; |
17
|
|
|
use phpDocumentor\Descriptor\Tag\ReturnDescriptor; |
18
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Method; |
19
|
|
|
use phpDocumentor\Reflection\Type; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Constructs a new descriptor from the Reflector for an `@method` tag. |
23
|
|
|
* |
24
|
|
|
* This object will read the reflected information for the `@method` tag and create a {@see MethodDescriptor} object |
25
|
|
|
* that can be used in the rest of the application and templates. |
26
|
|
|
*/ |
27
|
|
|
class MethodAssembler extends AssemblerAbstract |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* Creates a new Descriptor from the given Reflector. |
31
|
|
|
* |
32
|
|
|
* @param Method $data |
33
|
|
|
* |
34
|
|
|
* @return MethodDescriptor |
35
|
|
|
*/ |
36
|
|
|
public function create($data) |
37
|
|
|
{ |
38
|
|
|
$descriptor = new MethodDescriptor($data->getName()); |
39
|
|
|
$descriptor->setDescription($data->getDescription()); |
|
|
|
|
40
|
|
|
$descriptor->setMethodName($data->getMethodName()); |
41
|
|
|
$descriptor->setStatic($data->isStatic()); |
42
|
|
|
|
43
|
|
|
$response = new ReturnDescriptor('return'); |
44
|
|
|
$response->setTypes($data->getReturnType()); |
45
|
|
|
$descriptor->setResponse($response); |
46
|
|
|
|
47
|
|
|
foreach ($data->getArguments() as $argument) { |
48
|
|
|
$argumentDescriptor = $this->createArgumentDescriptorForMagicMethod($argument['name'], $argument['type']); |
|
|
|
|
49
|
|
|
$descriptor->getArguments()->set($argumentDescriptor->getName(), $argumentDescriptor); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return $descriptor; |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Construct an argument descriptor given the array representing an argument with a Method Tag in the Reflection |
57
|
|
|
* component. |
58
|
|
|
* |
59
|
|
|
* @param string $name |
60
|
|
|
* @param Type $type |
61
|
|
|
* @return ArgumentDescriptor |
62
|
|
|
* |
63
|
|
|
*/ |
64
|
|
|
private function createArgumentDescriptorForMagicMethod($name, Type $type) |
65
|
|
|
{ |
66
|
|
|
$argumentDescriptor = new ArgumentDescriptor(); |
67
|
|
|
$argumentDescriptor->setTypes($type); |
|
|
|
|
68
|
|
|
$argumentDescriptor->setName($name); |
69
|
|
|
|
70
|
|
|
return $argumentDescriptor; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
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: