Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php codesniffer returns nothing ... is my code in standard?

I have a laravel application (created with composer) that I am trying to ensure meets PHP coding standards (level PSR-1). I run:

$ phpcs --standard=PSR1 my_app/

And within a few seconds it returns with just a new, empty, ready-to-go command line:

$

Does this mean my code meets all requirements and standards in PSR-1? It does the same with just:

$ phpcs my_app/
$ phpcs --standard=PEAR my_app/
$ phpcs --standard=PSR1 --report=summary lauras_app/

I just want to make sure that if the commands return nothing, that means my code is in standard. Thank you!

like image 941
Laura_E Avatar asked Oct 18 '22 06:10

Laura_E


2 Answers

Phpcs does not output anything if it does detect no errors. From their doc:

By default, PHP_CodeSniffer will run quietly, only printing the report of errors and warnings at the end. If you are checking a large number of files, you may have to wait a while to see the report. If you want to know what is happening, you can turn on progress or verbose output.

There are 2 different options to see what phpcs is doing.

Using show_progress

With progress output enabled, PHP_CodeSniffer will print a single-character status for each file being checked

phpcs --config-set show_progress 1 --standard=PSR1 my_app/

or -p.

phpcs -p --standard=PSR1 my_app/

The second option is to use the verbose flag -v. You can set it up to -vvv to increase the details.

With verbose output enabled, PHP_CodeSniffer will print the file that it is checking, show you how many tokens and lines the file contains, and let you know how long it took to process.

phpcs -v --standard=PSR1 my_app/
like image 171
cb0 Avatar answered Oct 21 '22 01:10

cb0


In my case it was the file extension: you have to specify the file extension if it is not a standard one:

By default, PHP_CodeSniffer will check any file it finds with a .inc, .php, .js or .css extension,

WIKI

To check a .module file:

phpcs --standard=Drupal --extensions=module example.module
like image 27
Achraf JEDAY Avatar answered Oct 21 '22 02:10

Achraf JEDAY