Skip to content

Commit

Permalink
[TASK] Improve warning vor invalid method names (#37)
Browse files Browse the repository at this point in the history
Output context and make more clear we are talking about a method description here
  • Loading branch information
linawolf committed Mar 2, 2024
1 parent b4b38b8 commit cec5826
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Directives/Php/MethodDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected function processSub(
CollectionNode $collectionNode,
Directive $directive,
): Node|null {
$name = $this->methodNameService->getMethodName(trim($directive->getData()));
$name = $this->methodNameService->getMethodName($blockContext, trim($directive->getData()));
$id = $this->anchorNormalizer->reduceAnchor($name->toString());

$modifiers = $this->modifierService->getModifiersFromDirectiveOptions($directive, $this->allowedModifiers);
Expand Down
2 changes: 1 addition & 1 deletion src/Directives/Php/StaticMethodDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function processSub(
'Directive `.. php:staticmethod::` is deprecated use directive `.. php:method::` with option `:static:` instead. ',
$blockContext->getLoggerInformation()
);
$name = $this->methodNameService->getMethodName(trim($directive->getData()));
$name = $this->methodNameService->getMethodName($blockContext, trim($directive->getData()));
$id = $this->anchorNormalizer->reduceAnchor($name->toString());

return new PhpMethodNode(
Expand Down
5 changes: 3 additions & 2 deletions src/PhpDomain/MethodNameService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace T3Docs\GuidesPhpDomain\PhpDomain;

use phpDocumentor\Guides\RestructuredText\Parser\BlockContext;
use Psr\Log\LoggerInterface;
use T3Docs\GuidesPhpDomain\Nodes\MethodNameNode;

Expand All @@ -18,7 +19,7 @@ public function __construct(
private readonly LoggerInterface $logger
) {}

public function getMethodName(string $name): MethodNameNode
public function getMethodName(BlockContext $blockContext, string $name): MethodNameNode
{
if (preg_match(self::METHOD_SIGNATURE_REGEX, $name, $matches)) {
$methodName = $matches[1];
Expand All @@ -30,7 +31,7 @@ public function getMethodName(string $name): MethodNameNode
}
return new MethodNameNode($methodName, $parametersArray, $returnType);
}
$this->logger->warning(sprintf('Method signature %s is invalid. ', $name));
$this->logger->warning(sprintf('Method signature %s in PHP-domain method description is invalid. ', $name), $blockContext->getLoggerInformation());
return new MethodNameNode($name, [], null);
}
}

0 comments on commit cec5826

Please sign in to comment.