1 | <?php |
||
35 | class PhpMethod extends AbstractPhpMember { |
||
36 | |||
37 | use AbstractPart; |
||
38 | use BodyPart; |
||
39 | use FinalPart; |
||
40 | use ParametersPart; |
||
41 | use ReferenceReturnPart; |
||
42 | use TypeDocblockGeneratorPart; |
||
43 | |||
44 | /** |
||
45 | * Creates a new PHP method. |
||
46 | * |
||
47 | * @param string $name the method name |
||
48 | */ |
||
49 | 16 | public static function create($name) { |
|
50 | 16 | return new static($name); |
|
51 | } |
||
52 | |||
53 | /** |
||
54 | * Creates a PHP method from reflection |
||
55 | * |
||
56 | * @param \ReflectionMethod $ref |
||
57 | * @return PhpMethod |
||
58 | */ |
||
59 | 5 | public static function fromReflection(\ReflectionMethod $ref) { |
|
60 | 5 | $method = new static($ref->name); |
|
61 | 5 | $method->setFinal($ref->isFinal()) |
|
62 | 5 | ->setAbstract($ref->isAbstract()) |
|
63 | 5 | ->setStatic($ref->isStatic()) |
|
64 | 5 | ->setVisibility($ref->isPublic() |
|
65 | 5 | ? self::VISIBILITY_PUBLIC |
|
66 | 2 | : ($ref->isProtected() |
|
67 | 2 | ? self::VISIBILITY_PROTECTED |
|
68 | 5 | : self::VISIBILITY_PRIVATE)) |
|
69 | 5 | ->setReferenceReturned($ref->returnsReference()) |
|
70 | 5 | ->setBody(ReflectionUtils::getFunctionBody($ref)); |
|
71 | |||
72 | 5 | $docblock = new Docblock($ref); |
|
73 | 5 | $method->setDocblock($docblock); |
|
74 | 5 | $method->setDescription($docblock->getShortDescription()); |
|
75 | 5 | $method->setLongDescription($docblock->getLongDescription()); |
|
76 | |||
77 | // return type and description |
||
78 | 5 | $returns = $method->getDocblock()->getTags('return'); |
|
79 | 5 | if ($returns->size() > 0) { |
|
80 | $return = $returns->get(0); |
||
81 | $method->setType($return->getType(), $return->getDescription()); |
||
82 | } |
||
83 | |||
84 | // params |
||
85 | 5 | foreach ($ref->getParameters() as $param) { |
|
86 | 2 | $method->addParameter(static::createParameter($param)); |
|
87 | } |
||
88 | |||
89 | 5 | return $method; |
|
90 | } |
||
91 | |||
92 | /** |
||
93 | * Creates a parameter from reflection |
||
94 | * |
||
95 | * @return PhpParameter |
||
96 | */ |
||
97 | 2 | protected static function createParameter(\ReflectionParameter $parameter) { |
|
100 | |||
101 | /** |
||
102 | * Generates docblock based on provided information |
||
103 | */ |
||
104 | 11 | public function generateDocblock() { |
|
115 | } |
||
116 |