Skip to content

Commit

Permalink
Gracefully handle Docblock creation fails
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed Apr 28, 2020
1 parent 05ef983 commit a43f9a3
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/validators/Reflection/ValidatorReflection.php
Expand Up @@ -3,8 +3,8 @@

namespace hiapi\validators\Reflection;

use hiapi\commands\BaseCommand;
use hiapi\validators\IdValidator;
use phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\DocBlockFactory;
use phpDocumentor\Reflection\TypeResolver;
use phpDocumentor\Reflection\Types\ContextFactory;
Expand Down Expand Up @@ -66,23 +66,41 @@ public function getOpenApiType(): string
return 'string';
}

private function getDocBlock(): ?DocBlock
{
try {
return $this->docBlockFactory->create($this->reflection);
} catch (\InvalidArgumentException $e) {
return null;
}
}

public function getSummary(): string
{
$docBlock = $this->docBlockFactory->create($this->reflection);
$docBlock = $this->getDocBlock();
if ($docBlock === null) {
return '';
}

return $docBlock->getSummary();
}

public function getDescription(): string
{
$docBlock = $this->docBlockFactory->create($this->reflection);
$docBlock = $this->getDocBlock();
if ($docBlock === null) {
return '';
}

return $docBlock->getDescription()->__toString();
}

public function getExample(): ?string
{
$docBlock = $this->docBlockFactory->create($this->reflection);
$docBlock = $this->getDocBlock();
if ($docBlock === null) {
return null;
}

$examples = $docBlock->getTagsByName('example');
if (empty($examples)) {
Expand Down

0 comments on commit a43f9a3

Please sign in to comment.