Skip to content

Strange behavior of Magento2.Annotation.MethodAnnotationStructure.MethodAnnotation check #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hostep opened this issue Oct 2, 2021 · 4 comments · Fixed by #437
Closed
Labels
bug Something isn't working Progress: done

Comments

@hostep
Copy link
Contributor

hostep commented Oct 2, 2021

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 hostep added the bug Something isn't working label Oct 2, 2021
@m2-assistant
Copy link

m2-assistant bot commented Oct 2, 2021

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


@sivaschenko
Copy link
Member

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

@alexey-dorosh
Copy link

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

@hostep
Copy link
Contributor Author

hostep commented Sep 27, 2023

Woohoow, finally!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Progress: done
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants