Skip to content

Commit

Permalink
Catch errors due to malformed tags (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
villfa authored May 12, 2021
1 parent 42e0a50 commit b4b98c7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Annotation/DocblockAnnotationParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use function array_map;
use function array_values;
use function in_array;
use InvalidArgumentException;
use phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock\Tags\Formatter;
use phpDocumentor\Reflection\DocBlockFactoryInterface;
Expand Down Expand Up @@ -47,7 +48,11 @@ public function __construct(DocBlockFactoryInterface $factory, Formatter $tagsFo
*/
public function parse(string $docblock): array
{
$doc = $this->factory->create($docblock);
try {
$doc = $this->factory->create($docblock);
} catch (InvalidArgumentException $e) {
throw new MalformedTagException('The annotations could not be parsed.', 0, $e);
}

$tags = array_values(
array_filter(
Expand Down
24 changes: 24 additions & 0 deletions src/Annotation/MalformedTagException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

/*
* This file is part of the box project.
*
* (c) Kevin Herrera <[email protected]>
* Théo Fidry <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace KevinGH\Box\Annotation;

use UnexpectedValueException;

/**
* @private
*/
final class MalformedTagException extends UnexpectedValueException
{
}

0 comments on commit b4b98c7

Please sign in to comment.