Skip to content

Commit

Permalink
[FEATURE] Make Fully Qualified name available in members node. (#41)
Browse files Browse the repository at this point in the history
* [FEATURE] Make Fully Qualified name available in members node.

This is used to suggest a rst reference snippet in the render-guides.

I can then offer the following code in the suggest wizzard:

:php:method:`somemanual:\LibraryName\LibraryClassFinal::firstmethod`

Instead of something like this:

:php:method:`somemanual:libraryname-libraryclassfinal-firstmethod`

* [TASK] Update integration test baseline

Whitespace handling changed in the guides, therefore
our integration tests need to be updated for whitespace.
  • Loading branch information
linawolf authored Mar 25, 2024
1 parent 03c0976 commit 77a6e5c
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 8 deletions.
7 changes: 6 additions & 1 deletion src/Directives/Php/ClassDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

final class ClassDirective extends SubDirective
{
use ComponentTrait;
/**
* @var string[]
*/
Expand Down Expand Up @@ -54,13 +55,17 @@ protected function processSub(
$this->logger->warning('A PHP class cannot be abstract and final at the same time.', $blockContext->getLoggerInformation());
}

return new PhpClassNode(
$node = new PhpClassNode(
$id,
$fqn,
$collectionNode->getChildren(),
null,
[],
$modifiers,
);

$this->setParentsForMembers($collectionNode, $node);

return $node;
}
}
20 changes: 20 additions & 0 deletions src/Directives/Php/ComponentTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace T3Docs\GuidesPhpDomain\Directives\Php;

use phpDocumentor\Guides\Nodes\CollectionNode;
use T3Docs\GuidesPhpDomain\Nodes\PhpComponentNode;
use T3Docs\GuidesPhpDomain\Nodes\PhpMemberNode;

trait ComponentTrait
{
private function setParentsForMembers(CollectionNode $collectionNode, PhpComponentNode $node): void
{
foreach ($collectionNode->getChildren() as $child) {
if (!$child instanceof PhpMemberNode) {
continue;
}
$child->setParentComponent($node);
}
}
}
6 changes: 5 additions & 1 deletion src/Directives/Php/EnumDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

final class EnumDirective extends SubDirective
{
use ComponentTrait;
public function __construct(
Rule $startingRule,
GenericLinkProvider $genericLinkProvider,
Expand Down Expand Up @@ -59,7 +60,7 @@ protected function processSub(
$type = $directive->getOption('type')->toString();
}

return new PhpEnumNode(
$node = new PhpEnumNode(
$id,
$fqn,
$collectionNode->getChildren(),
Expand All @@ -68,5 +69,8 @@ protected function processSub(
[],
$type,
);

$this->setParentsForMembers($collectionNode, $node);
return $node;
}
}
6 changes: 5 additions & 1 deletion src/Directives/Php/ExceptionDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

final class ExceptionDirective extends SubDirective
{
use ComponentTrait;
/**
* @var string[]
*/
Expand Down Expand Up @@ -54,13 +55,16 @@ protected function processSub(
$this->logger->warning('A PHP class cannot be abstract and final at the same time.', $blockContext->getLoggerInformation());
}

return new PhpExceptionNode(
$node = new PhpExceptionNode(
$id,
$fqn,
$collectionNode->getChildren(),
null,
[],
$modifiers,
);

$this->setParentsForMembers($collectionNode, $node);
return $node;
}
}
7 changes: 5 additions & 2 deletions src/Directives/Php/InterfaceDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

final class InterfaceDirective extends SubDirective
{
use ComponentTrait;
public function __construct(
Rule $startingRule,
GenericLinkProvider $genericLinkProvider,
Expand All @@ -41,13 +42,15 @@ protected function processSub(
$fqn = $this->fullyQualifiedNameService->getFullyQualifiedName($name, true);

$id = $this->anchorNormalizer->reduceAnchor($fqn->toString());

return new PhpInterfaceNode(
$node = new PhpInterfaceNode(
$id,
$fqn,
$collectionNode->getChildren(),
null,
[],
);

$this->setParentsForMembers($collectionNode, $node);
return $node;
}
}
7 changes: 5 additions & 2 deletions src/Directives/Php/TraitDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

final class TraitDirective extends SubDirective
{
use ComponentTrait;
public function __construct(
Rule $startingRule,
GenericLinkProvider $genericLinkProvider,
Expand All @@ -40,13 +41,15 @@ protected function processSub(
$name = trim($directive->getData());
$fqn = $this->fullyQualifiedNameService->getFullyQualifiedName($name, true);
$id = $this->anchorNormalizer->reduceAnchor($fqn->toString());

return new PhpTraitNode(
$node = new PhpTraitNode(
$id,
$fqn,
$collectionNode->getChildren(),
null,
[],
);

$this->setParentsForMembers($collectionNode, $node);
return $node;
}
}
21 changes: 20 additions & 1 deletion src/Nodes/PhpMemberNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function __construct(
private readonly string $type,
private readonly string $name,
array $value = [],
private ?PhpComponentNode $parentComponent = null,
) {
parent::__construct($value);
}
Expand All @@ -42,7 +43,7 @@ public function getLinkType(): string
}
public function getLinkText(): string
{
return $this->name;
return $this->getFullyQualifiedName();
}

public function getType(): string
Expand All @@ -54,4 +55,22 @@ public function getId(): string
{
return $this->id;
}

public function getParentComponent(): ?PhpComponentNode
{
return $this->parentComponent;
}

public function setParentComponent(?PhpComponentNode $parentComponent): void
{
$this->parentComponent = $parentComponent;
}

public function getFullyQualifiedName(): string
{
if ($this->parentComponent == null) {
return $this->getName();
}
return $this->parentComponent->getName()->toString() . '::' . $this->getName();
}
}

0 comments on commit 77a6e5c

Please sign in to comment.