magento-coding-standard icon indicating copy to clipboard operation
magento-coding-standard copied to clipboard

Strange behavior of Magento2.Annotation.MethodAnnotationStructure.MethodAnnotation check

Open hostep opened this issue 2 years ago • 3 comments

Preconditions

  1. magento/magento-coding-standard version 12

Steps to reproduce

  1. 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;
    }
}
  1. Run vendor/bin/phpcs -s --standard=Magento2 --ignore=./vendor/ .

Expected result

  1. No confusing Missing short description and There must be exactly one blank line before tags warnings for the $output parameter

Actual result

  1. 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.

hostep avatar Oct 02 '21 16:10 hostep

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


m2-assistant[bot] avatar Oct 02 '21 16:10 m2-assistant[bot]

It looks like a separate check should be introduces for single-line annotations within the Sniff

sivaschenko avatar Oct 13 '21 14:10 sivaschenko

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

image

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... :(

alexey-dorosh avatar Aug 26 '22 05:08 alexey-dorosh

Woohoow, finally!

hostep avatar Sep 27 '23 18:09 hostep