Skip to content
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

PHPCS & Doctrine annotations #453

Closed
ArchangelDesign opened this issue Aug 23, 2022 · 6 comments
Closed

PHPCS & Doctrine annotations #453

ArchangelDesign opened this issue Aug 23, 2022 · 6 comments
Labels
wontfix This will not be worked on

Comments

@ArchangelDesign
Copy link
Contributor

Not sure what we can do about this, but PHPCS clearly allows

'disable: single sniff, docblock, with @'      => [
                'before'         => '/**'.PHP_EOL.' * @phpcs:disable Generic.Commenting.Todo'.PHP_EOL.' */ ',
                'expectedErrors' => 1,
            ],

(this is from CS unit tests)
use of /** @phpcs:disable Something */ while Doctrine Annotation module treats it as missing class. This becomes a problem when you disable Generic.Files.LineLength.TooLong within a doc block of a class.
The above results in

Doctrine\Common\Annotations\AnnotationException
[Semantical Error] The annotation "@phpcs:disable" in class App\Model\Entity\EventsUser was never imported. Did you maybe forget to add a "use" statement for this annotation?

even if Hot Reload is disabled as

/cnizzardini/cakephp-swagger-bake/src/Lib/Swagger.php in SwaggerBake\Lib\Swagger::__construct at line 80

always calls

        $this->buildSchemasFromModels();
        $this->buildPathsFromRoutes();

In my view, all the data should be already written to swagger.json when swagger bake command runs. Why is there still any code analysis?

@cnizzardini
Copy link
Owner

What version?

@cnizzardini
Copy link
Owner

always calls

You're right, the constructor is probably doing too much here and should be refactored.

@cnizzardini
Copy link
Owner

However, you lost me on the main problem here. I am confused.

@ArchangelDesign
Copy link
Contributor Author

yeah, I guess it's not clear what the main problem here is. I'll look into this further so I can give you more definitive answer, but at the moment it looks like the library you used (annotations) does not agree with code sniffer. It's not exactly the problem of the library but given the wide use of cs, breaking compatibility with it is rather significant.
If you're suffering the same problem (to whomever reads this) move all cs override commands from doc block to comment block to go around the problem.
@cnizzardini I'll look into potential fixes to this problem. For now this is none-issue, that can be easily resolved (worked around).

@cnizzardini
Copy link
Owner

cnizzardini commented Aug 24, 2022

Okay I understand the problem now, how annoying. I am not sure if there is a way to exclude certain annotations with https://github.com/webmozart/doctrine-common/blob/master/lib/Doctrine/Common/Annotations/AnnotationReader.php, but I bet some try/catch blocks could perhaps handle this in here: https://github.com/cnizzardini/cakephp-swagger-bake/blob/1.next/src/Lib/Utility/AnnotationUtility.php

I'd imagine if the exception message doesn't contain SwaggerBake in the namespace then the exception can be ignored. A bit brittle, but I think it would be fine.

@cnizzardini cnizzardini added the bug Something isn't working label Aug 24, 2022
@cnizzardini cnizzardini added this to the v1.7.9 milestone Aug 24, 2022
@cnizzardini
Copy link
Owner

cnizzardini commented Aug 24, 2022

Eh, not possible, but I did find this: https://stackoverflow.com/questions/41496487/how-to-tell-symfony-3-to-ignore-certain-annotations

This worked for me, but I have no idea if it will suppress phpcs internals or not.

/**
 * @IgnoreAnnotation("phpcs:disable")
 */
class OperationsController extends AppController
{
    /**
     * @Swag\SwagOperation(isVisible=false)
     * @phpcs:disable testing
     */
    public function isVisible()
    {

    }
}

This also worked if I placed it in my config/bootstrap.php:

Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('phpcs:disable');

@cnizzardini cnizzardini added wontfix This will not be worked on and removed bug Something isn't working labels Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants