Skip to content

Commit 37f375b

Browse files
committed
Fix deprecations in the codebase
1 parent ca2098e commit 37f375b

File tree

31 files changed

+146
-107
lines changed

31 files changed

+146
-107
lines changed
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
{% apply spaceless %}
2-
<figure
3-
class="uml-diagram{% if node.classesString %} {{ node.classesString }}{% endif %}"
4-
{% if node.hasOption('width') %}style="width: {{ node.option('width') }}"{% endif %}
5-
>
6-
{{ uml(node.value) }}
7-
{% if node.caption %}<figcaption>{{ node.caption }}</figcaption>{% endif %}
8-
</figure>
9-
{% endapply %}
1+
<figure class="uml-diagram{% if node.classesString %} {{ node.classesString }}{% endif %}"
2+
{%- if node.hasOption('width') %} style="width: {{ node.option('width') }}"{% endif -%}
3+
>
4+
{{ uml(node.value) }}
5+
{% if node.caption %}
6+
<figcaption>{{ node.caption }}</figcaption>
7+
{% endif %}
8+
</figure>

packages/guides-markdown/src/Markdown/Parsers/InlineParsers/EmphasisParser.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use phpDocumentor\Guides\Nodes\Inline\InlineNode;
2020
use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface;
2121
use Psr\Log\LoggerInterface;
22+
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
2223

2324
/** @extends AbstractInlineTextDecoratorParser<EmphasisInlineNode> */
2425
final class EmphasisParser extends AbstractInlineTextDecoratorParser
@@ -39,7 +40,7 @@ protected function getType(): string
3940
/** @param InlineNodeInterface[] $children */
4041
protected function createInlineNode(CommonMarkNode $commonMarkNode, string|null $content, array $children = []): InlineNodeInterface
4142
{
42-
return new EmphasisInlineNode($content ?? '', $children);
43+
return new EmphasisInlineNode($content ? [new PlainTextInlineNode($content)] : $children);
4344
}
4445

4546
protected function supportsCommonMarkNode(CommonMarkNode $commonMarkNode): bool

packages/guides-markdown/src/Markdown/Parsers/InlineParsers/LinkParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface;
2121
use Psr\Log\LoggerInterface;
2222

23+
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
2324
use function assert;
2425
use function filter_var;
2526
use function str_ends_with;
@@ -48,13 +49,12 @@ protected function createInlineNode(CommonMarkNode $commonMarkNode, string|null
4849
{
4950
assert($commonMarkNode instanceof Link);
5051

51-
$content ??= $commonMarkNode->getUrl();
5252
$url = $commonMarkNode->getUrl();
5353
if (str_ends_with($url, '.md') && filter_var($url, FILTER_VALIDATE_URL) === false) {
5454
$url = substr($url, 0, -3);
5555
}
5656

57-
return new HyperLinkNode($content, $url, $children);
57+
return new HyperLinkNode($content ? [new PlainTextInlineNode($content)] : $children, $url);
5858
}
5959

6060
protected function supportsCommonMarkNode(CommonMarkNode $commonMarkNode): bool

packages/guides-markdown/src/Markdown/Parsers/InlineParsers/StrongParser.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use League\CommonMark\Node\Node as CommonMarkNode;
1818
use phpDocumentor\Guides\Nodes\Inline\InlineNode;
1919
use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface;
20+
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
2021
use phpDocumentor\Guides\Nodes\Inline\StrongInlineNode;
2122
use Psr\Log\LoggerInterface;
2223

@@ -39,7 +40,7 @@ protected function getType(): string
3940
/** @param InlineNodeInterface[] $children */
4041
protected function createInlineNode(CommonMarkNode $commonMarkNode, string|null $content, array $children = []): InlineNodeInterface
4142
{
42-
return new StrongInlineNode($content ?? '', $children);
43+
return new StrongInlineNode($content ? [new PlainTextInlineNode($content)] : $children);
4344
}
4445

4546
protected function supportsCommonMarkNode(CommonMarkNode $commonMarkNode): bool

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,21 @@ public function processNode(
7777
private function resolveLinkTarget(string $targetReference): LinkInlineNode
7878
{
7979
if (filter_var($targetReference, FILTER_VALIDATE_EMAIL)) {
80-
return new HyperLinkNode('', $targetReference);
80+
return new HyperLinkNode([], $targetReference);
8181
}
8282

8383
if (filter_var($targetReference, FILTER_VALIDATE_URL)) {
84-
return new HyperLinkNode('', $targetReference);
84+
return new HyperLinkNode([], $targetReference);
8585
}
8686

8787
if (preg_match(self::REFERENCE_REGEX, $targetReference, $matches)) {
88-
return new ReferenceNode($matches[1], '');
88+
return new ReferenceNode($matches[1]);
8989
}
9090

9191
if (preg_match(self::REFERENCE_ESCAPED_REGEX, $targetReference, $matches)) {
92-
return new ReferenceNode($matches[1], '');
92+
return new ReferenceNode($matches[1]);
9393
}
9494

95-
return new DocReferenceNode($targetReference, '');
95+
return new DocReferenceNode($targetReference);
9696
}
9797
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use phpDocumentor\Guides\Nodes\Inline\EmphasisInlineNode;
1717
use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface;
18+
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
1819
use phpDocumentor\Guides\RestructuredText\Parser\BlockContext;
1920
use phpDocumentor\Guides\RestructuredText\Parser\InlineLexer;
2021

@@ -45,7 +46,7 @@ public function apply(BlockContext $blockContext, InlineLexer $lexer): InlineNod
4546

4647
$lexer->moveNext();
4748

48-
return new EmphasisInlineNode($text);
49+
return new EmphasisInlineNode([new PlainTextInlineNode($text)]);
4950

5051
default:
5152
$text .= $token->value;

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use phpDocumentor\Guides\Nodes\Inline\AbstractLinkInlineNode;
1717
use phpDocumentor\Guides\Nodes\Inline\DocReferenceNode;
1818
use phpDocumentor\Guides\Nodes\Inline\HyperLinkNode;
19+
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
1920
use phpDocumentor\Guides\RestructuredText\Parser\BlockContext;
2021

2122
use function filter_var;
@@ -39,13 +40,17 @@ protected function createReference(BlockContext $blockContext, string $reference
3940
if (str_ends_with($reference, '.rst') && filter_var($reference, FILTER_VALIDATE_URL) === false) {
4041
$reference = substr($reference, 0, -4);
4142

42-
return new DocReferenceNode($reference, $text ?? $reference);
43+
$text ??= $reference;
44+
45+
return new DocReferenceNode($reference, $text !== '' ? [new PlainTextInlineNode($text)] : []);
4346
}
4447

4548
if ($registerLink && $text !== null) {
4649
$blockContext->getDocumentParserContext()->setLink($text, $reference);
4750
}
4851

49-
return new HyperLinkNode($text ?? $reference, $reference);
52+
$text ??= $reference;
53+
54+
return new HyperLinkNode($text !== '' ? [new PlainTextInlineNode($text)] : [], $reference);
5055
}
5156
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace phpDocumentor\Guides\RestructuredText\Parser\Productions\InlineRules;
1515

1616
use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface;
17+
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
1718
use phpDocumentor\Guides\Nodes\Inline\StrongInlineNode;
1819
use phpDocumentor\Guides\RestructuredText\Parser\BlockContext;
1920
use phpDocumentor\Guides\RestructuredText\Parser\InlineLexer;
@@ -45,7 +46,7 @@ public function apply(BlockContext $blockContext, InlineLexer $lexer): InlineNod
4546

4647
$lexer->moveNext();
4748

48-
return new StrongInlineNode($text);
49+
return new StrongInlineNode([new PlainTextInlineNode($text)]);
4950

5051
default:
5152
$text .= $token->value;

packages/guides-restructured-text/src/RestructuredText/TextRoles/ApiClassTextRole.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace phpDocumentor\Guides\RestructuredText\TextRoles;
1515

1616
use phpDocumentor\Guides\Nodes\Inline\AbstractLinkInlineNode;
17+
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
1718
use phpDocumentor\Guides\Nodes\Inline\ReferenceNode;
1819
use phpDocumentor\Guides\ReferenceResolvers\AnchorNormalizer;
1920
use phpDocumentor\Guides\RestructuredText\Parser\Interlink\InterlinkParser;
@@ -49,6 +50,6 @@ protected function createNode(string $referenceTarget, string|null $referenceNam
4950
$reference = $this->anchorReducer->reduceAnchor($interlinkData->reference);
5051
$prefix = $this->genericLinkProvider->getLinkPrefix($role);
5152

52-
return new ReferenceNode($reference, $referenceName ?? '', $interlinkData->interlink, self::TYPE, $prefix);
53+
return new ReferenceNode($reference, $referenceName ? [new PlainTextInlineNode($referenceName)] : [], $interlinkData->interlink, self::TYPE, $prefix);
5354
}
5455
}

packages/guides-restructured-text/src/RestructuredText/TextRoles/DocReferenceTextRole.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use phpDocumentor\Guides\Nodes\Inline\AbstractLinkInlineNode;
1717
use phpDocumentor\Guides\Nodes\Inline\DocReferenceNode;
18+
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
1819
use phpDocumentor\Guides\RestructuredText\Parser\Interlink\InterlinkParser;
1920

2021
/**
@@ -51,6 +52,6 @@ protected function createNode(string $referenceTarget, string|null $referenceNam
5152
{
5253
$interlinkData = $this->interlinkParser->extractInterlink($referenceTarget);
5354

54-
return new DocReferenceNode($interlinkData->reference, $referenceName ?? '', $interlinkData->interlink);
55+
return new DocReferenceNode($interlinkData->reference, $referenceName ? [new PlainTextInlineNode($referenceName)] : [], $interlinkData->interlink);
5556
}
5657
}

packages/guides-restructured-text/src/RestructuredText/TextRoles/GenericReferenceTextRole.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace phpDocumentor\Guides\RestructuredText\TextRoles;
1515

1616
use phpDocumentor\Guides\Nodes\Inline\AbstractLinkInlineNode;
17+
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
1718
use phpDocumentor\Guides\Nodes\Inline\ReferenceNode;
1819
use phpDocumentor\Guides\ReferenceResolvers\AnchorNormalizer;
1920
use phpDocumentor\Guides\RestructuredText\Parser\Interlink\InterlinkParser;
@@ -48,6 +49,12 @@ protected function createNode(string $referenceTarget, string|null $referenceNam
4849
$reference = $this->anchorReducer->reduceAnchor($interlinkData->reference);
4950
$prefix = $this->genericLinkProvider->getLinkPrefix($role);
5051

51-
return new ReferenceNode($reference, $referenceName ?? '', $interlinkData->interlink, $linkType, $prefix);
52+
return new ReferenceNode(
53+
$reference,
54+
$referenceName ? [new PlainTextInlineNode($referenceName)] : [],
55+
$interlinkData->interlink,
56+
$linkType,
57+
$prefix
58+
);
5259
}
5360
}

packages/guides-restructured-text/src/RestructuredText/TextRoles/ReferenceTextRole.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace phpDocumentor\Guides\RestructuredText\TextRoles;
1515

1616
use phpDocumentor\Guides\Nodes\Inline\AbstractLinkInlineNode;
17+
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
1718
use phpDocumentor\Guides\Nodes\Inline\ReferenceNode;
1819

1920
final class ReferenceTextRole extends AbstractReferenceTextRole
@@ -34,6 +35,6 @@ public function getAliases(): array
3435
/** @return ReferenceNode */
3536
protected function createNode(string $referenceTarget, string|null $referenceName, string $role): AbstractLinkInlineNode
3637
{
37-
return new ReferenceNode($referenceTarget, $referenceName ?? '');
38+
return new ReferenceNode($referenceTarget, $referenceName ? [new PlainTextInlineNode($referenceName)] : []);
3839
}
3940
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
*{{- node.value|raw -}}*
1+
*{{- node|plaintext -}}*
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{%- if node.url -%}
2-
`{{ node.value|raw }} <{{- node.url -}}>`__
2+
`{{ node|plaintext }} <{{- node.url -}}>`__
33
{%- elseif node.targetReference -%}
4-
:doc:`{{ node.value|raw }} <{{- node.targetReference -}}>`
4+
:doc:`{{ node|plaintext }} <{{- node.targetReference -}}>`
55
{%- else -%}
6-
{{- node.value -}}
6+
{{- node|plaintext -}}
77
{%- endif -%}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
**{{- node.value|raw -}}**
1+
**{{- node|plaintext -}}**

packages/guides-theme-rst/src/RstTheme/Twig/RstExtension.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
namespace phpDocumentor\Guides\RstTheme\Twig;
1515

1616
use phpDocumentor\Guides\NodeRenderers\NodeRenderer;
17+
use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface;
18+
use phpDocumentor\Guides\Nodes\InlineCompoundNode;
1719
use phpDocumentor\Guides\Nodes\Table\TableColumn;
1820
use phpDocumentor\Guides\Nodes\Table\TableRow;
1921
use phpDocumentor\Guides\Nodes\TableNode;
@@ -57,14 +59,24 @@ public function getFunctions(): array
5759
public function getFilters(): array
5860
{
5961
return [
60-
new TwigFilter('clean_content', [$this, 'cleanContent']),
62+
new TwigFilter('clean_content', $this->cleanContent(...)),
63+
new TwigFilter('plaintext', $this->plaintext(...)),
6164
];
6265
}
6366

67+
public function plaintext(InlineNodeInterface $node): string
68+
{
69+
if ($node instanceof InlineCompoundNode) {
70+
return implode('', array_map($this->plaintext(...), $node->getChildren()));
71+
}
72+
73+
return $node->toString();
74+
}
75+
6476
public function cleanContent(string $content): string
6577
{
6678
$lines = explode("\n", $content);
67-
$lines = array_map('rtrim', $lines);
79+
$lines = array_map(rtrim(...), $lines);
6880
$content = implode("\n", $lines);
6981

7082
$content = preg_replace('/(\n){2,}/', "\n\n", $content);

packages/guides/src/Nodes/Inline/AbstractLinkInlineNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function getDebugInformation(): array
7474
return [
7575
'type' => $this->getType(),
7676
'targetReference' => $this->getTargetReference(),
77-
'value' => $this->getValue(),
77+
'value' => $this->toString(),
7878
];
7979
}
8080

packages/guides/src/ReferenceResolvers/AnchorHyperlinkResolver.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515

1616
use phpDocumentor\Guides\Nodes\Inline\HyperLinkNode;
1717
use phpDocumentor\Guides\Nodes\Inline\LinkInlineNode;
18+
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
1819
use phpDocumentor\Guides\Nodes\SectionNode;
1920
use phpDocumentor\Guides\RenderContext;
2021
use phpDocumentor\Guides\Renderer\UrlGenerator\UrlGeneratorInterface;
2122

23+
use function count;
24+
2225
/**
2326
* Resolves references with an anchor URL.
2427
*
@@ -51,8 +54,8 @@ public function resolve(LinkInlineNode $node, RenderContext $renderContext, Mess
5154
}
5255

5356
$node->setUrl($this->urlGenerator->generateCanonicalOutputUrl($renderContext, $target->getDocumentPath(), $target->getAnchor()));
54-
if ($node->getValue() === '') {
55-
$node->setValue($target->getTitle() ?? '');
57+
if (count($node->getChildren()) === 0) {
58+
$node->addChildNode(new PlainTextInlineNode($target->getTitle() ?? ''));
5659
}
5760

5861
return true;

packages/guides/src/ReferenceResolvers/AnchorReferenceResolver.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
namespace phpDocumentor\Guides\ReferenceResolvers;
1515

1616
use phpDocumentor\Guides\Nodes\Inline\LinkInlineNode;
17+
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
1718
use phpDocumentor\Guides\Nodes\Inline\ReferenceNode;
1819
use phpDocumentor\Guides\RenderContext;
1920
use phpDocumentor\Guides\Renderer\UrlGenerator\UrlGeneratorInterface;
2021

22+
use function count;
23+
2124
/**
2225
* Resolves references with an anchor URL.
2326
*
@@ -47,8 +50,8 @@ public function resolve(LinkInlineNode $node, RenderContext $renderContext, Mess
4750
}
4851

4952
$node->setUrl($this->urlGenerator->generateCanonicalOutputUrl($renderContext, $target->getDocumentPath(), $target->getPrefix() . $target->getAnchor()));
50-
if ($node->getValue() === '') {
51-
$node->setValue($target->getTitle() ?? '');
53+
if (count($node->getChildren()) === 0) {
54+
$node->addChildNode(new PlainTextInlineNode($target->getTitle() ?? ''));
5255
}
5356

5457
return true;

packages/guides/src/ReferenceResolvers/DocReferenceResolver.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515

1616
use phpDocumentor\Guides\Nodes\Inline\DocReferenceNode;
1717
use phpDocumentor\Guides\Nodes\Inline\LinkInlineNode;
18+
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
1819
use phpDocumentor\Guides\RenderContext;
1920
use phpDocumentor\Guides\Renderer\UrlGenerator\UrlGeneratorInterface;
2021

22+
use function count;
2123
use function explode;
2224
use function sprintf;
2325
use function str_contains;
@@ -64,8 +66,8 @@ public function resolve(LinkInlineNode $node, RenderContext $renderContext, Mess
6466
}
6567

6668
$node->setUrl($this->urlGenerator->generateCanonicalOutputUrl($renderContext, $document->getFile()) . $anchor);
67-
if ($node->getValue() === '') {
68-
$node->setValue($document->getTitle()->toString());
69+
if (count($node->getChildren()) === 0) {
70+
$node->addChildNode(new PlainTextInlineNode($document->getTitle()->toString()));
6971
}
7072

7173
return true;

packages/guides/src/ReferenceResolvers/InterlinkReferenceResolver.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515

1616
use phpDocumentor\Guides\Nodes\Inline\CrossReferenceNode;
1717
use phpDocumentor\Guides\Nodes\Inline\LinkInlineNode;
18+
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
1819
use phpDocumentor\Guides\ReferenceResolvers\Interlink\InventoryRepository;
1920
use phpDocumentor\Guides\RenderContext;
2021

22+
use function count;
23+
2124
final class InterlinkReferenceResolver implements ReferenceResolver
2225
{
2326
public final const PRIORITY = 50;
@@ -44,8 +47,8 @@ public function resolve(LinkInlineNode $node, RenderContext $renderContext, Mess
4447
}
4548

4649
$node->setUrl($inventory->getBaseUrl() . $link->getPath());
47-
if ($node->getValue() === '') {
48-
$node->setValue($link->getTitle());
50+
if (count($node->getChildren()) === 0) {
51+
$node->addChildNode(new PlainTextInlineNode($link->getTitle()));
4952
}
5053

5154
return true;

0 commit comments

Comments
 (0)