Skip to content

Commit

Permalink
[+]: quick-fix for missing namespaces
Browse files Browse the repository at this point in the history
-> TODO: check how to get the namespace via "PhpParser"
  • Loading branch information
voku committed Feb 15, 2022
1 parent 0353799 commit 8edca53
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
12 changes: 7 additions & 5 deletions src/voku/SimplePhpParser/Model/PHPFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ public function readObjectFromPhpNode($node, $dummy = null): self
}

if ($node->returnType) {
if (\method_exists($node->returnType, 'toString')) {
$this->returnType = $node->returnType->toString();
} elseif (\property_exists($node->returnType, 'name')) {
/** @psalm-suppress UndefinedPropertyFetch - FP? */
$this->returnType = $node->returnType->name;
if (!$this->returnType) {
if (\method_exists($node->returnType, 'toString')) {
$this->returnType = $node->returnType->toString();
} elseif (\property_exists($node->returnType, 'name')) {
/** @psalm-suppress UndefinedPropertyFetch - FP? */
$this->returnType = $node->returnType->name;
}
}

if ($node->returnType instanceof \PhpParser\Node\NullableType) {
Expand Down
12 changes: 7 additions & 5 deletions src/voku/SimplePhpParser/Model/PHPMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ public function readObjectFromPhpNode($node, $classStr = null): PHPFunction
}

if ($node->returnType) {
if (\method_exists($node->returnType, 'toString')) {
$this->returnType = $node->returnType->toString();
} elseif (\property_exists($node->returnType, 'name')) {
/** @psalm-suppress UndefinedPropertyFetch - FP? */
$this->returnType = $node->returnType->name;
if (!$this->returnType) {
if (\method_exists($node->returnType, 'toString')) {
$this->returnType = $node->returnType->toString();
} elseif (\property_exists($node->returnType, 'name')) {
/** @psalm-suppress UndefinedPropertyFetch - FP? */
$this->returnType = $node->returnType->name;
}
}

if ($node->returnType instanceof \PhpParser\Node\NullableType) {
Expand Down
12 changes: 7 additions & 5 deletions src/voku/SimplePhpParser/Model/PHPParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ public function readObjectFromPhpNode($parameter, $node = null, $classStr = null
}

if ($parameter->type !== null) {
if (empty($parameter->type->name)) {
if (!empty($parameter->type->parts)) {
$this->type = '\\' . \implode('\\', $parameter->type->parts);
if (!$this->type) {
if (empty($parameter->type->name)) {
if (!empty($parameter->type->parts)) {
$this->type = '\\' . \implode('\\', $parameter->type->parts);
}
} else {
$this->type = $parameter->type->name;
}
} else {
$this->type = $parameter->type->name;
}

if ($parameter->type instanceof \PhpParser\Node\NullableType) {
Expand Down
12 changes: 7 additions & 5 deletions src/voku/SimplePhpParser/Model/PHPProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,14 @@ public function readObjectFromPhpNode($node, $classStr = null): self
}

if ($node->type !== null) {
if (empty($node->type->name)) {
if (!empty($node->type->parts)) {
$this->type = '\\' . \implode('\\', $node->type->parts);
if (!$this->type) {
if (empty($node->type->name)) {
if (!empty($node->type->parts)) {
$this->type = '\\' . \implode('\\', $node->type->parts);
}
} else {
$this->type = $node->type->name;
}
} else {
$this->type = $node->type->name;
}

if ($node->type instanceof \PhpParser\Node\NullableType) {
Expand Down
7 changes: 5 additions & 2 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ public function testSimpleOneClassV2(): void
static::assertSame('lall4', $lall4->name);
static::assertSame('int', $lall4->typeFromPhpDoc);

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

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

$parsedParamTag = $withComplexReturnArray->parameters['parsedParamTag'];

static::assertSame('\phpDocumentor\Reflection\DocBlock\Tags\BaseTag', $parsedParamTag->type);
static::assertSame('\phpDocumentor\Reflection\DocBlock\Tags\BaseTag $parsedParamTag <p>this is a test-text [...] öäü !"§?</p>', $parsedParamTag->typeFromPhpDocMaybeWithComment);
}
Expand Down

0 comments on commit 8edca53

Please sign in to comment.