Skip to content

Commit f320dfe

Browse files
authored
Merge branch 'main' into per-project-settings-docs
2 parents c254e5a + 12cbf35 commit f320dfe

File tree

23 files changed

+129
-109
lines changed

23 files changed

+129
-109
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
5454
"doctrine/coding-standard": "^12.0",
5555
"fakerphp/faker": "^1.23",
56+
"fig/log-test": "^1.0",
5657
"gajus/dindent": "^2.0.1",
5758
"jangregor/phpstan-prophecy": "^1.0",
5859
"league/flysystem-memory": "^1.0",

composer.lock

Lines changed: 47 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/guides-graphs/src/Graphs/Directives/UmlDirective.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use phpDocumentor\Guides\RestructuredText\Directives\BaseDirective;
1111
use phpDocumentor\Guides\RestructuredText\Parser\Directive;
1212
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
13+
use Psr\Log\LoggerInterface;
1314
use Webmozart\Assert\Assert;
1415

1516
use function dirname;
@@ -34,6 +35,10 @@
3435
*/
3536
final class UmlDirective extends BaseDirective
3637
{
38+
public function __construct(private readonly LoggerInterface $logger)
39+
{
40+
}
41+
3742
public function getName(): string
3843
{
3944
return 'uml';
@@ -72,9 +77,11 @@ private function loadExternalUmlFile(ParserContext $parserContext, string $path)
7277
);
7378

7479
if (!$parserContext->getOrigin()->has($fileName)) {
75-
$parserContext->addError(
76-
sprintf('Tried to include "%s" as a diagram but the file could not be found', $fileName),
77-
);
80+
$message =
81+
sprintf('Tried to include "%s" as a diagram but the file could not be found', $fileName);
82+
83+
84+
$this->logger->error($message, $parserContext->getLoggerInformation());
7885

7986
return null;
8087
}

packages/guides-restructured-text/resources/config/guides-restructured-text.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
use phpDocumentor\Guides\RestructuredText\Parser\Productions\RuleContainer;
8080
use phpDocumentor\Guides\RestructuredText\Parser\Productions\SectionRule;
8181
use phpDocumentor\Guides\RestructuredText\Parser\Productions\SimpleTableRule;
82+
use phpDocumentor\Guides\RestructuredText\Parser\Productions\Table\GridTableBuilder;
8283
use phpDocumentor\Guides\RestructuredText\Parser\Productions\TitleRule;
8384
use phpDocumentor\Guides\RestructuredText\Parser\Productions\TransitionRule;
8485
use phpDocumentor\Guides\RestructuredText\TextRoles\AbbreviationTextRole;
@@ -214,6 +215,7 @@
214215
->set(GridTableRule::class)
215216
->arg('$productions', service('phpdoc.guides.parser.rst.body_elements'))
216217
->tag('phpdoc.guides.parser.rst.body_element', ['priority' => GridTableRule::PRIORITY])
218+
->set(GridTableBuilder::class)
217219
->set(SimpleTableRule::class)
218220
->arg('$productions', service('phpdoc.guides.parser.rst.body_elements'))
219221
->tag('phpdoc.guides.parser.rst.body_element', ['priority' => SimpleTableRule::PRIORITY])

packages/guides-restructured-text/src/RestructuredText/Parser/Productions/DirectiveRule.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use phpDocumentor\Guides\RestructuredText\Parser\DirectiveOption;
2323
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
2424
use phpDocumentor\Guides\RestructuredText\Parser\LinesIterator;
25+
use Psr\Log\LoggerInterface;
2526
use Throwable;
2627

2728
use function array_merge;
@@ -52,6 +53,7 @@ final class DirectiveRule implements Rule
5253
/** @param iterable<DirectiveHandler> $directives */
5354
public function __construct(
5455
private readonly InlineMarkupRule $inlineMarkupRule,
56+
private readonly LoggerInterface $logger,
5557
iterable $directives = [],
5658
) {
5759
foreach ($directives as $directive) {
@@ -101,7 +103,7 @@ public function apply(DocumentParserContext $documentParserContext, CompoundNode
101103
$openingLine,
102104
);
103105

104-
$documentParserContext->getContext()->addError($message);
106+
$this->logger->error($message, $documentParserContext->getContext()->getLoggerInformation());
105107

106108
return null;
107109
}
@@ -140,7 +142,8 @@ public function apply(DocumentParserContext $documentParserContext, CompoundNode
140142
$e->getMessage(),
141143
);
142144

143-
$documentParserContext->getContext()->addError($message);
145+
146+
$this->logger->error($message, $documentParserContext->getContext()->getLoggerInformation());
144147
}
145148

146149
return null;

packages/guides-restructured-text/src/RestructuredText/Parser/Productions/GridTableRule.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use phpDocumentor\Guides\RestructuredText\Parser\Productions\Table\GridTableBuilder;
2222
use phpDocumentor\Guides\RestructuredText\Parser\Productions\Table\ParserContext;
2323
use phpDocumentor\Guides\RestructuredText\Parser\Productions\Table\TableSeparatorLineConfig;
24+
use Psr\Log\LoggerInterface;
2425

2526
use function mb_strlen;
2627
use function preg_match;
@@ -37,11 +38,8 @@ final class GridTableRule implements Rule
3738
{
3839
public const PRIORITY = 50;
3940

40-
private readonly GridTableBuilder $builder;
41-
42-
public function __construct(private readonly RuleContainer $productions)
41+
public function __construct(private readonly LoggerInterface $logger, private readonly RuleContainer $productions, private readonly GridTableBuilder $builder)
4342
{
44-
$this->builder = new GridTableBuilder();
4543
}
4644

4745
public function applies(DocumentParserContext $documentParser): bool
@@ -68,10 +66,12 @@ public function apply(DocumentParserContext $documentParserContext, CompoundNode
6866
$documentIterator->next();
6967

7068
if ($lineLength !== mb_strlen($documentIterator->current())) {
71-
$documentParserContext->getContext()->addError(sprintf(
69+
$message = sprintf(
7270
"Malformed table: Line\n\n%s\n\ndoes not appear to be a complete table row",
7371
$documentIterator->current(),
74-
));
72+
);
73+
74+
$this->logger->error($message, $documentParserContext->getContext()->getLoggerInformation());
7575
}
7676

7777
if ($this->isHeaderDefinitionLine($documentIterator->current())) {

packages/guides-restructured-text/src/RestructuredText/Parser/Productions/Table/GridTableBuilder.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use phpDocumentor\Guides\Nodes\TableNode;
1414
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
1515
use phpDocumentor\Guides\RestructuredText\Parser\Productions\RuleContainer;
16+
use Psr\Log\LoggerInterface;
1617

1718
use function array_reverse;
1819
use function count;
@@ -26,6 +27,10 @@
2627

2728
class GridTableBuilder
2829
{
30+
public function __construct(private readonly LoggerInterface $logger)
31+
{
32+
}
33+
2934
protected function compile(ParserContext $context): TableNode
3035
{
3136
$columnRanges = $context->getColumnRanges();
@@ -153,7 +158,7 @@ protected function compile(ParserContext $context): TableNode
153158
try {
154159
$row->absorbRowContent($targetRow);
155160
} catch (InvalidTableStructure $e) {
156-
$context->addError($e->getMessage());
161+
$this->logger->error($e->getMessage());
157162
}
158163

159164
$nextRowCounter++;
@@ -207,13 +212,13 @@ public function buildNode(
207212
if ($tableParserContext->hasErrors()) {
208213
$tableAsString = $tableParserContext->getTableAsString();
209214
foreach ($tableParserContext->getErrors() as $error) {
210-
$documentParserContext->getContext()
211-
->addError(sprintf(
212-
"%s\nin file %s\n\n%s",
213-
$error,
214-
$documentParserContext->getContext()->getCurrentFileName(),
215-
$tableAsString,
216-
));
215+
$message = sprintf(
216+
"%s\nin file %s\n\n%s",
217+
$error,
218+
$documentParserContext->getContext()->getCurrentFileName(),
219+
$tableAsString,
220+
);
221+
$this->logger->error($message, $documentParserContext->getContext()->getLoggerInformation());
217222
}
218223

219224
return null;

packages/guides-restructured-text/tests/unit/Parser/Productions/DirectiveRuleTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace phpDocumentor\Guides\RestructuredText\Parser\Productions;
66

7+
use Monolog\Logger;
78
use phpDocumentor\Guides\Nodes\CodeNode;
89
use phpDocumentor\Guides\RestructuredText\Directives\BaseDirective as DirectiveHandler;
910
use phpDocumentor\Guides\RestructuredText\Directives\CodeBlockDirective;
@@ -22,7 +23,7 @@ final class DirectiveRuleTest extends RuleTestCase
2223
public function setUp(): void
2324
{
2425
$this->directiveHandler = new DummyBaseDirective();
25-
$this->rule = new DirectiveRule($this->givenInlineMarkupRule(), [$this->directiveHandler]);
26+
$this->rule = new DirectiveRule($this->givenInlineMarkupRule(), new Logger('test'), [$this->directiveHandler]);
2627
}
2728

2829
#[DataProvider('simpleDirectiveProvider')]
@@ -92,7 +93,7 @@ public function testApplySetsOptionValueMultipleLines(): void
9293
#[DataProvider('codeBlockValueProvider')]
9394
public function testCodeBlockValue(string $input, string $expectedValue): void
9495
{
95-
$this->rule = new DirectiveRule($this->givenInlineMarkupRule(), [$this->directiveHandler, new CodeBlockDirective(new CodeNodeOptionMapper())]);
96+
$this->rule = new DirectiveRule($this->givenInlineMarkupRule(), new Logger('test'), [$this->directiveHandler, new CodeBlockDirective(new CodeNodeOptionMapper())]);
9697
$context = $this->createContext($input);
9798
$node = $this->rule->apply($context);
9899
self::assertInstanceOf(CodeNode::class, $node);

0 commit comments

Comments
 (0)