php-collective / code-sniffer

This sniffer package builds on top of PSR-2/12 and ships with a lot of additional fixers on top.
MIT License
5 stars 0 forks source link

Add PSR4 namespace check for classes, traits, interfaces. #14

Closed dereuromark closed 7 months ago

dereuromark commented 7 months ago

Try to port not maintained https://github.com/suin/phpcs-psr4-sniff

BUT: It doesn't quite seem to work

If I have a namespace of

Foo => src/Foo

defined, It does not report issues like

Foo\Bar\Baz => src/Foo/Baaaaa/Baz

Which it should IMO

dereuromark commented 7 months ago

Using getcwd() I think I was able to fix the base path handling, which then made it work for me.

dereuromark commented 7 months ago

One false positive issue left

    "autoload-dev": {
        "psr-4": {
            "QueueScheduler\\Test\\": "tests/",
            "Cake\\Test\\": "vendor/cakephp/cakephp/tests/",
            "TestApp\\": "tests/test_app/src/"
        }
    },

and

FILE: /work/git/cakephp-queue-scheduler/tests/test_app/src/Application.php
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 10 | ERROR | Class name is not compliant with PSR-4 configuration. It should be `QueueScheduler\Test\test_app\src\Application` instead of `TestApp\Application`. (PhpCollective.Classes.Psr4.IncorrectClassName)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------