diff --git a/packages/guides-graphs/resources/template/html/body/uml.html.twig b/packages/guides-graphs/resources/template/html/body/uml.html.twig index a1578582f..299ed582b 100644 --- a/packages/guides-graphs/resources/template/html/body/uml.html.twig +++ b/packages/guides-graphs/resources/template/html/body/uml.html.twig @@ -1,9 +1,8 @@ -{% apply spaceless %} -
- {{ uml(node.value) }} - {% if node.caption %}
{{ node.caption }}
{% endif %} -
-{% endapply %} +
+ {{ uml(node.value) }} + {% if node.caption %} +
{{ node.caption }}
+ {% endif %} +
diff --git a/packages/guides-markdown/src/Markdown/Parsers/InlineParsers/EmphasisParser.php b/packages/guides-markdown/src/Markdown/Parsers/InlineParsers/EmphasisParser.php index 7525b3abe..7500f65d2 100644 --- a/packages/guides-markdown/src/Markdown/Parsers/InlineParsers/EmphasisParser.php +++ b/packages/guides-markdown/src/Markdown/Parsers/InlineParsers/EmphasisParser.php @@ -18,6 +18,7 @@ use phpDocumentor\Guides\Nodes\Inline\EmphasisInlineNode; use phpDocumentor\Guides\Nodes\Inline\InlineNode; use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface; +use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode; use Psr\Log\LoggerInterface; /** @extends AbstractInlineTextDecoratorParser */ @@ -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 diff --git a/packages/guides-markdown/src/Markdown/Parsers/InlineParsers/LinkParser.php b/packages/guides-markdown/src/Markdown/Parsers/InlineParsers/LinkParser.php index d4b640c9b..46a8132f5 100644 --- a/packages/guides-markdown/src/Markdown/Parsers/InlineParsers/LinkParser.php +++ b/packages/guides-markdown/src/Markdown/Parsers/InlineParsers/LinkParser.php @@ -18,6 +18,7 @@ use phpDocumentor\Guides\Nodes\Inline\HyperLinkNode; use phpDocumentor\Guides\Nodes\Inline\InlineNode; use phpDocumentor\Guides\Nodes\Inline\InlineNodeInterface; +use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode; use Psr\Log\LoggerInterface; use function assert; @@ -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 diff --git a/packages/guides-markdown/src/Markdown/Parsers/InlineParsers/StrongParser.php b/packages/guides-markdown/src/Markdown/Parsers/InlineParsers/StrongParser.php index bb31d6175..f8cb0923b 100644 --- a/packages/guides-markdown/src/Markdown/Parsers/InlineParsers/StrongParser.php +++ b/packages/guides-markdown/src/Markdown/Parsers/InlineParsers/StrongParser.php @@ -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; @@ -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 diff --git a/packages/guides-restructured-text/src/RestructuredText/Directives/ImageDirective.php b/packages/guides-restructured-text/src/RestructuredText/Directives/ImageDirective.php index 29730bad2..c1252a38d 100644 --- a/packages/guides-restructured-text/src/RestructuredText/Directives/ImageDirective.php +++ b/packages/guides-restructured-text/src/RestructuredText/Directives/ImageDirective.php @@ -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); } } diff --git a/packages/guides-restructured-text/src/RestructuredText/Parser/Productions/InlineRules/EmphasisRule.php b/packages/guides-restructured-text/src/RestructuredText/Parser/Productions/InlineRules/EmphasisRule.php index b4c4e3545..f542831eb 100644 --- a/packages/guides-restructured-text/src/RestructuredText/Parser/Productions/InlineRules/EmphasisRule.php +++ b/packages/guides-restructured-text/src/RestructuredText/Parser/Productions/InlineRules/EmphasisRule.php @@ -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; @@ -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; diff --git a/packages/guides-restructured-text/src/RestructuredText/Parser/Productions/InlineRules/ReferenceRule.php b/packages/guides-restructured-text/src/RestructuredText/Parser/Productions/InlineRules/ReferenceRule.php index a395f5185..6412ed4ef 100644 --- a/packages/guides-restructured-text/src/RestructuredText/Parser/Productions/InlineRules/ReferenceRule.php +++ b/packages/guides-restructured-text/src/RestructuredText/Parser/Productions/InlineRules/ReferenceRule.php @@ -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; @@ -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); } } diff --git a/packages/guides-restructured-text/src/RestructuredText/Parser/Productions/InlineRules/StrongRule.php b/packages/guides-restructured-text/src/RestructuredText/Parser/Productions/InlineRules/StrongRule.php index b9475a104..ae102aefe 100644 --- a/packages/guides-restructured-text/src/RestructuredText/Parser/Productions/InlineRules/StrongRule.php +++ b/packages/guides-restructured-text/src/RestructuredText/Parser/Productions/InlineRules/StrongRule.php @@ -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; @@ -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; diff --git a/packages/guides-restructured-text/src/RestructuredText/TextRoles/ApiClassTextRole.php b/packages/guides-restructured-text/src/RestructuredText/TextRoles/ApiClassTextRole.php index fcb348e9d..8243cc6bd 100644 --- a/packages/guides-restructured-text/src/RestructuredText/TextRoles/ApiClassTextRole.php +++ b/packages/guides-restructured-text/src/RestructuredText/TextRoles/ApiClassTextRole.php @@ -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; @@ -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); } } diff --git a/packages/guides-restructured-text/src/RestructuredText/TextRoles/DocReferenceTextRole.php b/packages/guides-restructured-text/src/RestructuredText/TextRoles/DocReferenceTextRole.php index 7c0370d06..3d028b920 100644 --- a/packages/guides-restructured-text/src/RestructuredText/TextRoles/DocReferenceTextRole.php +++ b/packages/guides-restructured-text/src/RestructuredText/TextRoles/DocReferenceTextRole.php @@ -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; /** @@ -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); } } diff --git a/packages/guides-restructured-text/src/RestructuredText/TextRoles/GenericReferenceTextRole.php b/packages/guides-restructured-text/src/RestructuredText/TextRoles/GenericReferenceTextRole.php index 04e32bfc9..de172cb36 100644 --- a/packages/guides-restructured-text/src/RestructuredText/TextRoles/GenericReferenceTextRole.php +++ b/packages/guides-restructured-text/src/RestructuredText/TextRoles/GenericReferenceTextRole.php @@ -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; @@ -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, + ); } } diff --git a/packages/guides-restructured-text/src/RestructuredText/TextRoles/ReferenceTextRole.php b/packages/guides-restructured-text/src/RestructuredText/TextRoles/ReferenceTextRole.php index 7d76d324e..171d5dd7b 100644 --- a/packages/guides-restructured-text/src/RestructuredText/TextRoles/ReferenceTextRole.php +++ b/packages/guides-restructured-text/src/RestructuredText/TextRoles/ReferenceTextRole.php @@ -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 @@ -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)] : []); } } diff --git a/packages/guides-theme-rst/resources/template/rst/inline/emphasis.rst.twig b/packages/guides-theme-rst/resources/template/rst/inline/emphasis.rst.twig index 7c0eee195..1c35549ab 100644 --- a/packages/guides-theme-rst/resources/template/rst/inline/emphasis.rst.twig +++ b/packages/guides-theme-rst/resources/template/rst/inline/emphasis.rst.twig @@ -1 +1 @@ -*{{- node.value|raw -}}* +*{{- node|plaintext -}}* diff --git a/packages/guides-theme-rst/resources/template/rst/inline/link.rst.twig b/packages/guides-theme-rst/resources/template/rst/inline/link.rst.twig index edde6ce9c..572b26fea 100644 --- a/packages/guides-theme-rst/resources/template/rst/inline/link.rst.twig +++ b/packages/guides-theme-rst/resources/template/rst/inline/link.rst.twig @@ -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 -%} diff --git a/packages/guides-theme-rst/resources/template/rst/inline/strong.rst.twig b/packages/guides-theme-rst/resources/template/rst/inline/strong.rst.twig index 3a08cb2cc..52ff83d17 100644 --- a/packages/guides-theme-rst/resources/template/rst/inline/strong.rst.twig +++ b/packages/guides-theme-rst/resources/template/rst/inline/strong.rst.twig @@ -1 +1 @@ -**{{- node.value|raw -}}** +**{{- node|plaintext -}}** diff --git a/packages/guides-theme-rst/src/RstTheme/Twig/RstExtension.php b/packages/guides-theme-rst/src/RstTheme/Twig/RstExtension.php index c0b697f29..2438ff14b 100644 --- a/packages/guides-theme-rst/src/RstTheme/Twig/RstExtension.php +++ b/packages/guides-theme-rst/src/RstTheme/Twig/RstExtension.php @@ -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; @@ -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); diff --git a/packages/guides/src/Nodes/Inline/AbstractLinkInlineNode.php b/packages/guides/src/Nodes/Inline/AbstractLinkInlineNode.php index 5732d4ecc..b00439ba1 100644 --- a/packages/guides/src/Nodes/Inline/AbstractLinkInlineNode.php +++ b/packages/guides/src/Nodes/Inline/AbstractLinkInlineNode.php @@ -16,6 +16,10 @@ use Doctrine\Deprecations\Deprecation; use phpDocumentor\Guides\Nodes\InlineCompoundNode; +use function func_get_arg; +use function func_num_args; +use function is_string; + abstract class AbstractLinkInlineNode extends InlineCompoundNode implements LinkInlineNode { use BCInlineNodeBehavior; @@ -26,16 +30,24 @@ abstract class AbstractLinkInlineNode extends InlineCompoundNode implements Link public function __construct( private readonly string $type, private readonly string $targetReference, - string $value = '', - array $children = [], + string|array $children = [], ) { - if (empty($children)) { + if (is_string($children)) { Deprecation::trigger( 'phpdocumentor/guides', 'https://github.com/phpDocumentor/guides/issues/1161', - 'Please provide the children as an array of InlineNodeInterface instances instead of a string.', + 'Passing the content of %s as string is deprecated, pass an array of InlineNodeInterface instances instead. New signature: string $type, string $targetReference, array $children', + static::class, ); - $children = [new PlainTextInlineNode($value)]; + + if (func_num_args() < 4) { + // compat with (string $type, string $targetReference, string $value) signature + $children = $children === '' ? [] : [new PlainTextInlineNode($children)]; + } else { + // compat with (string $type, string $targetReference, string $value, array $children = []) signature + /** @var InlineNodeInterface[] $children */ + $children = func_get_arg(3); + } } parent::__construct($children); @@ -62,7 +74,7 @@ public function getDebugInformation(): array return [ 'type' => $this->getType(), 'targetReference' => $this->getTargetReference(), - 'value' => $this->getValue(), + 'value' => $this->toString(), ]; } diff --git a/packages/guides/src/Nodes/Inline/BCInlineNodeBehavior.php b/packages/guides/src/Nodes/Inline/BCInlineNodeBehavior.php index e34ca8538..138298252 100644 --- a/packages/guides/src/Nodes/Inline/BCInlineNodeBehavior.php +++ b/packages/guides/src/Nodes/Inline/BCInlineNodeBehavior.php @@ -24,7 +24,8 @@ public function getValue(): string Deprecation::trigger( 'phpdocumentor/guides', 'https://github.com/phpDocumentor/guides/issues/1161', - 'Use getChildren to access the value of this node.', + 'Use getChildren to access the value of %s.', + static::class, ); return $this->toString(); @@ -34,12 +35,13 @@ public function getValue(): string public function setValue(mixed $value): void { if (is_string($value)) { - $value = [new PlainTextInlineNode($value)]; + $value = $value === '' ? [] : [new PlainTextInlineNode($value)]; Deprecation::trigger( 'phpdocumentor/guides', 'https://github.com/phpDocumentor/guides/issues/1161', - 'Please provide the children as an array of InlineNodeInterface instances instead of a string.', + 'Passing a string to %s is deprecated, pass an array of InlineNodeInterface instances instead.', + __METHOD__, ); } diff --git a/packages/guides/src/Nodes/Inline/DocReferenceNode.php b/packages/guides/src/Nodes/Inline/DocReferenceNode.php index 3cbc25cec..d5acfde8b 100644 --- a/packages/guides/src/Nodes/Inline/DocReferenceNode.php +++ b/packages/guides/src/Nodes/Inline/DocReferenceNode.php @@ -13,7 +13,10 @@ namespace phpDocumentor\Guides\Nodes\Inline; +use Doctrine\Deprecations\Deprecation; + use function array_merge; +use function is_string; /** * Represents a link to document @@ -29,12 +32,24 @@ final class DocReferenceNode extends AbstractLinkInlineNode implements CrossRefe { final public const TYPE = 'doc'; + /** @param InlineNodeInterface[] $children */ public function __construct( string $targetDocument, - string $value = '', + string|array $children = [], private readonly string $interlinkDomain = '', ) { - parent::__construct(self::TYPE, $targetDocument, $value); + if (is_string($children)) { + Deprecation::trigger( + 'phpdocumentor/guides', + 'https://github.com/phpDocumentor/guides/issues/1161', + 'Passing the content of %s as string is deprecated, pass an array of InlineNodeInterface instances instead. New signature: string $targetDocument, array $children, string $interlinkDomain', + static::class, + ); + + $children = $children === '' ? [] : [new PlainTextInlineNode($children)]; + } + + parent::__construct(self::TYPE, $targetDocument, $children); } public function getInterlinkDomain(): string diff --git a/packages/guides/src/Nodes/Inline/EmphasisInlineNode.php b/packages/guides/src/Nodes/Inline/EmphasisInlineNode.php index 1d4371aab..d16fd21cb 100644 --- a/packages/guides/src/Nodes/Inline/EmphasisInlineNode.php +++ b/packages/guides/src/Nodes/Inline/EmphasisInlineNode.php @@ -16,6 +16,10 @@ use Doctrine\Deprecations\Deprecation; use phpDocumentor\Guides\Nodes\InlineCompoundNode; +use function func_get_arg; +use function func_num_args; +use function is_string; + final class EmphasisInlineNode extends InlineCompoundNode { use BCInlineNodeBehavior; @@ -23,15 +27,24 @@ final class EmphasisInlineNode extends InlineCompoundNode public const TYPE = 'emphasis'; /** @param InlineNodeInterface[] $children */ - public function __construct(string $value, array $children = []) + public function __construct(string|array $children = []) { - if (empty($children)) { - $children = [new PlainTextInlineNode($value)]; + if (is_string($children)) { Deprecation::trigger( 'phpdocumentor/guides', 'https://github.com/phpDocumentor/guides/issues/1161', - 'Please provide the children as an array of InlineNodeInterface instances instead of a string.', + 'Passing the content of %s as string is deprecated, pass an array of InlineNodeInterface instances instead. New signature: array $children', + static::class, ); + + if (func_num_args() < 2) { + // compat with (string $value) signature + $children = $children === '' ? [] : [new PlainTextInlineNode($children)]; + } else { + // compat with (string $value, array $children = []) signature + /** @var InlineNodeInterface[] $children */ + $children = func_get_arg(1); + } } parent::__construct($children); diff --git a/packages/guides/src/Nodes/Inline/HyperLinkNode.php b/packages/guides/src/Nodes/Inline/HyperLinkNode.php index 89eef6f56..ba87a3e36 100644 --- a/packages/guides/src/Nodes/Inline/HyperLinkNode.php +++ b/packages/guides/src/Nodes/Inline/HyperLinkNode.php @@ -13,14 +13,38 @@ namespace phpDocumentor\Guides\Nodes\Inline; +use Doctrine\Deprecations\Deprecation; + +use function func_get_arg; +use function func_num_args; +use function is_string; + /** * Represents a link to an external source or email */ final class HyperLinkNode extends AbstractLinkInlineNode { /** @param InlineNodeInterface[] $children */ - public function __construct(string $value, string $targetReference, array $children = []) + public function __construct(string|array $children, string $targetReference) { - parent::__construct('link', $targetReference, $value, $children); + if (is_string($children)) { + Deprecation::trigger( + 'phpdocumentor/guides', + 'https://github.com/phpDocumentor/guides/issues/1161', + 'Passing the content of %s as string is deprecated, pass an array of InlineNodeInterface instances instead. New signature: array $children, string $targetReference', + static::class, + ); + + if (func_num_args() < 3) { + // compat with (string $value, string $targetReference) signature + $children = $children === '' ? [] : [new PlainTextInlineNode($children)]; + } else { + // compat with (string $value, string $targetReference, array $children = []) signature + /** @var InlineNodeInterface[] $children */ + $children = func_get_arg(2); + } + } + + parent::__construct('link', $targetReference, $children); } } diff --git a/packages/guides/src/Nodes/Inline/ReferenceNode.php b/packages/guides/src/Nodes/Inline/ReferenceNode.php index edde092bf..6eb0f45b5 100644 --- a/packages/guides/src/Nodes/Inline/ReferenceNode.php +++ b/packages/guides/src/Nodes/Inline/ReferenceNode.php @@ -13,9 +13,11 @@ namespace phpDocumentor\Guides\Nodes\Inline; +use Doctrine\Deprecations\Deprecation; use phpDocumentor\Guides\Nodes\SectionNode; use function array_merge; +use function is_string; /** * CrossReferences are references outside a document. As parsing is file based normal references are in document, @@ -32,14 +34,26 @@ final class ReferenceNode extends AbstractLinkInlineNode implements CrossReferen { final public const TYPE = 'ref'; + /** @param InlineNodeInterface[] $children */ public function __construct( string $targetReference, - string $value = '', + string|array $children = [], private readonly string $interlinkDomain = '', private readonly string $linkType = SectionNode::STD_LABEL, private readonly string $prefix = '', ) { - parent::__construct(self::TYPE, $targetReference, $value); + if (is_string($children)) { + Deprecation::trigger( + 'phpdocumentor/guides', + 'https://github.com/phpDocumentor/guides/issues/1161', + 'Passing the content of %s as string is deprecated, pass an array of InlineNodeInterface instances instead. New signature: string $targetReference, $children, string $interlinkDomain, string $linkType, string $prefix', + static::class, + ); + + $children = $children === '' ? [] : [new PlainTextInlineNode($children)]; + } + + parent::__construct(self::TYPE, $targetReference, $children); } public function getLinkType(): string diff --git a/packages/guides/src/Nodes/Inline/StrongInlineNode.php b/packages/guides/src/Nodes/Inline/StrongInlineNode.php index 1a3d3a26c..8f8e71fa0 100644 --- a/packages/guides/src/Nodes/Inline/StrongInlineNode.php +++ b/packages/guides/src/Nodes/Inline/StrongInlineNode.php @@ -16,6 +16,10 @@ use Doctrine\Deprecations\Deprecation; use phpDocumentor\Guides\Nodes\InlineCompoundNode; +use function func_get_arg; +use function func_num_args; +use function is_string; + final class StrongInlineNode extends InlineCompoundNode { use BCInlineNodeBehavior; @@ -23,15 +27,24 @@ final class StrongInlineNode extends InlineCompoundNode public const TYPE = 'strong'; /** @param InlineNodeInterface[] $children */ - public function __construct(string $value, array $children = []) + public function __construct(string|array $children = []) { - if (empty($children)) { - $children = [new PlainTextInlineNode($value)]; + if (is_string($children)) { Deprecation::trigger( 'phpdocumentor/guides', 'https://github.com/phpDocumentor/guides/issues/1161', - 'Please provide the children as an array of InlineNodeInterface instances instead of a string.', + 'Passing the content of %s as string is deprecated, pass an array of InlineNodeInterface instances instead. New signature: array $children', + static::class, ); + + if (func_num_args() < 2) { + // compat with (string $value) signature + $children = $children === '' ? [] : [new PlainTextInlineNode($children)]; + } else { + // compat with (string $value, array $children = []) signature + /** @var InlineNodeInterface[] $children */ + $children = func_get_arg(1); + } } parent::__construct($children); diff --git a/packages/guides/src/ParserContext.php b/packages/guides/src/ParserContext.php index fc4311406..9aca0cdcb 100644 --- a/packages/guides/src/ParserContext.php +++ b/packages/guides/src/ParserContext.php @@ -14,8 +14,7 @@ namespace phpDocumentor\Guides; use League\Flysystem\FilesystemInterface; -use League\Uri\Uri; -use League\Uri\UriInfo; +use League\Uri\BaseUri; use phpDocumentor\FileSystem\FileSystem; use phpDocumentor\Guides\Nodes\ProjectNode; use phpDocumentor\Guides\ReferenceResolvers\DocumentNameResolverInterface; @@ -47,8 +46,7 @@ public function getInitialHeaderLevel(): int public function absoluteRelativePath(string $url): string { - $uri = Uri::createFromString($url); - if (UriInfo::isAbsolutePath($uri)) { + if (BaseUri::from($url)->isAbsolutePath()) { return $this->currentDirectory . '/' . ltrim($url, '/'); } diff --git a/packages/guides/src/ReferenceResolvers/AnchorHyperlinkResolver.php b/packages/guides/src/ReferenceResolvers/AnchorHyperlinkResolver.php index ed8757d31..52e0e27dc 100644 --- a/packages/guides/src/ReferenceResolvers/AnchorHyperlinkResolver.php +++ b/packages/guides/src/ReferenceResolvers/AnchorHyperlinkResolver.php @@ -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. * @@ -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; diff --git a/packages/guides/src/ReferenceResolvers/AnchorReferenceResolver.php b/packages/guides/src/ReferenceResolvers/AnchorReferenceResolver.php index 4bead238f..c1ba64412 100644 --- a/packages/guides/src/ReferenceResolvers/AnchorReferenceResolver.php +++ b/packages/guides/src/ReferenceResolvers/AnchorReferenceResolver.php @@ -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. * @@ -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; diff --git a/packages/guides/src/ReferenceResolvers/DocReferenceResolver.php b/packages/guides/src/ReferenceResolvers/DocReferenceResolver.php index 0de9e76b8..33a3b51f3 100644 --- a/packages/guides/src/ReferenceResolvers/DocReferenceResolver.php +++ b/packages/guides/src/ReferenceResolvers/DocReferenceResolver.php @@ -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; @@ -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; diff --git a/packages/guides/src/ReferenceResolvers/DocumentNameResolver.php b/packages/guides/src/ReferenceResolvers/DocumentNameResolver.php index f22229b43..398e99aca 100644 --- a/packages/guides/src/ReferenceResolvers/DocumentNameResolver.php +++ b/packages/guides/src/ReferenceResolvers/DocumentNameResolver.php @@ -13,8 +13,7 @@ namespace phpDocumentor\Guides\ReferenceResolvers; -use League\Uri\UriInfo; -use phpDocumentor\Guides\UriFactory; +use League\Uri\BaseUri; use function array_pop; use function explode; @@ -32,13 +31,12 @@ final class DocumentNameResolver implements DocumentNameResolverInterface */ public function absoluteUrl(string $basePath, string $url): string { - $uri = UriFactory::createUri($url); - - if (UriInfo::isAbsolute($uri)) { + $uri = BaseUri::from($url); + if ($uri->isAbsolute()) { return $url; } - if (UriInfo::isAbsolutePath($uri)) { + if ($uri->isAbsolutePath()) { return $url; } diff --git a/packages/guides/src/ReferenceResolvers/InterlinkReferenceResolver.php b/packages/guides/src/ReferenceResolvers/InterlinkReferenceResolver.php index 2ac497d1d..3bef72104 100644 --- a/packages/guides/src/ReferenceResolvers/InterlinkReferenceResolver.php +++ b/packages/guides/src/ReferenceResolvers/InterlinkReferenceResolver.php @@ -13,11 +13,15 @@ namespace phpDocumentor\Guides\ReferenceResolvers; +use phpDocumentor\Guides\Nodes\CompoundNode; 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; @@ -44,7 +48,11 @@ public function resolve(LinkInlineNode $node, RenderContext $renderContext, Mess } $node->setUrl($inventory->getBaseUrl() . $link->getPath()); - if ($node->getValue() === '') { + if ($node instanceof CompoundNode) { + if (count($node->getChildren()) === 0) { + $node->addChildNode(new PlainTextInlineNode($link->getTitle())); + } + } elseif ($node->getValue() === '') { $node->setValue($link->getTitle()); } diff --git a/packages/guides/src/ReferenceResolvers/PageHyperlinkResolver.php b/packages/guides/src/ReferenceResolvers/PageHyperlinkResolver.php index a4fd7f4c9..2bdc5a4a8 100644 --- a/packages/guides/src/ReferenceResolvers/PageHyperlinkResolver.php +++ b/packages/guides/src/ReferenceResolvers/PageHyperlinkResolver.php @@ -15,9 +15,11 @@ use phpDocumentor\Guides\Nodes\Inline\HyperLinkNode; 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 str_ends_with; use function strlen; use function substr; @@ -55,8 +57,8 @@ public function resolve(LinkInlineNode $node, RenderContext $renderContext, Mess } $node->setUrl($this->urlGenerator->generateCanonicalOutputUrl($renderContext, $document->getFile())); - if ($node->getValue() === '') { - $node->setValue($document->getTitle()->toString()); + if (count($node->getChildren()) === 0) { + $node->addChildNode(new PlainTextInlineNode($document->getTitle()->toString())); } return true; diff --git a/packages/guides/src/ReferenceResolvers/TitleReferenceResolver.php b/packages/guides/src/ReferenceResolvers/TitleReferenceResolver.php index 05e5d7282..b983fbcfb 100644 --- a/packages/guides/src/ReferenceResolvers/TitleReferenceResolver.php +++ b/packages/guides/src/ReferenceResolvers/TitleReferenceResolver.php @@ -14,11 +14,14 @@ 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\Nodes\SectionNode; use phpDocumentor\Guides\RenderContext; use phpDocumentor\Guides\Renderer\UrlGenerator\UrlGeneratorInterface; +use function count; + /** * Resolves references with an anchor URL. * @@ -48,8 +51,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; diff --git a/packages/guides/src/Renderer/UrlGenerator/AbstractUrlGenerator.php b/packages/guides/src/Renderer/UrlGenerator/AbstractUrlGenerator.php index 6e7faf38d..c1d551aa9 100644 --- a/packages/guides/src/Renderer/UrlGenerator/AbstractUrlGenerator.php +++ b/packages/guides/src/Renderer/UrlGenerator/AbstractUrlGenerator.php @@ -14,10 +14,9 @@ namespace phpDocumentor\Guides\Renderer\UrlGenerator; use Exception; -use League\Uri\UriInfo; +use League\Uri\BaseUri; use phpDocumentor\Guides\ReferenceResolvers\DocumentNameResolverInterface; use phpDocumentor\Guides\RenderContext; -use phpDocumentor\Guides\UriFactory; use function filter_var; use function sprintf; @@ -84,9 +83,7 @@ public function generateInternalUrl( private function isRelativeUrl(string $url): bool { - $uri = UriFactory::createUri($url); - - return UriInfo::isRelativePath($uri); + return BaseUri::from($url)->isRelativePath(); } public function getCurrentFileUrl(RenderContext $renderContext): string diff --git a/packages/guides/src/Renderer/UrlGenerator/RelativeUrlGenerator.php b/packages/guides/src/Renderer/UrlGenerator/RelativeUrlGenerator.php index 40f005c21..dc4e83387 100644 --- a/packages/guides/src/Renderer/UrlGenerator/RelativeUrlGenerator.php +++ b/packages/guides/src/Renderer/UrlGenerator/RelativeUrlGenerator.php @@ -30,8 +30,8 @@ public function generateInternalPathFromRelativeUrl( RenderContext $renderContext, string $canonicalUrl, ): string { - $currentPathUri = Uri::createFromString($renderContext->getOutputFilePath()); - $canonicalUrlUri = Uri::createFromString($canonicalUrl); + $currentPathUri = Uri::new($renderContext->getOutputFilePath()); + $canonicalUrlUri = Uri::new($canonicalUrl); $canonicalAnchor = $canonicalUrlUri->getFragment(); diff --git a/packages/guides/src/Twig/AssetsExtension.php b/packages/guides/src/Twig/AssetsExtension.php index 070d79f7e..87da94d81 100644 --- a/packages/guides/src/Twig/AssetsExtension.php +++ b/packages/guides/src/Twig/AssetsExtension.php @@ -13,8 +13,8 @@ namespace phpDocumentor\Guides\Twig; +use League\Uri\BaseUri; use League\Uri\Uri; -use League\Uri\UriInfo; use phpDocumentor\Guides\Meta\InternalTarget; use phpDocumentor\Guides\Meta\Target; use phpDocumentor\Guides\NodeRenderers\NodeRenderer; @@ -27,10 +27,12 @@ use RuntimeException; use Stringable; use Throwable; +use Twig\DeprecatedCallableInfo; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; use Twig\TwigTest; +use function class_exists; use function sprintf; use function trim; @@ -56,7 +58,11 @@ public function getFunctions(): array new TwigFunction('renderNode', $this->renderNode(...), ['is_safe' => ['html'], 'needs_context' => true]), new TwigFunction('renderLink', $this->renderLink(...), ['is_safe' => ['html'], 'needs_context' => true]), new TwigFunction('renderBreadcrumb', $this->renderBreadcrumb(...), ['is_safe' => ['html'], 'needs_context' => true]), - new TwigFunction('renderMenu', $this->renderMenu(...), ['is_safe' => ['html'], 'needs_context' => true, 'deprecated' => true]), + new TwigFunction( + 'renderMenu', + $this->renderMenu(...), + ['is_safe' => ['html'], 'needs_context' => true] + (class_exists(DeprecatedCallableInfo::class) ? ['deprecation_info' => new DeprecatedCallableInfo('phpdocumentor/guides', '1.1.0', 'renderMenu" from "' . GlobalMenuExtension::class)] : ['deprecated' => true]), + ), new TwigFunction('renderTarget', $this->renderTarget(...), ['is_safe' => ['html'], 'needs_context' => true]), new TwigFunction('renderOrderedListType', $this->renderOrderedListType(...), ['is_safe' => ['html'], 'needs_context' => false]), ]; @@ -73,7 +79,7 @@ public function getTests(): array ), new TwigTest( 'external_target', - static fn (string|Stringable $value): bool => UriInfo::isAbsolute(Uri::createFromString($value)), + static fn (string|Stringable $value): bool => BaseUri::from(Uri::new($value))->isAbsolute(), ), ]; } diff --git a/packages/guides/src/UriFactory.php b/packages/guides/src/UriFactory.php index 645de5aa0..0a85925dc 100644 --- a/packages/guides/src/UriFactory.php +++ b/packages/guides/src/UriFactory.php @@ -46,10 +46,10 @@ public static function createUri(string $uriString): UriInterface $uriString = substr($uriString, strlen('file:///')); } - return LeagueUri::createFromWindowsPath($uriString); + return LeagueUri::fromWindowsPath($uriString); } - return LeagueUri::createFromString($uriString); + return LeagueUri::new($uriString); } catch (Throwable $exception) { throw new InvalidArgumentException( sprintf( @@ -70,7 +70,7 @@ private static function createPharUri(string $uriString): UriInterface $path = '/' . $path; } - return LeagueUri::createFromComponents( + return LeagueUri::fromComponents( [ 'scheme' => 'phar', 'host' => '', diff --git a/packages/guides/tests/unit/Compiler/CompilerContextTest.php b/packages/guides/tests/unit/Compiler/CompilerContextTest.php index 075bee7a0..b2c624eaa 100644 --- a/packages/guides/tests/unit/Compiler/CompilerContextTest.php +++ b/packages/guides/tests/unit/Compiler/CompilerContextTest.php @@ -15,12 +15,14 @@ use Doctrine\Deprecations\PHPUnit\VerifyDeprecations; use phpDocumentor\Guides\Nodes\ProjectNode; +use PHPUnit\Framework\Attributes\WithoutErrorHandler; use PHPUnit\Framework\TestCase; final class CompilerContextTest extends TestCase { use VerifyDeprecations; + #[WithoutErrorHandler] public function testTriggersDeprecationOnContextExtend(): void { $this->expectDeprecationWithIdentifier('https://github.com/phpDocumentor/guides/issues/971'); @@ -28,6 +30,7 @@ public function testTriggersDeprecationOnContextExtend(): void }; } + #[WithoutErrorHandler] public function testNoDeprecationOnNormalConstruct(): void { $this->expectNoDeprecationWithIdentifier('https://github.com/phpDocumentor/guides/issues/971'); diff --git a/packages/guides/tests/unit/Interlink/InventoryGroupTest.php b/packages/guides/tests/unit/Interlink/InventoryGroupTest.php index 371cbebf2..3c4c4be10 100644 --- a/packages/guides/tests/unit/Interlink/InventoryGroupTest.php +++ b/packages/guides/tests/unit/Interlink/InventoryGroupTest.php @@ -41,7 +41,7 @@ public function testGetLinkFromInterlinkGroup(string $expected, string $input, s $this->inventoryGroup->addLink($path, new InventoryLink('', '', $path . '.html', '')); $messages = new Messages(); $link = $this->inventoryGroup->getLink( - new DocReferenceNode($input, '', 'interlink'), + new DocReferenceNode($input, [], 'interlink'), $this->renderContext, $messages, ); diff --git a/packages/guides/tests/unit/Interlink/InventoryLoaderTest.php b/packages/guides/tests/unit/Interlink/InventoryLoaderTest.php index 1e476a976..b60e516b0 100644 --- a/packages/guides/tests/unit/Interlink/InventoryLoaderTest.php +++ b/packages/guides/tests/unit/Interlink/InventoryLoaderTest.php @@ -74,7 +74,7 @@ public function loadObjectsJsonInv(string $filename): void public function testInventoryLoaderLoadsInventory(): void { - $node = new DocReferenceNode('SomeDocument', '', 'somekey'); + $node = new DocReferenceNode('SomeDocument', [], 'somekey'); $inventory = $this->inventoryRepository->getInventory($node, $this->renderContext, new Messages()); self::assertTrue($inventory instanceof Inventory); self::assertGreaterThan(1, count($inventory->getGroups())); @@ -92,7 +92,7 @@ public function testInventoryIsLoadedExactlyOnce(): void public function testInventoryLoaderAcceptsNull(): void { $this->loadObjectsJsonInv(__DIR__ . '/fixtures/null-in-objects.inv.json'); - $node = new DocReferenceNode('SomeDocument', '', 'somekey'); + $node = new DocReferenceNode('SomeDocument', [], 'somekey'); $inventory = $this->inventoryRepository->getInventory($node, $this->renderContext, new Messages()); self::assertTrue($inventory instanceof Inventory); self::assertGreaterThan(1, count($inventory->getGroups())); @@ -111,47 +111,47 @@ public static function rawAnchorProvider(): Generator { yield 'Simple label' => [ 'some_page.html#modindex', - new ReferenceNode('modindex', '', 'somekey'), + new ReferenceNode('modindex', [], 'somekey'), ]; yield 'Inventory with changed case' => [ 'some_page.html#modindex', - new ReferenceNode('modindex', '', 'SomeKey'), + new ReferenceNode('modindex', [], 'SomeKey'), ]; yield 'Inventory with minus' => [ 'some_page.html#modindex', - new ReferenceNode('modindex', '', 'some-key'), + new ReferenceNode('modindex', [], 'some-key'), ]; yield 'Inventory with underscore and changed case' => [ 'some_page.html#modindex', - new ReferenceNode('modindex', '', 'Some_Key'), + new ReferenceNode('modindex', [], 'Some_Key'), ]; yield 'Both with minus' => [ 'some_page.html#php-modindex', - new ReferenceNode('php-modindex', '', 'somekey'), + new ReferenceNode('php-modindex', [], 'somekey'), ]; yield 'Linked with underscore, inventory with minus' => [ 'some_page.html#php-modindex', - new ReferenceNode('php_modindex', '', 'somekey'), + new ReferenceNode('php_modindex', [], 'somekey'), ]; yield 'Linked with underscore, inventory with underscore' => [ 'php-objectsindex.html#php-objectsindex', - new ReferenceNode('php_objectsindex', '', 'somekey'), + new ReferenceNode('php_objectsindex', [], 'somekey'), ]; yield 'Linked with minus, inventory with underscore' => [ 'php-objectsindex.html#php-objectsindex', - new ReferenceNode('php-objectsindex', '', 'somekey'), + new ReferenceNode('php-objectsindex', [], 'somekey'), ]; yield 'Doc link' => [ 'Page1/Subpage1.html', - new DocReferenceNode('Page1/Subpage1', '', 'somekey'), + new DocReferenceNode('Page1/Subpage1', [], 'somekey'), ]; } @@ -167,15 +167,15 @@ public function testInventoryLinkNotFound(CrossReferenceNode $node): void public static function notFoundInventoryProvider(): Generator { yield 'Simple labe not found' => [ - new ReferenceNode('non-existant-label', '', 'somekey'), + new ReferenceNode('non-existant-label', [], 'somekey'), ]; yield 'docs are casesensitve' => [ - new DocReferenceNode('index', '', 'somekey'), + new DocReferenceNode('index', [], 'somekey'), ]; yield 'docs are not slugged' => [ - new DocReferenceNode('Page1-Subpage1', '', 'somekey'), + new DocReferenceNode('Page1-Subpage1', [], 'somekey'), ]; } } diff --git a/packages/guides/tests/unit/ReferenceResolvers/InterlinkReferenceResolverTest.php b/packages/guides/tests/unit/ReferenceResolvers/InterlinkReferenceResolverTest.php index 60e16547b..fe256b252 100644 --- a/packages/guides/tests/unit/ReferenceResolvers/InterlinkReferenceResolverTest.php +++ b/packages/guides/tests/unit/ReferenceResolvers/InterlinkReferenceResolverTest.php @@ -40,7 +40,7 @@ protected function setUp(): void #[DataProvider('pathProvider')] public function testDocumentReducer(string $expected, string $input, string $path): void { - $input = new DocReferenceNode($input, '', 'interlink-target'); + $input = new DocReferenceNode($input, [], 'interlink-target'); $inventoryLink = new InventoryLink('project', '1.0', $path, ''); $inventory = new Inventory('base-url/', $this->anchorNormalizer); $this->inventoryRepository->expects(self::once())->method('getInventory')->willReturn($inventory); diff --git a/phpunit-baseline.xml b/phpunit-baseline.xml new file mode 100644 index 000000000..f0612a87c --- /dev/null +++ b/phpunit-baseline.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a249e76f7..b2632abca 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,16 +3,18 @@ @@ -28,7 +30,7 @@ - + packages/**/src diff --git a/tests/Integration/tests/graphs/plantuml-external/expected/Plantuml/index.html b/tests/Integration/tests/graphs/plantuml-external/expected/Plantuml/index.html index 1a93dce09..720fb1dac 100644 --- a/tests/Integration/tests/graphs/plantuml-external/expected/Plantuml/index.html +++ b/tests/Integration/tests/graphs/plantuml-external/expected/Plantuml/index.html @@ -1,15 +1,13 @@
-

Uml Directive

-
- 75038c5ec593504a90a100f9668e1138 -
Figure 1-1: Application flow
-
- 75038c5ec593504a90a100f9668e1138 -
Figure 1-1: Application flow
+

Uml Directive

+
+ 75038c5ec593504a90a100f9668e1138 +
Figure 1-1: Application flow
+
+
+ 75038c5ec593504a90a100f9668e1138 +
Figure 1-1: Application flow
+
diff --git a/tests/Integration/tests/graphs/plantuml-external/expected/index.html b/tests/Integration/tests/graphs/plantuml-external/expected/index.html index a731f116f..047febb17 100644 --- a/tests/Integration/tests/graphs/plantuml-external/expected/index.html +++ b/tests/Integration/tests/graphs/plantuml-external/expected/index.html @@ -1,24 +1,20 @@

Uml Directive

-
- 75038c5ec593504a90a100f9668e1138 -
Figure 1-1: Application flow
-
- 75038c5ec593504a90a100f9668e1138 -
Figure 1-1: Application flow
+
+ 75038c5ec593504a90a100f9668e1138 +
Figure 1-1: Application flow
+
+
+ 75038c5ec593504a90a100f9668e1138 +
Figure 1-1: Application flow
+
- -
+ +
diff --git a/tests/Integration/tests/graphs/plantuml-inline/expected/index.html b/tests/Integration/tests/graphs/plantuml-inline/expected/index.html index c886287ba..c9e999ac2 100644 --- a/tests/Integration/tests/graphs/plantuml-inline/expected/index.html +++ b/tests/Integration/tests/graphs/plantuml-inline/expected/index.html @@ -1,15 +1,12 @@

Uml Directive

-
- 2c5f59f569e09c9c8c693c4e924815fa -
-
- 2c5f59f569e09c9c8c693c4e924815fa -
Some Caption
+
+ 2c5f59f569e09c9c8c693c4e924815fa +
+
+ 2c5f59f569e09c9c8c693c4e924815fa +
Some Caption
+
diff --git a/tests/Integration/tests/graphs/plantuml-server-error/expected/index.html b/tests/Integration/tests/graphs/plantuml-server-error/expected/index.html index 2f55a1bda..b906f3bb4 100644 --- a/tests/Integration/tests/graphs/plantuml-server-error/expected/index.html +++ b/tests/Integration/tests/graphs/plantuml-server-error/expected/index.html @@ -1,11 +1,11 @@

Uml Directive

-
Figure 1-1: Application flow
-
Figure 1-1: Application flow
+
+
Figure 1-1: Application flow
+
+
+
Figure 1-1: Application flow
+
diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 000000000..eb349cb65 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,10 @@ +