Skip to content

Commit 8edca53

Browse files
committed
[+]: quick-fix for missing namespaces
-> TODO: check how to get the namespace via "PhpParser"
1 parent 0353799 commit 8edca53

File tree

5 files changed

+33
-22
lines changed

5 files changed

+33
-22
lines changed

src/voku/SimplePhpParser/Model/PHPFunction.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ public function readObjectFromPhpNode($node, $dummy = null): self
7979
}
8080

8181
if ($node->returnType) {
82-
if (\method_exists($node->returnType, 'toString')) {
83-
$this->returnType = $node->returnType->toString();
84-
} elseif (\property_exists($node->returnType, 'name')) {
85-
/** @psalm-suppress UndefinedPropertyFetch - FP? */
86-
$this->returnType = $node->returnType->name;
82+
if (!$this->returnType) {
83+
if (\method_exists($node->returnType, 'toString')) {
84+
$this->returnType = $node->returnType->toString();
85+
} elseif (\property_exists($node->returnType, 'name')) {
86+
/** @psalm-suppress UndefinedPropertyFetch - FP? */
87+
$this->returnType = $node->returnType->name;
88+
}
8789
}
8890

8991
if ($node->returnType instanceof \PhpParser\Node\NullableType) {

src/voku/SimplePhpParser/Model/PHPMethod.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ public function readObjectFromPhpNode($node, $classStr = null): PHPFunction
7373
}
7474

7575
if ($node->returnType) {
76-
if (\method_exists($node->returnType, 'toString')) {
77-
$this->returnType = $node->returnType->toString();
78-
} elseif (\property_exists($node->returnType, 'name')) {
79-
/** @psalm-suppress UndefinedPropertyFetch - FP? */
80-
$this->returnType = $node->returnType->name;
76+
if (!$this->returnType) {
77+
if (\method_exists($node->returnType, 'toString')) {
78+
$this->returnType = $node->returnType->toString();
79+
} elseif (\property_exists($node->returnType, 'name')) {
80+
/** @psalm-suppress UndefinedPropertyFetch - FP? */
81+
$this->returnType = $node->returnType->name;
82+
}
8183
}
8284

8385
if ($node->returnType instanceof \PhpParser\Node\NullableType) {

src/voku/SimplePhpParser/Model/PHPParameter.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,14 @@ public function readObjectFromPhpNode($parameter, $node = null, $classStr = null
102102
}
103103

104104
if ($parameter->type !== null) {
105-
if (empty($parameter->type->name)) {
106-
if (!empty($parameter->type->parts)) {
107-
$this->type = '\\' . \implode('\\', $parameter->type->parts);
105+
if (!$this->type) {
106+
if (empty($parameter->type->name)) {
107+
if (!empty($parameter->type->parts)) {
108+
$this->type = '\\' . \implode('\\', $parameter->type->parts);
109+
}
110+
} else {
111+
$this->type = $parameter->type->name;
108112
}
109-
} else {
110-
$this->type = $parameter->type->name;
111113
}
112114

113115
if ($parameter->type instanceof \PhpParser\Node\NullableType) {

src/voku/SimplePhpParser/Model/PHPProperty.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,14 @@ public function readObjectFromPhpNode($node, $classStr = null): self
9595
}
9696

9797
if ($node->type !== null) {
98-
if (empty($node->type->name)) {
99-
if (!empty($node->type->parts)) {
100-
$this->type = '\\' . \implode('\\', $node->type->parts);
98+
if (!$this->type) {
99+
if (empty($node->type->name)) {
100+
if (!empty($node->type->parts)) {
101+
$this->type = '\\' . \implode('\\', $node->type->parts);
102+
}
103+
} else {
104+
$this->type = $node->type->name;
101105
}
102-
} else {
103-
$this->type = $node->type->name;
104106
}
105107

106108
if ($node->type instanceof \PhpParser\Node\NullableType) {

tests/ParserTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ public function testSimpleOneClassV2(): void
3636
static::assertSame('lall4', $lall4->name);
3737
static::assertSame('int', $lall4->typeFromPhpDoc);
3838

39-
$withComplexReturnArray = $phpClasses[Dummy3::class]->methods['withComplexReturnArray'];
39+
$lall11 = $phpClasses[Dummy3::class]->methods['lall11'];
40+
static::assertSame('lall11', $lall11->name);
41+
static::assertSame('voku\tests\DummyInterface', $lall11->returnType);
42+
static::assertSame('\voku\tests\Dummy3', $lall11->returnTypeFromPhpDocMaybeWithComment);
4043

44+
$withComplexReturnArray = $phpClasses[Dummy3::class]->methods['withComplexReturnArray'];
4145
static::assertSame('withComplexReturnArray', $withComplexReturnArray->name);
4246
static::assertSame('This is a test-text [...] öäü !"§?.', $withComplexReturnArray->summary . $withComplexReturnArray->description);
4347

4448
$parsedParamTag = $withComplexReturnArray->parameters['parsedParamTag'];
45-
4649
static::assertSame('\phpDocumentor\Reflection\DocBlock\Tags\BaseTag', $parsedParamTag->type);
4750
static::assertSame('\phpDocumentor\Reflection\DocBlock\Tags\BaseTag $parsedParamTag <p>this is a test-text [...] öäü !"§?</p>', $parsedParamTag->typeFromPhpDocMaybeWithComment);
4851
}

0 commit comments

Comments
 (0)