magento-coding-standard
magento-coding-standard copied to clipboard
Strange behavior of Magento2.Annotation.MethodAnnotationStructure.MethodAnnotation check
Preconditions
-
magento/magento-coding-standard
version 12
Steps to reproduce
- Have a class like this:
<?php
declare(strict_types=1);
namespace Some\Namespace;
use Symfony\Component\Console\Output\OutputInterface;
class Progress
{
/** @var OutputInterface */
private $output;
private function methodOne(): bool
{
return false;
}
private function methodTwo(): bool
{
return false;
}
private function methodThree(): bool
{
return false;
}
}
- Run
vendor/bin/phpcs -s --standard=Magento2 --ignore=./vendor/ .
Expected result
- No confusing
Missing short description
andThere must be exactly one blank line before tags
warnings for the$output
parameter
Actual result
- Getting this output:
FILE: Progress.php
----------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 9 WARNINGS AFFECTING 4 LINES
----------------------------------------------------------------------------------------------------------------------------------
11 | WARNING | Missing short description (Magento2.Annotation.MethodAnnotationStructure.MethodAnnotation)
11 | WARNING | Missing short description (Magento2.Annotation.MethodAnnotationStructure.MethodAnnotation)
11 | WARNING | Missing short description (Magento2.Annotation.MethodAnnotationStructure.MethodAnnotation)
11 | WARNING | There must be exactly one blank line before tags
| | (Magento2.Annotation.MethodAnnotationStructure.MethodAnnotation)
11 | WARNING | There must be exactly one blank line before tags
| | (Magento2.Annotation.MethodAnnotationStructure.MethodAnnotation)
11 | WARNING | There must be exactly one blank line before tags
| | (Magento2.Annotation.MethodAnnotationStructure.MethodAnnotation)
14 | WARNING | Comment block is missing (Magento2.Annotation.MethodArguments.MethodArguments)
19 | WARNING | Comment block is missing (Magento2.Annotation.MethodArguments.MethodArguments)
24 | WARNING | Comment block is missing (Magento2.Annotation.MethodArguments.MethodArguments)
----------------------------------------------------------------------------------------------------------------------------------
Each time I add a new method, 2 more warnings for Missing short description
and There must be exactly one blank line before tags
appear that claim to have something to do with the $output
variable. Which is really confusing.
Hi @hostep. Thank you for your report. To help us process this issue please make sure that you provided sufficient information.
Please, add a comment to assign the issue: @magento I am working on this
- Join Magento Community Engineering Slack and ask your questions in #github channel.
It looks like a separate check should be introduces for single-line annotations within the Sniff
Magento version: CE 2.4.5 Coding Standard version: 25
<?php
declare(strict_types=1);
namespace Vendor\Module\Model;
class MyClass
{
//...
/**
* Some description
*/
private function getDurationText(\DateInterval $duration): string
{
//...
return '';
}
//...
}
fails with phpcs: Magento2.Annotation.MethodArguments.ParamMissing: Missing @param for argument in method annotation
, but all the method signature is covered by strict types
Also, why classes constructors requires docblocks? We were so happy about new php 8.1 feature with shorten class signature. Like it will decrease the amount of boilerplate code... And then Magento requires us to duplicate information in docblocks ("to duplicate" - because mostly all the methods are covered with strict types) and to write unnecessary descriptions for methods with obvious names and behaviors... :(
Woohoow, finally!