Skip to content

Commit c2f4a6c

Browse files
committed
Add exception TODOs
1 parent 89535d8 commit c2f4a6c

5 files changed

Lines changed: 30 additions & 17 deletions

File tree

libs/phpdoc/src/DocBlock/Tag/TagFactory.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
{
1111
public function create(string $name, string $suffix, DescriptionParserInterface $descriptions): TagInterface
1212
{
13-
// throw new \LogicException('asd');
14-
1513
return new Tag($name, $descriptions->tryParse($suffix));
1614
}
1715
}

libs/phpdoc/src/DocBlockParser.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use TypeLang\PhpDoc\Exception\ParsingExceptionInterface;
1414
use TypeLang\PhpDoc\Parser\Description\BalancedBraceAwareParser;
1515
use TypeLang\PhpDoc\Parser\Description\DescriptionParserInterface;
16-
use TypeLang\PhpDoc\Parser\SourceMap;
1716
use TypeLang\PhpDoc\Parser\Splitter\SplitterInterface;
1817
use TypeLang\PhpDoc\Parser\Splitter\StringSplitter;
1918
use TypeLang\PhpDoc\Parser\Tag\StringTagParser;
@@ -64,6 +63,7 @@ private function createTags(array $blocks): array
6463
$result = [];
6564

6665
foreach ($blocks as $block) {
66+
// TODO Add an internal exception handling
6767
$result[] = $this->tags->parse($block, $this->descriptions);
6868
}
6969

@@ -72,21 +72,17 @@ private function createTags(array $blocks): array
7272

7373
private function tryCreateDescription(string $description): ?DescriptionInterface
7474
{
75+
// TODO Add an internal exception handling
7576
return $this->descriptions->tryParse($description);
7677
}
7778

7879
public function parse(#[Language('InjectablePHP')] string $docblock): DocBlock
7980
{
80-
$map = new SourceMap();
81-
8281
$current = '';
8382
$blocks = [];
8483

8584
foreach ($this->splitter->split($docblock) as $segment) {
86-
$text = $segment->text;
87-
$offset = $segment->offset;
88-
89-
$map->addMapping($text, $offset);
85+
$segmentText = $segment->text;
9086

9187
// A segment starting with "@" opens a new tag section, flushing
9288
// whatever was accumulated for the previous one.
@@ -95,7 +91,7 @@ public function parse(#[Language('InjectablePHP')] string $docblock): DocBlock
9591
$current = '';
9692
}
9793

98-
$current .= $text;
94+
$current .= $segmentText;
9995
}
10096

10197
$blocks[] = $current;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\PhpDoc\Exception;
6+
7+
final class TagParsingException extends ParsingException
8+
{
9+
/**
10+
* @param int<0, max> $offset
11+
*/
12+
public static function becauseInternalErrorOccurs(
13+
\Throwable $previous,
14+
string $source,
15+
int $offset = 0,
16+
): self {
17+
return new self(
18+
source: $source,
19+
offset: $offset,
20+
message: $previous->getMessage(),
21+
previous: $previous,
22+
);
23+
}
24+
}

libs/phpdoc/src/Parser/Analyzer.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace TypeLang\PhpDoc\Parser;
66

7-
use TypeLang\PhpDoc\DocBlock\Description\DescriptionInterface;
87
use TypeLang\PhpDoc\DocBlock\DocBlock;
98
use TypeLang\PhpDoc\DocBlock\Tag\TagInterface;
109
use TypeLang\PhpDoc\Exception\ParsingExceptionInterface;
@@ -54,7 +53,7 @@ public function analyze(string $docblock): DocBlock
5453

5554
return new DocBlock(
5655
// The first section is always the description; the rest are tags.
57-
description: $this->tryCreateDescription(\array_shift($blocks)),
56+
description: $this->descriptions->tryParse(\array_shift($blocks)),
5857
tags: $this->createTags($blocks),
5958
);
6059
}
@@ -74,9 +73,4 @@ private function createTags(array $blocks): array
7473

7574
return $result;
7675
}
77-
78-
private function tryCreateDescription(string $description): ?DescriptionInterface
79-
{
80-
return $this->descriptions->tryParse($description);
81-
}
8276
}

libs/phpdoc/src/Parser/Description/BalancedBraceAwareParser.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ private function getComponents(string $description): array
8484

8585
// Strip the outer braces: "{@see X}" becomes "@see X".
8686
$definition = \substr($description, $open + 1, $close - $open - 1);
87+
// TODO Add an internal exception handling
8788
$tag = $this->tags->parse($definition, $this);
8889

8990
// A "{@...}" with an unreadable tag name is not a tag at all: keep

0 commit comments

Comments
 (0)