From 720542131fe5fa8aa417433e007febd4765ecdf0 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Fri, 12 Apr 2024 12:09:02 +0200 Subject: [PATCH 1/2] Introduce CompilerContextInterface The Compiler context is a very important class in our compiler, however extending projects may want to extend the information caried around with the context to add extra information for specific use cases in custom compiler passes. To make this possible I introduced a new interface to be able to wrap the compilercontext and extend the functionality. Changing the interfaces would be a backward compatibility break so we need to introduce this step by step. --- .../guides/src/Compiler/CompilerContext.php | 13 ++++++- .../src/Compiler/CompilerContextInterface.php | 37 +++++++++++++++++++ .../CitationInlineNodeTransformer.php | 6 +-- .../CitationTargetTransformer.php | 6 +-- .../NodeTransformers/ClassNodeTransformer.php | 6 +-- .../CollectLinkTargetsTransformer.php | 8 ++-- .../DocumentBlockNodeTransformer.php | 6 +-- .../DocumentEntryRegistrationTransformer.php | 6 +-- .../FootNodeNamedTransformer.php | 6 +-- .../FootNodeNumberedTransformer.php | 6 +-- .../FootnoteInlineNodeTransformer.php | 6 +-- .../NodeTransformers/ListNodeTransformer.php | 6 +-- .../AbstractMenuEntryNodeTransformer.php | 8 ++-- .../ContentsMenuEntryNodeTransformer.php | 4 +- .../ExternalMenuEntryNodeTransformer.php | 4 +- .../GlobMenuEntryNodeTransformer.php | 4 +- .../InternalMenuEntryNodeTransformer.php | 4 +- .../MenuEntryManagement.php | 4 +- .../SubInternalMenuEntryNodeTransformer.php | 6 +-- .../TocNodeTransformer.php | 6 +-- .../MoveAnchorTransformer.php | 6 +-- .../SectionCreationTransformer.php | 6 +-- .../SectionEntryRegistrationTransformer.php | 6 +-- .../NodeTransformers/TransformerPass.php | 1 + .../VariableInlineNodeTransformer.php | 6 +-- .../src/Compiler/Passes/GlobalMenuPass.php | 10 ++--- .../Passes/ImplicitHyperlinkTargetPass.php | 4 +- .../Compiler/Passes/ToctreeValidationPass.php | 4 +- 28 files changed, 122 insertions(+), 73 deletions(-) create mode 100644 packages/guides/src/Compiler/CompilerContextInterface.php diff --git a/packages/guides/src/Compiler/CompilerContext.php b/packages/guides/src/Compiler/CompilerContext.php index e7531723c..3b8d794cc 100644 --- a/packages/guides/src/Compiler/CompilerContext.php +++ b/packages/guides/src/Compiler/CompilerContext.php @@ -19,7 +19,18 @@ use phpDocumentor\Guides\Nodes\Node; use phpDocumentor\Guides\Nodes\ProjectNode; -final class CompilerContext +/** + * Context class used in compiler passes to store the state of the nodes. + * + * The {@see Compiler} is making changes to the nodes in a {@see DocumentNode} as the nodes are immutable cannot + * do this directly. This class helps to modify the nodes in the {@see DocumentNode} by creating a shadow tree. + * + * The class is final and should not be extended, if you need to provide more information to the compiler pass + * you can use the {@see CompilerContextInterface} and decorate this class. + * + * @final + */ +class CompilerContext implements CompilerContextInterface { /** @var TreeNode */ private TreeNode $shadowTree; diff --git a/packages/guides/src/Compiler/CompilerContextInterface.php b/packages/guides/src/Compiler/CompilerContextInterface.php new file mode 100644 index 000000000..0168da4d8 --- /dev/null +++ b/packages/guides/src/Compiler/CompilerContextInterface.php @@ -0,0 +1,37 @@ + $shadowTree */ + public function withShadowTree(TreeNode $shadowTree): self; + + /** @return TreeNode */ + public function getShadowTree(): TreeNode; + + /** @return array */ + public function getLoggerInformation(): array; +} diff --git a/packages/guides/src/Compiler/NodeTransformers/CitationInlineNodeTransformer.php b/packages/guides/src/Compiler/NodeTransformers/CitationInlineNodeTransformer.php index d41ccf37e..61083574f 100644 --- a/packages/guides/src/Compiler/NodeTransformers/CitationInlineNodeTransformer.php +++ b/packages/guides/src/Compiler/NodeTransformers/CitationInlineNodeTransformer.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Guides\Compiler\NodeTransformers; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Compiler\NodeTransformer; use phpDocumentor\Guides\Nodes\Inline\CitationInlineNode; use phpDocumentor\Guides\Nodes\Node; @@ -21,7 +21,7 @@ /** @implements NodeTransformer */ final class CitationInlineNodeTransformer implements NodeTransformer { - public function enterNode(Node $node, CompilerContext $compilerContext): Node + public function enterNode(Node $node, CompilerContextInterface $compilerContext): Node { if ($node instanceof CitationInlineNode) { $internalTarget = $compilerContext->getProjectNode()->getCitationTarget($node->getName()); @@ -31,7 +31,7 @@ public function enterNode(Node $node, CompilerContext $compilerContext): Node return $node; } - public function leaveNode(Node $node, CompilerContext $compilerContext): Node|null + public function leaveNode(Node $node, CompilerContextInterface $compilerContext): Node|null { return $node; } diff --git a/packages/guides/src/Compiler/NodeTransformers/CitationTargetTransformer.php b/packages/guides/src/Compiler/NodeTransformers/CitationTargetTransformer.php index 926216746..1fa6033df 100644 --- a/packages/guides/src/Compiler/NodeTransformers/CitationTargetTransformer.php +++ b/packages/guides/src/Compiler/NodeTransformers/CitationTargetTransformer.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Guides\Compiler\NodeTransformers; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Compiler\NodeTransformer; use phpDocumentor\Guides\Meta\CitationTarget; use phpDocumentor\Guides\Nodes\CitationNode; @@ -22,7 +22,7 @@ /** @implements NodeTransformer */ final class CitationTargetTransformer implements NodeTransformer { - public function enterNode(Node $node, CompilerContext $compilerContext): Node + public function enterNode(Node $node, CompilerContextInterface $compilerContext): Node { if ($node instanceof CitationNode) { $compilerContext->getProjectNode()->addCitationTarget( @@ -37,7 +37,7 @@ public function enterNode(Node $node, CompilerContext $compilerContext): Node return $node; } - public function leaveNode(Node $node, CompilerContext $compilerContext): Node|null + public function leaveNode(Node $node, CompilerContextInterface $compilerContext): Node|null { return $node; } diff --git a/packages/guides/src/Compiler/NodeTransformers/ClassNodeTransformer.php b/packages/guides/src/Compiler/NodeTransformers/ClassNodeTransformer.php index 22fb83fb9..0e0be95aa 100644 --- a/packages/guides/src/Compiler/NodeTransformers/ClassNodeTransformer.php +++ b/packages/guides/src/Compiler/NodeTransformers/ClassNodeTransformer.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Guides\Compiler\NodeTransformers; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Compiler\NodeTransformer; use phpDocumentor\Guides\Nodes\ClassNode; use phpDocumentor\Guides\Nodes\DocumentNode; @@ -32,7 +32,7 @@ final class ClassNodeTransformer implements NodeTransformer /** @var string[] */ private array $classes = []; - public function enterNode(Node $node, CompilerContext $compilerContext): Node + public function enterNode(Node $node, CompilerContextInterface $compilerContext): Node { if ($node instanceof DocumentNode) { // unset classes when entering the next document @@ -52,7 +52,7 @@ public function enterNode(Node $node, CompilerContext $compilerContext): Node return $node; } - public function leaveNode(Node $node, CompilerContext $compilerContext): Node|null + public function leaveNode(Node $node, CompilerContextInterface $compilerContext): Node|null { if ($node instanceof ClassNode) { //Remove the class node from the tree. diff --git a/packages/guides/src/Compiler/NodeTransformers/CollectLinkTargetsTransformer.php b/packages/guides/src/Compiler/NodeTransformers/CollectLinkTargetsTransformer.php index 86781d49c..28e75f691 100644 --- a/packages/guides/src/Compiler/NodeTransformers/CollectLinkTargetsTransformer.php +++ b/packages/guides/src/Compiler/NodeTransformers/CollectLinkTargetsTransformer.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Guides\Compiler\NodeTransformers; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Compiler\NodeTransformer; use phpDocumentor\Guides\Meta\InternalTarget; use phpDocumentor\Guides\Nodes\AnchorNode; @@ -49,7 +49,7 @@ public function __construct( $this->documentStack = new SplStack(); } - public function enterNode(Node $node, CompilerContext $compilerContext): Node + public function enterNode(Node $node, CompilerContextInterface $compilerContext): Node { if ($node instanceof DocumentNode) { $this->documentStack->push($node); @@ -137,7 +137,7 @@ public function enterNode(Node $node, CompilerContext $compilerContext): Node return $node; } - public function leaveNode(Node $node, CompilerContext $compilerContext): Node|null + public function leaveNode(Node $node, CompilerContextInterface $compilerContext): Node|null { if ($node instanceof DocumentNode) { $this->documentStack->pop(); @@ -157,7 +157,7 @@ public function getPriority(): int return 5000; } - private function addLinkTargetToProject(CompilerContext $compilerContext, InternalTarget $internalTarget): void + private function addLinkTargetToProject(CompilerContextInterface $compilerContext, InternalTarget $internalTarget): void { if ($compilerContext->getProjectNode()->hasInternalTarget($internalTarget->getAnchor(), $internalTarget->getLinkType())) { $otherLink = $compilerContext->getProjectNode()->getInternalTarget($internalTarget->getAnchor(), $internalTarget->getLinkType()); diff --git a/packages/guides/src/Compiler/NodeTransformers/DocumentBlockNodeTransformer.php b/packages/guides/src/Compiler/NodeTransformers/DocumentBlockNodeTransformer.php index 4936ec85e..01b88c7c2 100644 --- a/packages/guides/src/Compiler/NodeTransformers/DocumentBlockNodeTransformer.php +++ b/packages/guides/src/Compiler/NodeTransformers/DocumentBlockNodeTransformer.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Guides\Compiler\NodeTransformers; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Compiler\NodeTransformer; use phpDocumentor\Guides\Nodes\DocumentBlockNode; use phpDocumentor\Guides\Nodes\Menu\TocNode; @@ -27,12 +27,12 @@ */ final class DocumentBlockNodeTransformer implements NodeTransformer { - public function enterNode(Node $node, CompilerContext $compilerContext): Node + public function enterNode(Node $node, CompilerContextInterface $compilerContext): Node { return $node; } - public function leaveNode(Node $node, CompilerContext $compilerContext): Node|null + public function leaveNode(Node $node, CompilerContextInterface $compilerContext): Node|null { if ($node instanceof DocumentBlockNode) { $children = []; diff --git a/packages/guides/src/Compiler/NodeTransformers/DocumentEntryRegistrationTransformer.php b/packages/guides/src/Compiler/NodeTransformers/DocumentEntryRegistrationTransformer.php index 1a01611ec..0edd5c59f 100644 --- a/packages/guides/src/Compiler/NodeTransformers/DocumentEntryRegistrationTransformer.php +++ b/packages/guides/src/Compiler/NodeTransformers/DocumentEntryRegistrationTransformer.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Guides\Compiler\NodeTransformers; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Compiler\NodeTransformer; use phpDocumentor\Guides\Nodes\DocumentNode; use phpDocumentor\Guides\Nodes\DocumentTree\DocumentEntryNode; @@ -29,12 +29,12 @@ public function __construct( ) { } - public function enterNode(Node $node, CompilerContext $compilerContext): Node + public function enterNode(Node $node, CompilerContextInterface $compilerContext): Node { return $node; } - public function leaveNode(Node $node, CompilerContext $compilerContext): Node|null + public function leaveNode(Node $node, CompilerContextInterface $compilerContext): Node|null { if (!$node instanceof DocumentNode) { return $node; diff --git a/packages/guides/src/Compiler/NodeTransformers/FootNodeNamedTransformer.php b/packages/guides/src/Compiler/NodeTransformers/FootNodeNamedTransformer.php index 43b96a390..de29f9e6d 100644 --- a/packages/guides/src/Compiler/NodeTransformers/FootNodeNamedTransformer.php +++ b/packages/guides/src/Compiler/NodeTransformers/FootNodeNamedTransformer.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Guides\Compiler\NodeTransformers; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Compiler\NodeTransformer; use phpDocumentor\Guides\Meta\FootnoteTarget; use phpDocumentor\Guides\Nodes\FootnoteNode; @@ -22,7 +22,7 @@ /** @implements NodeTransformer */ final class FootNodeNamedTransformer implements NodeTransformer { - public function enterNode(Node $node, CompilerContext $compilerContext): Node + public function enterNode(Node $node, CompilerContextInterface $compilerContext): Node { if ($node instanceof FootnoteNode && $this->supports($node)) { $number = $compilerContext->getDocumentNode()->addFootnoteTarget(new FootnoteTarget( @@ -37,7 +37,7 @@ public function enterNode(Node $node, CompilerContext $compilerContext): Node return $node; } - public function leaveNode(Node $node, CompilerContext $compilerContext): Node|null + public function leaveNode(Node $node, CompilerContextInterface $compilerContext): Node|null { return $node; } diff --git a/packages/guides/src/Compiler/NodeTransformers/FootNodeNumberedTransformer.php b/packages/guides/src/Compiler/NodeTransformers/FootNodeNumberedTransformer.php index ac7903cb5..29cbaf2b4 100644 --- a/packages/guides/src/Compiler/NodeTransformers/FootNodeNumberedTransformer.php +++ b/packages/guides/src/Compiler/NodeTransformers/FootNodeNumberedTransformer.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Guides\Compiler\NodeTransformers; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Compiler\NodeTransformer; use phpDocumentor\Guides\Meta\FootnoteTarget; use phpDocumentor\Guides\Nodes\FootnoteNode; @@ -22,7 +22,7 @@ /** @implements NodeTransformer */ final class FootNodeNumberedTransformer implements NodeTransformer { - public function enterNode(Node $node, CompilerContext $compilerContext): Node + public function enterNode(Node $node, CompilerContextInterface $compilerContext): Node { if ($node instanceof FootnoteNode && $this->supports($node)) { $compilerContext->getDocumentNode()->addFootnoteTarget(new FootnoteTarget( @@ -36,7 +36,7 @@ public function enterNode(Node $node, CompilerContext $compilerContext): Node return $node; } - public function leaveNode(Node $node, CompilerContext $compilerContext): Node|null + public function leaveNode(Node $node, CompilerContextInterface $compilerContext): Node|null { return $node; } diff --git a/packages/guides/src/Compiler/NodeTransformers/FootnoteInlineNodeTransformer.php b/packages/guides/src/Compiler/NodeTransformers/FootnoteInlineNodeTransformer.php index 844726b64..03d35003e 100644 --- a/packages/guides/src/Compiler/NodeTransformers/FootnoteInlineNodeTransformer.php +++ b/packages/guides/src/Compiler/NodeTransformers/FootnoteInlineNodeTransformer.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Guides\Compiler\NodeTransformers; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Compiler\NodeTransformer; use phpDocumentor\Guides\Nodes\Inline\FootnoteInlineNode; use phpDocumentor\Guides\Nodes\Node; @@ -21,7 +21,7 @@ /** @implements NodeTransformer */ final class FootnoteInlineNodeTransformer implements NodeTransformer { - public function enterNode(Node $node, CompilerContext $compilerContext): Node + public function enterNode(Node $node, CompilerContextInterface $compilerContext): Node { if ($node instanceof FootnoteInlineNode) { if ($node->getNumber() > 0) { @@ -38,7 +38,7 @@ public function enterNode(Node $node, CompilerContext $compilerContext): Node return $node; } - public function leaveNode(Node $node, CompilerContext $compilerContext): Node|null + public function leaveNode(Node $node, CompilerContextInterface $compilerContext): Node|null { return $node; } diff --git a/packages/guides/src/Compiler/NodeTransformers/ListNodeTransformer.php b/packages/guides/src/Compiler/NodeTransformers/ListNodeTransformer.php index d2f6dfc96..a4dbd866b 100644 --- a/packages/guides/src/Compiler/NodeTransformers/ListNodeTransformer.php +++ b/packages/guides/src/Compiler/NodeTransformers/ListNodeTransformer.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Guides\Compiler\NodeTransformers; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Compiler\NodeTransformer; use phpDocumentor\Guides\Nodes\ListItemNode; use phpDocumentor\Guides\Nodes\ListNode; @@ -30,12 +30,12 @@ public function __construct( ) { } - public function enterNode(Node $node, CompilerContext $compilerContext): Node + public function enterNode(Node $node, CompilerContextInterface $compilerContext): Node { return $node; } - public function leaveNode(Node $node, CompilerContext $compilerContext): Node|null + public function leaveNode(Node $node, CompilerContextInterface $compilerContext): Node|null { assert($node instanceof ListNode); foreach ($node->getChildren() as $listItemNode) { diff --git a/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/AbstractMenuEntryNodeTransformer.php b/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/AbstractMenuEntryNodeTransformer.php index 6cf4166f4..df8ea46d8 100644 --- a/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/AbstractMenuEntryNodeTransformer.php +++ b/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/AbstractMenuEntryNodeTransformer.php @@ -14,7 +14,7 @@ namespace phpDocumentor\Guides\Compiler\NodeTransformers\MenuNodeTransformers; use Exception; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Compiler\NodeTransformer; use phpDocumentor\Guides\Nodes\Menu\MenuEntryNode; use phpDocumentor\Guides\Nodes\Menu\MenuNode; @@ -32,13 +32,13 @@ public function __construct( ) { } - final public function enterNode(Node $node, CompilerContext $compilerContext): MenuEntryNode + final public function enterNode(Node $node, CompilerContextInterface $compilerContext): MenuEntryNode { return $node; } /** @param MenuEntryNode $node */ - final public function leaveNode(Node $node, CompilerContext $compilerContext): MenuEntryNode|null + final public function leaveNode(Node $node, CompilerContextInterface $compilerContext): MenuEntryNode|null { assert($node instanceof MenuEntryNode); $currentMenuShaddow = $compilerContext->getShadowTree()->getParent(); @@ -70,5 +70,5 @@ final public function leaveNode(Node $node, CompilerContext $compilerContext): M } /** @return list */ - abstract protected function handleMenuEntry(MenuNode $currentMenu, MenuEntryNode $entryNode, CompilerContext $compilerContext): array; + abstract protected function handleMenuEntry(MenuNode $currentMenu, MenuEntryNode $entryNode, CompilerContextInterface $compilerContext): array; } diff --git a/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/ContentsMenuEntryNodeTransformer.php b/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/ContentsMenuEntryNodeTransformer.php index 2ff0d4e0c..7883f8384 100644 --- a/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/ContentsMenuEntryNodeTransformer.php +++ b/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/ContentsMenuEntryNodeTransformer.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Guides\Compiler\NodeTransformers\MenuNodeTransformers; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Nodes\DocumentTree\SectionEntryNode; use phpDocumentor\Guides\Nodes\Menu\ContentMenuNode; use phpDocumentor\Guides\Nodes\Menu\MenuEntryNode; @@ -38,7 +38,7 @@ public function supports(Node $node): bool } /** @return list */ - protected function handleMenuEntry(MenuNode $currentMenu, MenuEntryNode $entryNode, CompilerContext $compilerContext): array + protected function handleMenuEntry(MenuNode $currentMenu, MenuEntryNode $entryNode, CompilerContextInterface $compilerContext): array { if (!$currentMenu instanceof ContentMenuNode) { return [$entryNode]; diff --git a/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/ExternalMenuEntryNodeTransformer.php b/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/ExternalMenuEntryNodeTransformer.php index da464c2b2..2efd0b167 100644 --- a/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/ExternalMenuEntryNodeTransformer.php +++ b/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/ExternalMenuEntryNodeTransformer.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Guides\Compiler\NodeTransformers\MenuNodeTransformers; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Nodes\DocumentTree\ExternalEntryNode; use phpDocumentor\Guides\Nodes\Menu\ExternalMenuEntryNode; use phpDocumentor\Guides\Nodes\Menu\MenuEntryNode; @@ -42,7 +42,7 @@ public function supports(Node $node): bool } /** @return list */ - protected function handleMenuEntry(MenuNode $currentMenu, MenuEntryNode $entryNode, CompilerContext $compilerContext): array + protected function handleMenuEntry(MenuNode $currentMenu, MenuEntryNode $entryNode, CompilerContextInterface $compilerContext): array { assert($entryNode instanceof ExternalMenuEntryNode); diff --git a/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/GlobMenuEntryNodeTransformer.php b/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/GlobMenuEntryNodeTransformer.php index b9c4e4045..28dae6e18 100644 --- a/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/GlobMenuEntryNodeTransformer.php +++ b/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/GlobMenuEntryNodeTransformer.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Guides\Compiler\NodeTransformers\MenuNodeTransformers; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Nodes\Menu\GlobMenuEntryNode; use phpDocumentor\Guides\Nodes\Menu\InternalMenuEntryNode; use phpDocumentor\Guides\Nodes\Menu\MenuEntryNode; @@ -38,7 +38,7 @@ final class GlobMenuEntryNodeTransformer extends AbstractMenuEntryNodeTransforme private const DEFAULT_MAX_LEVELS = 10; /** @return list */ - protected function handleMenuEntry(MenuNode $currentMenu, MenuEntryNode $entryNode, CompilerContext $compilerContext): array + protected function handleMenuEntry(MenuNode $currentMenu, MenuEntryNode $entryNode, CompilerContextInterface $compilerContext): array { assert($entryNode instanceof GlobMenuEntryNode); $maxDepth = (int) $currentMenu->getOption('maxdepth', self::DEFAULT_MAX_LEVELS); diff --git a/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/InternalMenuEntryNodeTransformer.php b/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/InternalMenuEntryNodeTransformer.php index 82245cc99..f4ec497a9 100644 --- a/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/InternalMenuEntryNodeTransformer.php +++ b/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/InternalMenuEntryNodeTransformer.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Guides\Compiler\NodeTransformers\MenuNodeTransformers; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Nodes\Menu\InternalMenuEntryNode; use phpDocumentor\Guides\Nodes\Menu\MenuEntryNode; use phpDocumentor\Guides\Nodes\Menu\MenuNode; @@ -49,7 +49,7 @@ public function supports(Node $node): bool } /** @return list */ - protected function handleMenuEntry(MenuNode $currentMenu, MenuEntryNode $entryNode, CompilerContext $compilerContext): array + protected function handleMenuEntry(MenuNode $currentMenu, MenuEntryNode $entryNode, CompilerContextInterface $compilerContext): array { assert($entryNode instanceof InternalMenuEntryNode); $documentEntries = $compilerContext->getProjectNode()->getAllDocumentEntries(); diff --git a/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/MenuEntryManagement.php b/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/MenuEntryManagement.php index a1ee0b245..73b918e9c 100644 --- a/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/MenuEntryManagement.php +++ b/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/MenuEntryManagement.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Guides\Compiler\NodeTransformers\MenuNodeTransformers; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Nodes\DocumentTree\DocumentEntryNode; use phpDocumentor\Guides\Nodes\DocumentTree\ExternalEntryNode; @@ -25,7 +25,7 @@ trait MenuEntryManagement /** @param array $entryNodes */ private function attachDocumentEntriesToParents( array $entryNodes, - CompilerContext $compilerContext, + CompilerContextInterface $compilerContext, string $currentPath, ): void { foreach ($entryNodes as $entryNode) { diff --git a/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/SubInternalMenuEntryNodeTransformer.php b/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/SubInternalMenuEntryNodeTransformer.php index e36270513..9aa777608 100644 --- a/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/SubInternalMenuEntryNodeTransformer.php +++ b/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/SubInternalMenuEntryNodeTransformer.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Guides\Compiler\NodeTransformers\MenuNodeTransformers; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Exception\DocumentEntryNotFound; use phpDocumentor\Guides\Nodes\DocumentTree\DocumentEntryNode; use phpDocumentor\Guides\Nodes\DocumentTree\ExternalEntryNode; @@ -41,7 +41,7 @@ public function supports(Node $node): bool } /** @return list */ - protected function handleMenuEntry(MenuNode $currentMenu, MenuEntryNode $entryNode, CompilerContext $compilerContext): array + protected function handleMenuEntry(MenuNode $currentMenu, MenuEntryNode $entryNode, CompilerContextInterface $compilerContext): array { assert($entryNode instanceof InternalMenuEntryNode); $maxDepth = (int) $currentMenu->getOption('maxdepth', self::DEFAULT_MAX_LEVELS); @@ -67,7 +67,7 @@ public function getPriority(): int private function addSubEntries( MenuNode $currentMenu, - CompilerContext $compilerContext, + CompilerContextInterface $compilerContext, InternalMenuEntryNode $sectionMenuEntry, DocumentEntryNode $documentEntry, int $currentLevel, diff --git a/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/TocNodeTransformer.php b/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/TocNodeTransformer.php index 590c7c778..f69643e4c 100644 --- a/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/TocNodeTransformer.php +++ b/packages/guides/src/Compiler/NodeTransformers/MenuNodeTransformers/TocNodeTransformer.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Guides\Compiler\NodeTransformers\MenuNodeTransformers; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Compiler\NodeTransformer; use phpDocumentor\Guides\Nodes\Menu\TocNode; use phpDocumentor\Guides\Nodes\Node; @@ -23,7 +23,7 @@ /** @implements NodeTransformer */ final class TocNodeTransformer implements NodeTransformer { - public function enterNode(Node $node, CompilerContext $compilerContext): Node + public function enterNode(Node $node, CompilerContextInterface $compilerContext): Node { assert($node instanceof TocNode); $compilerContext->getDocumentNode()->addTocNode($node); @@ -31,7 +31,7 @@ public function enterNode(Node $node, CompilerContext $compilerContext): Node return $node; } - public function leaveNode(Node $node, CompilerContext $compilerContext): Node|null + public function leaveNode(Node $node, CompilerContextInterface $compilerContext): Node|null { return $node; } diff --git a/packages/guides/src/Compiler/NodeTransformers/MoveAnchorTransformer.php b/packages/guides/src/Compiler/NodeTransformers/MoveAnchorTransformer.php index 6c3158f2b..9b6ef3c8f 100644 --- a/packages/guides/src/Compiler/NodeTransformers/MoveAnchorTransformer.php +++ b/packages/guides/src/Compiler/NodeTransformers/MoveAnchorTransformer.php @@ -15,7 +15,7 @@ use ArrayIterator; use LogicException; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Compiler\NodeTransformer; use phpDocumentor\Guides\Compiler\ShadowTree\TreeNode; use phpDocumentor\Guides\Nodes\AnchorNode; @@ -34,12 +34,12 @@ public function __construct() $this->seen = new WeakMap(); } - public function enterNode(Node $node, CompilerContext $compilerContext): Node + public function enterNode(Node $node, CompilerContextInterface $compilerContext): Node { return $node; } - public function leaveNode(Node $node, CompilerContext $compilerContext): Node|null + public function leaveNode(Node $node, CompilerContextInterface $compilerContext): Node|null { //When exists in seen, it means that the node has already been processed. Ignore it. if (isset($this->seen[$node])) { diff --git a/packages/guides/src/Compiler/NodeTransformers/SectionCreationTransformer.php b/packages/guides/src/Compiler/NodeTransformers/SectionCreationTransformer.php index 00bcf0565..dbda6251b 100644 --- a/packages/guides/src/Compiler/NodeTransformers/SectionCreationTransformer.php +++ b/packages/guides/src/Compiler/NodeTransformers/SectionCreationTransformer.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Guides\Compiler\NodeTransformers; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Compiler\NodeTransformer; use phpDocumentor\Guides\Nodes\DocumentNode; use phpDocumentor\Guides\Nodes\Node; @@ -32,7 +32,7 @@ final class SectionCreationTransformer implements NodeTransformer /** @var SectionNode[] $sectionStack */ private array $sectionStack = []; - public function enterNode(Node $node, CompilerContext $compilerContext): Node + public function enterNode(Node $node, CompilerContextInterface $compilerContext): Node { if (!$compilerContext->getShadowTree()->getParent()?->getNode() instanceof DocumentNode) { return $node; @@ -48,7 +48,7 @@ public function enterNode(Node $node, CompilerContext $compilerContext): Node return $node; } - public function leaveNode(Node $node, CompilerContext $compilerContext): Node|null + public function leaveNode(Node $node, CompilerContextInterface $compilerContext): Node|null { if (!$compilerContext->getShadowTree()->getParent()?->getNode() instanceof DocumentNode) { return $node; diff --git a/packages/guides/src/Compiler/NodeTransformers/SectionEntryRegistrationTransformer.php b/packages/guides/src/Compiler/NodeTransformers/SectionEntryRegistrationTransformer.php index 136964ec3..de7e2cc0f 100644 --- a/packages/guides/src/Compiler/NodeTransformers/SectionEntryRegistrationTransformer.php +++ b/packages/guides/src/Compiler/NodeTransformers/SectionEntryRegistrationTransformer.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Guides\Compiler\NodeTransformers; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Compiler\NodeTransformer; use phpDocumentor\Guides\Nodes\DocumentTree\SectionEntryNode; use phpDocumentor\Guides\Nodes\Node; @@ -30,7 +30,7 @@ final class SectionEntryRegistrationTransformer implements NodeTransformer /** @var SectionEntryNode[] $sectionStack */ private array $sectionStack = []; - public function enterNode(Node $node, CompilerContext $compilerContext): Node + public function enterNode(Node $node, CompilerContextInterface $compilerContext): Node { if (!$node instanceof SectionNode) { return $node; @@ -50,7 +50,7 @@ public function enterNode(Node $node, CompilerContext $compilerContext): Node return $node; } - public function leaveNode(Node $node, CompilerContext $compilerContext): Node|null + public function leaveNode(Node $node, CompilerContextInterface $compilerContext): Node|null { if (!$node instanceof SectionNode) { return $node; diff --git a/packages/guides/src/Compiler/NodeTransformers/TransformerPass.php b/packages/guides/src/Compiler/NodeTransformers/TransformerPass.php index 4ede37e1c..e2db86e59 100644 --- a/packages/guides/src/Compiler/NodeTransformers/TransformerPass.php +++ b/packages/guides/src/Compiler/NodeTransformers/TransformerPass.php @@ -14,6 +14,7 @@ namespace phpDocumentor\Guides\Compiler\NodeTransformers; use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Compiler\CompilerPass; use phpDocumentor\Guides\Compiler\DocumentNodeTraverser; use phpDocumentor\Guides\Nodes\DocumentNode; diff --git a/packages/guides/src/Compiler/NodeTransformers/VariableInlineNodeTransformer.php b/packages/guides/src/Compiler/NodeTransformers/VariableInlineNodeTransformer.php index 7d53eac8c..7d2a0c6b5 100644 --- a/packages/guides/src/Compiler/NodeTransformers/VariableInlineNodeTransformer.php +++ b/packages/guides/src/Compiler/NodeTransformers/VariableInlineNodeTransformer.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Guides\Compiler\NodeTransformers; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Compiler\NodeTransformer; use phpDocumentor\Guides\Nodes\Inline\PlainTextInlineNode; use phpDocumentor\Guides\Nodes\Inline\VariableInlineNode; @@ -33,12 +33,12 @@ public function __construct( ) { } - public function enterNode(Node $node, CompilerContext $compilerContext): Node + public function enterNode(Node $node, CompilerContextInterface $compilerContext): Node { return $node; } - public function leaveNode(Node $node, CompilerContext $compilerContext): Node|null + public function leaveNode(Node $node, CompilerContextInterface $compilerContext): Node|null { if (!$node instanceof VariableInlineNode) { return $node; diff --git a/packages/guides/src/Compiler/Passes/GlobalMenuPass.php b/packages/guides/src/Compiler/Passes/GlobalMenuPass.php index a74163a98..edc97ba8a 100644 --- a/packages/guides/src/Compiler/Passes/GlobalMenuPass.php +++ b/packages/guides/src/Compiler/Passes/GlobalMenuPass.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Guides\Compiler\Passes; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Compiler\CompilerPass; use phpDocumentor\Guides\Nodes\DocumentNode; use phpDocumentor\Guides\Nodes\DocumentTree\DocumentEntryNode; @@ -50,7 +50,7 @@ public function getPriority(): int * * @return DocumentNode[] */ - public function run(array $documents, CompilerContext $compilerContext): array + public function run(array $documents, CompilerContextInterface $compilerContext): array { $projectNode = $compilerContext->getProjectNode(); try { @@ -83,7 +83,7 @@ public function run(array $documents, CompilerContext $compilerContext): array return $documents; } - private function getNavMenuNodefromTocNode(CompilerContext $compilerContext, TocNode $tocNode, string|null $menuType = null): NavMenuNode + private function getNavMenuNodefromTocNode(CompilerContextInterface $compilerContext, TocNode $tocNode, string|null $menuType = null): NavMenuNode { $self = $this; $menuEntries = array_map(static function (MenuEntryNode $tocEntry) use ($compilerContext, $self) { @@ -104,7 +104,7 @@ private function getNavMenuNodefromTocNode(CompilerContext $compilerContext, Toc return $node; } - private function getMenuEntryWithChildren(CompilerContext $compilerContext, MenuEntryNode $menuEntry): MenuEntryNode + private function getMenuEntryWithChildren(CompilerContextInterface $compilerContext, MenuEntryNode $menuEntry): MenuEntryNode { if (!$menuEntry instanceof InternalMenuEntryNode) { return $menuEntry; @@ -121,7 +121,7 @@ private function getMenuEntryWithChildren(CompilerContext $compilerContext, Menu /** @param EntryNode|ExternalEntryNode $entryNode */ private function addSubEntries( - CompilerContext $compilerContext, + CompilerContextInterface $compilerContext, MenuEntryNode $sectionMenuEntry, EntryNode $entryNode, int $currentLevel, diff --git a/packages/guides/src/Compiler/Passes/ImplicitHyperlinkTargetPass.php b/packages/guides/src/Compiler/Passes/ImplicitHyperlinkTargetPass.php index 260bab199..6c7fcbd5f 100644 --- a/packages/guides/src/Compiler/Passes/ImplicitHyperlinkTargetPass.php +++ b/packages/guides/src/Compiler/Passes/ImplicitHyperlinkTargetPass.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Guides\Compiler\Passes; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Compiler\CompilerPass; use phpDocumentor\Guides\Nodes\AnchorNode; use phpDocumentor\Guides\Nodes\CompoundNode; @@ -43,7 +43,7 @@ public function getPriority(): int } /** {@inheritDoc} */ - public function run(array $documents, CompilerContext $compilerContext): array + public function run(array $documents, CompilerContextInterface $compilerContext): array { return array_map(function (DocumentNode $document): DocumentNode { // implicit references must not conflict with explicit ones diff --git a/packages/guides/src/Compiler/Passes/ToctreeValidationPass.php b/packages/guides/src/Compiler/Passes/ToctreeValidationPass.php index f4bdf880e..208f40e1c 100644 --- a/packages/guides/src/Compiler/Passes/ToctreeValidationPass.php +++ b/packages/guides/src/Compiler/Passes/ToctreeValidationPass.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Guides\Compiler\Passes; -use phpDocumentor\Guides\Compiler\CompilerContext; +use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Compiler\CompilerPass; use phpDocumentor\Guides\Nodes\DocumentNode; use phpDocumentor\Guides\Nodes\DocumentTree\DocumentEntryNode; @@ -37,7 +37,7 @@ public function getPriority(): int * * @return DocumentNode[] */ - public function run(array $documents, CompilerContext $compilerContext): array + public function run(array $documents, CompilerContextInterface $compilerContext): array { $projectNode = $compilerContext->getProjectNode(); From e8a578edd43ad866df29ef0dc1dfa03d7b18081e Mon Sep 17 00:00:00 2001 From: Jaapio Date: Fri, 12 Apr 2024 13:36:34 +0200 Subject: [PATCH 2/2] Add deprecation trigger for context extension --- composer.json | 1 + composer.lock | 99 ++++++++++--------- packages/guides/composer.json | 1 + .../guides/src/Compiler/CompilerContext.php | 10 ++ .../NodeTransformers/TransformerPass.php | 1 - .../unit/Compiler/CompilerContextTest.php | 36 +++++++ phpstan-baseline.neon | 15 +++ psalm-baseline.xml | 7 +- 8 files changed, 119 insertions(+), 51 deletions(-) create mode 100644 packages/guides/tests/unit/Compiler/CompilerContextTest.php diff --git a/composer.json b/composer.json index 9ea29c817..f0a30fda4 100644 --- a/composer.json +++ b/composer.json @@ -36,6 +36,7 @@ "php": "^8.1", "ext-json": "*", "ext-mbstring": "*", + "doctrine/deprecations": "^1.1", "phpdocumentor/guides": "^1.0@dev || ^0.3", "phpdocumentor/guides-cli": "^1.0@dev || ^0.3", "phpdocumentor/guides-code": "^1.0@dev || ^0.3", diff --git a/composer.lock b/composer.lock index d5cf8b8de..9f57eb328 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "57f312472c8bd34d142bbfe5cda544fb", + "content-hash": "a920fe635ecef8b4d0825b2f97a08ff2", "packages": [ { "name": "dflydev/dot-access-data", @@ -81,6 +81,53 @@ }, "time": "2022-10-27T11:44:00+00:00" }, + { + "name": "doctrine/deprecations", + "version": "1.1.3", + "source": { + "type": "git", + "url": "https://github.com/doctrine/deprecations.git", + "reference": "dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/deprecations/zipball/dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab", + "reference": "dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "doctrine/coding-standard": "^9", + "phpstan/phpstan": "1.4.10 || 1.10.15", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "psalm/plugin-phpunit": "0.18.4", + "psr/log": "^1 || ^2 || ^3", + "vimeo/psalm": "4.30.0 || 5.12.0" + }, + "suggest": { + "psr/log": "Allows logging deprecations via PSR-3 logger implementation" + }, + "type": "library", + "autoload": { + "psr-4": { + "Doctrine\\Deprecations\\": "lib/Doctrine/Deprecations" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages.", + "homepage": "https://www.doctrine-project.org/", + "support": { + "issues": "https://github.com/doctrine/deprecations/issues", + "source": "https://github.com/doctrine/deprecations/tree/1.1.3" + }, + "time": "2024-01-30T19:34:25+00:00" + }, { "name": "doctrine/lexer", "version": "3.0.1", @@ -1173,9 +1220,10 @@ "dist": { "type": "path", "url": "./packages/guides", - "reference": "7f6292a52a662791118b99ee519aeb4620b80887" + "reference": "3b2665a08dc0d92e3990780b43d22068ac130c5f" }, "require": { + "doctrine/deprecations": "^1.0", "ext-json": "*", "ext-zlib": "*", "league/flysystem": "^1.1", @@ -4300,53 +4348,6 @@ }, "time": "2023-04-24T17:43:28+00:00" }, - { - "name": "doctrine/deprecations", - "version": "1.1.3", - "source": { - "type": "git", - "url": "https://github.com/doctrine/deprecations.git", - "reference": "dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/deprecations/zipball/dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab", - "reference": "dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab", - "shasum": "" - }, - "require": { - "php": "^7.1 || ^8.0" - }, - "require-dev": { - "doctrine/coding-standard": "^9", - "phpstan/phpstan": "1.4.10 || 1.10.15", - "phpstan/phpstan-phpunit": "^1.0", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "psalm/plugin-phpunit": "0.18.4", - "psr/log": "^1 || ^2 || ^3", - "vimeo/psalm": "4.30.0 || 5.12.0" - }, - "suggest": { - "psr/log": "Allows logging deprecations via PSR-3 logger implementation" - }, - "type": "library", - "autoload": { - "psr-4": { - "Doctrine\\Deprecations\\": "lib/Doctrine/Deprecations" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages.", - "homepage": "https://www.doctrine-project.org/", - "support": { - "issues": "https://github.com/doctrine/deprecations/issues", - "source": "https://github.com/doctrine/deprecations/tree/1.1.3" - }, - "time": "2024-01-30T19:34:25+00:00" - }, { "name": "fakerphp/faker", "version": "v1.23.1", diff --git a/packages/guides/composer.json b/packages/guides/composer.json index 33e00ac41..ee566c1fc 100644 --- a/packages/guides/composer.json +++ b/packages/guides/composer.json @@ -24,6 +24,7 @@ "php": "^8.1", "ext-json": "*", "ext-zlib": "*", + "doctrine/deprecations": "^1.0", "league/flysystem": "^1.1", "league/tactician": "^1.1", "league/uri": "^6.5 || ^7.0", diff --git a/packages/guides/src/Compiler/CompilerContext.php b/packages/guides/src/Compiler/CompilerContext.php index 3b8d794cc..45a1c40fd 100644 --- a/packages/guides/src/Compiler/CompilerContext.php +++ b/packages/guides/src/Compiler/CompilerContext.php @@ -13,6 +13,7 @@ namespace phpDocumentor\Guides\Compiler; +use Doctrine\Deprecations\Deprecation; use Exception; use phpDocumentor\Guides\Compiler\ShadowTree\TreeNode; use phpDocumentor\Guides\Nodes\DocumentNode; @@ -38,6 +39,15 @@ class CompilerContext implements CompilerContextInterface public function __construct( private readonly ProjectNode $projectNode, ) { + if (self::class === static::class) { + return; + } + + Deprecation::trigger( + 'phpdocumentor/guides', + 'https://github.com/phpDocumentor/guides/issues/971', + 'Extending CompilerContext is deprecated, please use the CompilerContextInterface instead.', + ); } public function getProjectNode(): ProjectNode diff --git a/packages/guides/src/Compiler/NodeTransformers/TransformerPass.php b/packages/guides/src/Compiler/NodeTransformers/TransformerPass.php index e2db86e59..4ede37e1c 100644 --- a/packages/guides/src/Compiler/NodeTransformers/TransformerPass.php +++ b/packages/guides/src/Compiler/NodeTransformers/TransformerPass.php @@ -14,7 +14,6 @@ namespace phpDocumentor\Guides\Compiler\NodeTransformers; use phpDocumentor\Guides\Compiler\CompilerContext; -use phpDocumentor\Guides\Compiler\CompilerContextInterface; use phpDocumentor\Guides\Compiler\CompilerPass; use phpDocumentor\Guides\Compiler\DocumentNodeTraverser; use phpDocumentor\Guides\Nodes\DocumentNode; diff --git a/packages/guides/tests/unit/Compiler/CompilerContextTest.php b/packages/guides/tests/unit/Compiler/CompilerContextTest.php new file mode 100644 index 000000000..075bee7a0 --- /dev/null +++ b/packages/guides/tests/unit/Compiler/CompilerContextTest.php @@ -0,0 +1,36 @@ +expectDeprecationWithIdentifier('https://github.com/phpDocumentor/guides/issues/971'); + $context = new class (new ProjectNode()) extends CompilerContext{ + }; + } + + public function testNoDeprecationOnNormalConstruct(): void + { + $this->expectNoDeprecationWithIdentifier('https://github.com/phpDocumentor/guides/issues/971'); + $context = new CompilerContext(new ProjectNode()); + } +} diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b6d29bd1e..e729bfea9 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -120,6 +120,16 @@ parameters: count: 1 path: packages/guides-restructured-text/src/RestructuredText/Parser/Productions/ListRule.php + - + message: "#^Strict comparison using \\=\\=\\= between 'phpDocumentor\\\\\\\\Guides\\\\\\\\Compiler\\\\\\\\CompilerContext' and 'phpDocumentor\\\\\\\\Guides\\\\\\\\Compiler\\\\\\\\CompilerContext' will always evaluate to true\\.$#" + count: 1 + path: packages/guides/src/Compiler/CompilerContext.php + + - + message: "#^Unreachable statement \\- code above always terminates\\.$#" + count: 1 + path: packages/guides/src/Compiler/CompilerContext.php + - message: "#^Function Symfony\\\\Component\\\\DependencyInjection\\\\Loader\\\\Configurator\\\\tagged_iterator not found\\.$#" count: 2 @@ -140,6 +150,11 @@ parameters: count: 1 path: packages/guides/src/Renderer/DocumentListIterator.php + - + message: "#^Anonymous class extends @final class phpDocumentor\\\\Guides\\\\Compiler\\\\CompilerContext\\.$#" + count: 1 + path: packages/guides/tests/unit/Compiler/CompilerContextTest.php + - message: "#^Return type \\(iterable\\\\) of method class@anonymous/packages/guides/tests/unit/Compiler/NodeTransformers/MoveAnchorTransformerTest\\.php\\:32\\:\\:getTransformers\\(\\) should be compatible with return type \\(iterable\\\\>\\) of method phpDocumentor\\\\Guides\\\\Compiler\\\\NodeTransformers\\\\NodeTransformerFactory\\:\\:getTransformers\\(\\)$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 9c44f71c9..2db3ae9d9 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + @@ -55,6 +55,11 @@ value]]> + + + + +