Skip to content

Commit 8ee1cd1

Browse files
committed
Optimization
1 parent 8eeaa96 commit 8ee1cd1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/PhpDocReader/PhpDocReader.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ public function __construct()
3737
*/
3838
public function getPropertyType(ReflectionProperty $property)
3939
{
40-
$class = $property->getDeclaringClass();
41-
4240
// Get the content of the @var annotation
4341
if (preg_match('/@var\s+([^\s]+)/', $property->getDocComment(), $matches)) {
4442
list(, $type) = $matches;
4543
} else {
4644
return null;
4745
}
4846

47+
$class = $property->getDeclaringClass();
48+
4949
// If the class name is not fully qualified (i.e. doesn't start with a \)
5050
if ($type[0] !== '\\') {
5151
$alias = (false === $pos = strpos($type, '\\')) ? $type : substr($type, 0, $pos);
@@ -103,9 +103,6 @@ public function getPropertyType(ReflectionProperty $property)
103103
*/
104104
public function getParameterType(ReflectionParameter $parameter)
105105
{
106-
$method = $parameter->getDeclaringFunction();
107-
$class = $parameter->getDeclaringClass();
108-
109106
// Use reflection
110107
$parameterClass = $parameter->getClass();
111108
if ($parameterClass !== null) {
@@ -114,12 +111,15 @@ public function getParameterType(ReflectionParameter $parameter)
114111

115112
$parameterName = $parameter->name;
116113
// Get the content of the @param annotation
114+
$method = $parameter->getDeclaringFunction();
117115
if (preg_match('/@param\s+([^\s]+)\s+\$' . $parameterName . '/', $method->getDocComment(), $matches)) {
118116
list(, $type) = $matches;
119117
} else {
120118
return null;
121119
}
122120

121+
$class = $parameter->getDeclaringClass();
122+
123123
// If the class name is not fully qualified (i.e. doesn't start with a \)
124124
if ($type[0] !== '\\') {
125125
$alias = (false === $pos = strpos($type, '\\')) ? $type : substr($type, 0, $pos);

0 commit comments

Comments
 (0)