Skip to content

Commit 5027630

Browse files
authored
Merge pull request #895 from phpDocumentor/backport/1.x/pr-891
[1.x] Merge pull request #891 from phpDocumentor/task/improve-warnings
2 parents cb1befb + 9437ff8 commit 5027630

File tree

7 files changed

+25
-8
lines changed

7 files changed

+25
-8
lines changed

packages/guides-restructured-text/src/RestructuredText/Directives/ConfigurationBlockDirective.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
use function assert;
2929
use function get_debug_type;
30+
use function sprintf;
3031

3132
final class ConfigurationBlockDirective extends SubDirective
3233
{
@@ -59,7 +60,10 @@ protected function processSub(
5960
$tabs = [];
6061
foreach ($collectionNode->getValue() as $child) {
6162
if (!$child instanceof CodeNode) {
62-
$this->logger->warning('The ".. configuration-block::" directive only supports code blocks, "' . get_debug_type($child) . '" given.');
63+
$this->logger->warning(
64+
sprintf('The ".. configuration-block::" directive only supports code blocks, "%s" given.', get_debug_type($child)),
65+
$blockContext->getLoggerInformation(),
66+
);
6367

6468
continue;
6569
}

packages/guides-restructured-text/src/RestructuredText/Directives/CsvTableDirective.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
use function array_filter;
2929
use function array_map;
30+
use function array_merge;
3031
use function assert;
3132
use function count;
3233
use function explode;
@@ -69,7 +70,10 @@ public function processNode(
6970
->readStream((string) $directive->getOption('file')->getValue());
7071

7172
if ($csvStream === false) {
72-
$this->logger->error('Unable to read CSV file {file}', ['file' => $directive->getOption('file')->getValue()]);
73+
$this->logger->error(
74+
'Unable to read CSV file {file}',
75+
array_merge(['file' => $directive->getOption('file')->getValue()], $blockContext->getLoggerInformation()),
76+
);
7377

7478
return new GenericNode('csv-table');
7579
}

packages/guides-restructured-text/src/RestructuredText/Directives/TableDirective.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,20 @@ protected function processSub(
6464
Directive $directive,
6565
): Node|null {
6666
if (count($collectionNode->getChildren()) !== 1) {
67-
$this->logger->warning(sprintf('The table directive may contain exactly one table. %s children found', count($collectionNode->getChildren())));
67+
$this->logger->warning(
68+
sprintf('The table directive may contain exactly one table. %s children found', count($collectionNode->getChildren())),
69+
$blockContext->getLoggerInformation(),
70+
);
6871

6972
return $collectionNode;
7073
}
7174

7275
$tableNode = $collectionNode->getChildren()[0];
7376
if (!$tableNode instanceof TableNode) {
74-
$this->logger->warning(sprintf('The table directive may contain exactly one table. A node of type %s was found. ', $tableNode::class));
77+
$this->logger->warning(
78+
sprintf('The table directive may contain exactly one table. A node of type %s was found. ', $tableNode::class),
79+
$blockContext->getLoggerInformation(),
80+
);
7581

7682
return $collectionNode;
7783
}

packages/guides-restructured-text/src/RestructuredText/NodeRenderers/Html/GeneralDirectiveNodeRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function render(Node $node, RenderContext $renderContext): string
5656
'No template found for rendering directive "%s". Expected template "%s"',
5757
$node->getName(),
5858
$template,
59-
));
59+
), $renderContext->getLoggerInformation());
6060
$template = 'body/directive/not-found.html.twig';
6161

6262
return $this->renderer->renderTemplate($renderContext, $template, $data);

packages/guides-restructured-text/src/RestructuredText/NodeRenderers/LaTeX/GeneralDirectiveNodeRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function render(Node $node, RenderContext $renderContext): string
5656
'No template found for rendering directive "%s". Expected template "%s"',
5757
$node->getName(),
5858
$template,
59-
));
59+
), $renderContext->getLoggerInformation());
6060
$template = 'body/directive/not-found.html.twig';
6161

6262
return $this->renderer->renderTemplate($renderContext, $template, $data);

packages/guides-theme-bootstrap/src/Bootstrap/Directives/TabsDirective.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ protected function processSub(
6969

7070
$tabs[] = $child;
7171
} else {
72-
$this->logger->warning('The "tabs" directive may only contain children of type "tab". The following node was found: ' . $child::class);
72+
$this->logger->warning(
73+
'The "tabs" directive may only contain children of type "tab". The following node was found: ' . $child::class,
74+
$blockContext->getLoggerInformation(),
75+
);
7376
}
7477
}
7578

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
app.WARNING: No template found for rendering directive "some-unknown-directive". Expected template "body/directive/some-unknown-directive.html.twig" [] []
1+
app.WARNING: No template found for rendering directive "some-unknown-directive". Expected template "body/directive/some-unknown-directive.html.twig" {"rst-file":"index"} []

0 commit comments

Comments
 (0)