Skip to content

Commit

Permalink
Fix deprecations in the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed Nov 30, 2024
1 parent ca2098e commit 37f375b
Show file tree
Hide file tree
Showing 31 changed files with 146 additions and 107 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{% apply spaceless %}
<figure
class="uml-diagram{% if node.classesString %} {{ node.classesString }}{% endif %}"
{% if node.hasOption('width') %}style="width: {{ node.option('width') }}"{% endif %}
>
{{ uml(node.value) }}
{% if node.caption %}<figcaption>{{ node.caption }}</figcaption>{% endif %}
</figure>
{% endapply %}
<figure class="uml-diagram{% if node.classesString %} {{ node.classesString }}{% endif %}"
{%- if node.hasOption('width') %} style="width: {{ node.option('width') }}"{% endif -%}
>
{{ uml(node.value) }}
{% if node.caption %}
<figcaption>{{ node.caption }}</figcaption>
{% endif %}
</figure>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use phpDocumentor\Guides\Nodes\Inline\InlineNode;
use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface;
use Psr\Log\LoggerInterface;
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;

Check failure on line 22 in packages/guides-markdown/src/Markdown/Parsers/InlineParsers/EmphasisParser.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Use statements should be sorted alphabetically. The first wrong one is phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode.

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

protected function supportsCommonMarkNode(CommonMarkNode $commonMarkNode): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface;
use Psr\Log\LoggerInterface;

use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;

Check failure on line 23 in packages/guides-markdown/src/Markdown/Parsers/InlineParsers/LinkParser.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Use statements should be sorted alphabetically. The first wrong one is phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode.

Check failure on line 23 in packages/guides-markdown/src/Markdown/Parsers/InlineParsers/LinkParser.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Expected 0 lines between same types of use statement, found 1.
use function assert;

Check failure on line 24 in packages/guides-markdown/src/Markdown/Parsers/InlineParsers/LinkParser.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Expected 1 line between different types of use statement, found 0.
use function filter_var;
use function str_ends_with;
Expand Down Expand Up @@ -48,13 +49,12 @@ protected function createInlineNode(CommonMarkNode $commonMarkNode, string|null
{
assert($commonMarkNode instanceof Link);

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

return new HyperLinkNode($content, $url, $children);
return new HyperLinkNode($content ? [new PlainTextInlineNode($content)] : $children, $url);
}

protected function supportsCommonMarkNode(CommonMarkNode $commonMarkNode): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use League\CommonMark\Node\Node as CommonMarkNode;
use phpDocumentor\Guides\Nodes\Inline\InlineNode;
use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface;
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
use phpDocumentor\Guides\Nodes\Inline\StrongInlineNode;
use Psr\Log\LoggerInterface;

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

protected function supportsCommonMarkNode(CommonMarkNode $commonMarkNode): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,21 @@ public function processNode(
private function resolveLinkTarget(string $targetReference): LinkInlineNode
{
if (filter_var($targetReference, FILTER_VALIDATE_EMAIL)) {
return new HyperLinkNode('', $targetReference);
return new HyperLinkNode([], $targetReference);
}

if (filter_var($targetReference, FILTER_VALIDATE_URL)) {
return new HyperLinkNode('', $targetReference);
return new HyperLinkNode([], $targetReference);
}

if (preg_match(self::REFERENCE_REGEX, $targetReference, $matches)) {
return new ReferenceNode($matches[1], '');
return new ReferenceNode($matches[1]);
}

if (preg_match(self::REFERENCE_ESCAPED_REGEX, $targetReference, $matches)) {
return new ReferenceNode($matches[1], '');
return new ReferenceNode($matches[1]);
}

return new DocReferenceNode($targetReference, '');
return new DocReferenceNode($targetReference);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use phpDocumentor\Guides\Nodes\Inline\EmphasisInlineNode;
use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface;
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
use phpDocumentor\Guides\RestructuredText\Parser\BlockContext;
use phpDocumentor\Guides\RestructuredText\Parser\InlineLexer;

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

$lexer->moveNext();

return new EmphasisInlineNode($text);
return new EmphasisInlineNode([new PlainTextInlineNode($text)]);

default:
$text .= $token->value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use phpDocumentor\Guides\Nodes\Inline\AbstractLinkInlineNode;
use phpDocumentor\Guides\Nodes\Inline\DocReferenceNode;
use phpDocumentor\Guides\Nodes\Inline\HyperLinkNode;
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
use phpDocumentor\Guides\RestructuredText\Parser\BlockContext;

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

return new DocReferenceNode($reference, $text ?? $reference);
$text ??= $reference;

return new DocReferenceNode($reference, $text !== '' ? [new PlainTextInlineNode($text)] : []);
}

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

return new HyperLinkNode($text ?? $reference, $reference);
$text ??= $reference;

return new HyperLinkNode($text !== '' ? [new PlainTextInlineNode($text)] : [], $reference);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace phpDocumentor\Guides\RestructuredText\Parser\Productions\InlineRules;

use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface;
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
use phpDocumentor\Guides\Nodes\Inline\StrongInlineNode;
use phpDocumentor\Guides\RestructuredText\Parser\BlockContext;
use phpDocumentor\Guides\RestructuredText\Parser\InlineLexer;
Expand Down Expand Up @@ -45,7 +46,7 @@ public function apply(BlockContext $blockContext, InlineLexer $lexer): InlineNod

$lexer->moveNext();

return new StrongInlineNode($text);
return new StrongInlineNode([new PlainTextInlineNode($text)]);

default:
$text .= $token->value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace phpDocumentor\Guides\RestructuredText\TextRoles;

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

return new ReferenceNode($reference, $referenceName ?? '', $interlinkData->interlink, self::TYPE, $prefix);
return new ReferenceNode($reference, $referenceName ? [new PlainTextInlineNode($referenceName)] : [], $interlinkData->interlink, self::TYPE, $prefix);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use phpDocumentor\Guides\Nodes\Inline\AbstractLinkInlineNode;
use phpDocumentor\Guides\Nodes\Inline\DocReferenceNode;
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
use phpDocumentor\Guides\RestructuredText\Parser\Interlink\InterlinkParser;

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

return new DocReferenceNode($interlinkData->reference, $referenceName ?? '', $interlinkData->interlink);
return new DocReferenceNode($interlinkData->reference, $referenceName ? [new PlainTextInlineNode($referenceName)] : [], $interlinkData->interlink);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace phpDocumentor\Guides\RestructuredText\TextRoles;

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

return new ReferenceNode($reference, $referenceName ?? '', $interlinkData->interlink, $linkType, $prefix);
return new ReferenceNode(
$reference,
$referenceName ? [new PlainTextInlineNode($referenceName)] : [],
$interlinkData->interlink,
$linkType,
$prefix

Check failure on line 57 in packages/guides-restructured-text/src/RestructuredText/TextRoles/GenericReferenceTextRole.php

View workflow job for this annotation

GitHub Actions / Coding Standards

Multi-line function calls must have a trailing comma after the last parameter.
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace phpDocumentor\Guides\RestructuredText\TextRoles;

use phpDocumentor\Guides\Nodes\Inline\AbstractLinkInlineNode;
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
use phpDocumentor\Guides\Nodes\Inline\ReferenceNode;

final class ReferenceTextRole extends AbstractReferenceTextRole
Expand All @@ -34,6 +35,6 @@ public function getAliases(): array
/** @return ReferenceNode */
protected function createNode(string $referenceTarget, string|null $referenceName, string $role): AbstractLinkInlineNode
{
return new ReferenceNode($referenceTarget, $referenceName ?? '');
return new ReferenceNode($referenceTarget, $referenceName ? [new PlainTextInlineNode($referenceName)] : []);
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
*{{- node.value|raw -}}*
*{{- node|plaintext -}}*
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{%- if node.url -%}
`{{ node.value|raw }} <{{- node.url -}}>`__
`{{ node|plaintext }} <{{- node.url -}}>`__
{%- elseif node.targetReference -%}
:doc:`{{ node.value|raw }} <{{- node.targetReference -}}>`
:doc:`{{ node|plaintext }} <{{- node.targetReference -}}>`
{%- else -%}
{{- node.value -}}
{{- node|plaintext -}}
{%- endif -%}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
**{{- node.value|raw -}}**
**{{- node|plaintext -}}**
16 changes: 14 additions & 2 deletions packages/guides-theme-rst/src/RstTheme/Twig/RstExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
namespace phpDocumentor\Guides\RstTheme\Twig;

use phpDocumentor\Guides\NodeRenderers\NodeRenderer;
use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface;
use phpDocumentor\Guides\Nodes\InlineCompoundNode;
use phpDocumentor\Guides\Nodes\Table\TableColumn;
use phpDocumentor\Guides\Nodes\Table\TableRow;
use phpDocumentor\Guides\Nodes\TableNode;
Expand Down Expand Up @@ -57,14 +59,24 @@ public function getFunctions(): array
public function getFilters(): array
{
return [
new TwigFilter('clean_content', [$this, 'cleanContent']),
new TwigFilter('clean_content', $this->cleanContent(...)),
new TwigFilter('plaintext', $this->plaintext(...)),
];
}

public function plaintext(InlineNodeInterface $node): string
{
if ($node instanceof InlineCompoundNode) {
return implode('', array_map($this->plaintext(...), $node->getChildren()));
}

return $node->toString();
}

public function cleanContent(string $content): string
{
$lines = explode("\n", $content);
$lines = array_map('rtrim', $lines);
$lines = array_map(rtrim(...), $lines);
$content = implode("\n", $lines);

$content = preg_replace('/(\n){2,}/', "\n\n", $content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function getDebugInformation(): array
return [
'type' => $this->getType(),
'targetReference' => $this->getTargetReference(),
'value' => $this->getValue(),
'value' => $this->toString(),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@

use phpDocumentor\Guides\Nodes\Inline\HyperLinkNode;
use phpDocumentor\Guides\Nodes\Inline\LinkInlineNode;
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
use phpDocumentor\Guides\Nodes\SectionNode;
use phpDocumentor\Guides\RenderContext;
use phpDocumentor\Guides\Renderer\UrlGenerator\UrlGeneratorInterface;

use function count;

/**
* Resolves references with an anchor URL.
*
Expand Down Expand Up @@ -51,8 +54,8 @@ public function resolve(LinkInlineNode $node, RenderContext $renderContext, Mess
}

$node->setUrl($this->urlGenerator->generateCanonicalOutputUrl($renderContext, $target->getDocumentPath(), $target->getAnchor()));
if ($node->getValue() === '') {
$node->setValue($target->getTitle() ?? '');
if (count($node->getChildren()) === 0) {
$node->addChildNode(new PlainTextInlineNode($target->getTitle() ?? ''));
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
namespace phpDocumentor\Guides\ReferenceResolvers;

use phpDocumentor\Guides\Nodes\Inline\LinkInlineNode;
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
use phpDocumentor\Guides\Nodes\Inline\ReferenceNode;
use phpDocumentor\Guides\RenderContext;
use phpDocumentor\Guides\Renderer\UrlGenerator\UrlGeneratorInterface;

use function count;

/**
* Resolves references with an anchor URL.
*
Expand Down Expand Up @@ -47,8 +50,8 @@ public function resolve(LinkInlineNode $node, RenderContext $renderContext, Mess
}

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

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@

use phpDocumentor\Guides\Nodes\Inline\DocReferenceNode;
use phpDocumentor\Guides\Nodes\Inline\LinkInlineNode;
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
use phpDocumentor\Guides\RenderContext;
use phpDocumentor\Guides\Renderer\UrlGenerator\UrlGeneratorInterface;

use function count;
use function explode;
use function sprintf;
use function str_contains;
Expand Down Expand Up @@ -64,8 +66,8 @@ public function resolve(LinkInlineNode $node, RenderContext $renderContext, Mess
}

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

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@

use phpDocumentor\Guides\Nodes\Inline\CrossReferenceNode;
use phpDocumentor\Guides\Nodes\Inline\LinkInlineNode;
use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode;
use phpDocumentor\Guides\ReferenceResolvers\Interlink\InventoryRepository;
use phpDocumentor\Guides\RenderContext;

use function count;

final class InterlinkReferenceResolver implements ReferenceResolver
{
public final const PRIORITY = 50;
Expand All @@ -44,8 +47,8 @@ public function resolve(LinkInlineNode $node, RenderContext $renderContext, Mess
}

$node->setUrl($inventory->getBaseUrl() . $link->getPath());
if ($node->getValue() === '') {
$node->setValue($link->getTitle());
if (count($node->getChildren()) === 0) {

Check failure on line 50 in packages/guides/src/ReferenceResolvers/InterlinkReferenceResolver.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.2)

Call to an undefined method phpDocumentor\Guides\Nodes\Inline\CrossReferenceNode::getChildren().
$node->addChildNode(new PlainTextInlineNode($link->getTitle()));

Check failure on line 51 in packages/guides/src/ReferenceResolvers/InterlinkReferenceResolver.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.2)

Call to an undefined method phpDocumentor\Guides\Nodes\Inline\CrossReferenceNode::addChildNode().
}

return true;
Expand Down
Loading

0 comments on commit 37f375b

Please sign in to comment.