-
-
Notifications
You must be signed in to change notification settings - Fork 188
/
MethodReflection.php
135 lines (123 loc) · 3.71 KB
/
MethodReflection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
namespace Neos\Flow\Reflection;
/*
* This file is part of the Neos.Flow package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
use Neos\Flow\Annotations as Flow;
/**
* Extended version of the ReflectionMethod
*
* @Flow\Proxy(false)
*/
class MethodReflection extends \ReflectionMethod
{
/**
* @var DocCommentParser An instance of the doc comment parser
*/
protected $docCommentParser;
/**
* Returns the declaring class
*
* @return ClassReflection The declaring class
*/
public function getDeclaringClass(): ClassReflection
{
return new ClassReflection(parent::getDeclaringClass()->getName());
}
/**
* Replacement for the original getParameters() method which makes sure
* that ParameterReflection objects are returned instead of the
* original ReflectionParameter instances.
*
* @return array<ParameterReflection> objects of the parameters of this method
*/
public function getParameters(): array
{
$extendedParameters = [];
foreach (parent::getParameters() as $parameter) {
$extendedParameters[] = new ParameterReflection([$this->getDeclaringClass()->getName(), $this->getName()], $parameter->getName());
}
return $extendedParameters;
}
/**
* Checks if the doc comment of this method is tagged with
* the specified tag
*
* @param string $tag Tag name to check for
* @return boolean true if such a tag has been defined, otherwise false
*/
public function isTaggedWith($tag)
{
return $this->getDocCommentParser()->isTaggedWith($tag);
}
/**
* Returns an array of tags and their values
*
* @return array Tags and values
*/
public function getTagsValues()
{
return $this->getDocCommentParser()->getTagsValues();
}
/**
* Returns the values of the specified tag
*
* @param string $tag Tag name to check for
* @return array Values of the given tag
*/
public function getTagValues($tag)
{
return $this->getDocCommentParser()->getTagValues($tag);
}
/**
* Returns the description part of the doc comment
*
* @return string Doc comment description
*/
public function getDescription()
{
return $this->getDocCommentParser()->getDescription();
}
/**
* @return string|null The name of a type (e.g. string, \stdClass) if it was declared as a return type, null otherwise
*/
public function getDeclaredReturnType()
{
if (!is_callable([$this, 'getReturnType'])) {
return null;
}
$type = $this->getReturnType();
return $type !== null ? ltrim((string)$type, '?') : null;
}
/**
* @return bool Whether a return type is declared (@see getDeclaredReturnType()) and has a nullable modifier ("?")
*/
public function isDeclaredReturnTypeNullable()
{
if (!is_callable([$this, 'getReturnType'])) {
return false;
}
$type = $this->getReturnType();
return $type !== null && $type->allowsNull();
}
/**
* Returns an instance of the doc comment parser and
* runs the parse() method.
*
* @return DocCommentParser
*/
protected function getDocCommentParser()
{
if (!is_object($this->docCommentParser)) {
$this->docCommentParser = new DocCommentParser;
$this->docCommentParser->parseDocComment($this->getDocComment());
}
return $this->docCommentParser;
}
}