Skip to content

Commit

Permalink
[TASK] Improve warnings to contain line numbers. (#29)
Browse files Browse the repository at this point in the history
This was previously not possible due to a bug in the directive
  • Loading branch information
linawolf authored Dec 13, 2023
1 parent e92c96e commit bed620c
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/Directives/Php/ClassDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function processSub(
$modifiers = $this->modifierService->getModifiersFromDirectiveOptions($directive, $this->allowedModifiers);

if ($directive->hasOption('abstract') && $directive->hasOption('final')) {
$this->logger->warning('A PHP class cannot be abstract and final at the same time.', $blockContext->getDocumentParserContext()->getLoggerInformation());
$this->logger->warning('A PHP class cannot be abstract and final at the same time.', $blockContext->getLoggerInformation());
}

return new PhpClassNode(
Expand Down
2 changes: 1 addition & 1 deletion src/Directives/Php/ConstDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function processSub(

foreach ($this->illegalCombinations as $combination) {
if ($directive->hasOption($combination[0]) && $directive->hasOption($combination[1])) {
$this->logger->warning(sprintf('A PHP constant cannot be %s and %s at the same time.', $combination[0], $combination[1]), $blockContext->getDocumentParserContext()->getLoggerInformation());
$this->logger->warning(sprintf('A PHP constant cannot be %s and %s at the same time.', $combination[0], $combination[1]), $blockContext->getLoggerInformation());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Directives/Php/EnumDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function processSub(
if (str_contains($name, ':')) {
[$name, $type] = explode(':', $name, 2);
$type = trim($type);
$this->logger->warning('Passing the type of a backed enum directly with the name is deprecated. Use option :type: instead.', $blockContext->getDocumentParserContext()->getLoggerInformation());
$this->logger->warning('Passing the type of a backed enum directly with the name is deprecated. Use option :type: instead.', $blockContext->getLoggerInformation());
}

$fqn = $this->fullyQualifiedNameService->getFullyQualifiedName(trim($name), true);
Expand All @@ -54,7 +54,7 @@ protected function processSub(

if ($directive->hasOption('type')) {
if ($type != null) {
$this->logger->warning('The type of the backed enum was set twice. The type from the option will be prefered.', $blockContext->getDocumentParserContext()->getLoggerInformation());
$this->logger->warning('The type of the backed enum was set twice. The type from the option will be prefered.', $blockContext->getLoggerInformation());
}
$type = $directive->getOption('type')->toString();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Directives/Php/ExceptionDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function processSub(
$modifiers = $this->modifierService->getModifiersFromDirectiveOptions($directive, $this->allowedModifiers);

if ($directive->hasOption('abstract') && $directive->hasOption('final')) {
$this->logger->warning('A PHP class cannot be abstract and final at the same time.', $blockContext->getDocumentParserContext()->getLoggerInformation());
$this->logger->warning('A PHP class cannot be abstract and final at the same time.', $blockContext->getLoggerInformation());
}

return new PhpExceptionNode(
Expand Down
6 changes: 3 additions & 3 deletions src/Directives/Php/MethodDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ private function extractReturnDescriptionFromFieldListItem(?CollectionNode $retu
.. :php:method:: %s
:returns: Your Description
", $name), $blockContext->getDocumentParserContext()->getLoggerInformation());
", $name), $blockContext->getLoggerInformation());
} else {
$this->logger->warning(sprintf('The return description of method %s has been given multiple times', $name), $blockContext->getDocumentParserContext()->getLoggerInformation());
$this->logger->warning(sprintf('The return description of method %s has been given multiple times', $name), $blockContext->getLoggerInformation());
}
return $returnInlineNode;
}
Expand All @@ -110,7 +110,7 @@ protected function processSub(

foreach ($this->illegalCombinations as $combination) {
if ($directive->hasOption($combination[0]) && $directive->hasOption($combination[1])) {
$this->logger->warning(sprintf('A PHP method cannot be %s and %s at the same time.', $combination[0], $combination[1]), $blockContext->getDocumentParserContext()->getLoggerInformation());
$this->logger->warning(sprintf('A PHP method cannot be %s and %s at the same time.', $combination[0], $combination[1]), $blockContext->getLoggerInformation());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Directives/Php/PropertyDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ protected function processSub(
$modifiers = $this->modifierService->getModifiersFromDirectiveOptions($directive, $this->allowedModifiers);

if ($directive->getName() !== 'php:property') {
$this->logger->warning(sprintf('Using directive `%s` is deprecated, use directive `php:property` instead.', $directive->getName()), $blockContext->getDocumentParserContext()->getLoggerInformation());
$this->logger->warning(sprintf('Using directive `%s` is deprecated, use directive `php:property` instead.', $directive->getName()), $blockContext->getLoggerInformation());
}

foreach ($this->illegalCombinations as $combination) {
if ($directive->hasOption($combination[0]) && $directive->hasOption($combination[1])) {
$this->logger->warning(sprintf('A PHP property cannot be %s and %s at the same time.', $combination[0], $combination[1]), $blockContext->getDocumentParserContext()->getLoggerInformation());
$this->logger->warning(sprintf('A PHP property cannot be %s and %s at the same time.', $combination[0], $combination[1]), $blockContext->getLoggerInformation());
}
}
$type = null;
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 @@ -42,7 +42,7 @@ protected function processSub(
): Node|null {
$this->logger->warning(
'Directive `.. php:staticmethod::` is deprecated use directive `.. php:method::` with option `:static:` instead. ',
$blockContext->getDocumentParserContext()->getLoggerInformation()
$blockContext->getLoggerInformation()
);
$name = $this->methodNameService->getMethodName(trim($directive->getData()));
$id = $this->anchorReducer->reduceAnchor($name->toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
app.WARNING: A PHP constant cannot be private and public at the same time. {"rst-file":"index.rst"} []
app.WARNING: A PHP constant cannot be protected and public at the same time. {"rst-file":"index.rst"} []
app.WARNING: A PHP constant cannot be private and protected at the same time. {"rst-file":"index.rst"} []
app.WARNING: A PHP constant cannot be private and public at the same time. {"rst-file":"index.rst","currentLineNumber":9} []
app.WARNING: A PHP constant cannot be protected and public at the same time. {"rst-file":"index.rst","currentLineNumber":16} []
app.WARNING: A PHP constant cannot be private and protected at the same time. {"rst-file":"index.rst","currentLineNumber":22} []
Original file line number Diff line number Diff line change
@@ -1 +1 @@
app.WARNING: Directive `.. php:staticmethod::` is deprecated use directive `.. php:method::` with option `:static:` instead. {"rst-file":"index.rst"} []
app.WARNING: Directive `.. php:staticmethod::` is deprecated use directive `.. php:method::` with option `:static:` instead. {"rst-file":"index.rst","currentLineNumber":5} []
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
app.WARNING: Passing the type of a backed enum directly with the name is deprecated. Use option :type: instead. {"rst-file":"index.rst"} []
app.WARNING: The type of the backed enum was set twice. The type from the option will be prefered. {"rst-file":"index.rst"} []
app.WARNING: Passing the type of a backed enum directly with the name is deprecated. Use option :type: instead. {"rst-file":"index.rst"} []
app.WARNING: Passing the type of a backed enum directly with the name is deprecated. Use option :type: instead. {"rst-file":"index.rst","currentLineNumber":21} []
app.WARNING: The type of the backed enum was set twice. The type from the option will be prefered. {"rst-file":"index.rst","currentLineNumber":21} []
app.WARNING: Passing the type of a backed enum directly with the name is deprecated. Use option :type: instead. {"rst-file":"index.rst","currentLineNumber":30} []
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
app.WARNING: A PHP method cannot be final and abstract at the same time. {"rst-file":"index.rst"} []
app.WARNING: A PHP method cannot be protected and public at the same time. {"rst-file":"index.rst"} []
app.WARNING: A PHP method cannot be private and public at the same time. {"rst-file":"index.rst"} []
app.WARNING: A PHP method cannot be private and protected at the same time. {"rst-file":"index.rst"} []
app.WARNING: A PHP method cannot be private and abstract at the same time. {"rst-file":"index.rst"} []
app.WARNING: A PHP method cannot be final and abstract at the same time. {"rst-file":"index.rst","currentLineNumber":10} []
app.WARNING: A PHP method cannot be protected and public at the same time. {"rst-file":"index.rst","currentLineNumber":16} []
app.WARNING: A PHP method cannot be private and public at the same time. {"rst-file":"index.rst","currentLineNumber":22} []
app.WARNING: A PHP method cannot be private and protected at the same time. {"rst-file":"index.rst","currentLineNumber":28} []
app.WARNING: A PHP method cannot be private and abstract at the same time. {"rst-file":"index.rst","currentLineNumber":33} []
2 changes: 1 addition & 1 deletion tests/integration/static-method/expected/logs/warning.log
Original file line number Diff line number Diff line change
@@ -1 +1 @@
app.WARNING: Directive `.. php:staticmethod::` is deprecated use directive `.. php:method::` with option `:static:` instead. {"rst-file":"index.rst"} []
app.WARNING: Directive `.. php:staticmethod::` is deprecated use directive `.. php:method::` with option `:static:` instead. {"rst-file":"index.rst","currentLineNumber":7} []

0 comments on commit bed620c

Please sign in to comment.