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

Let's get PHP_CodeSniffer working with Backdrop #10

Open
alanmels opened this issue Mar 1, 2020 · 6 comments
Open

Let's get PHP_CodeSniffer working with Backdrop #10

alanmels opened this issue Mar 1, 2020 · 6 comments

Comments

@alanmels
Copy link
Member

alanmels commented Mar 1, 2020

I am trying to get PHP_CodeSniffer working with Backdrop. So far I've got it installed on OS level by taking the following steps:

sudo pear channel-update pear.php.net
sudo pear install PHP_CodeSniffer
sudo ln -sv /var/www/docroot/modules/coder_review/coder_sniffer/Backdrop $(pear config-get php_dir)/PHP/CodeSniffer/Standards
sudo phpcs --config-set installed_paths /var/www/docroot/modules/coder_review/coder_sniffer
sudo phpcbf --config-set installed_paths /var/www/docroot/modules/coder_review/coder_sniffer

and now the both the phpcs -i and phpcbf -i commands output:

The installed coding standards are Squiz, Zend, MySource, PSR1, PEAR, PSR2, PSR12 and Backdrop

However, Backdrop is not picking up PHP_CodeSniffer and the status page still shows:

Coder Review 
PHP_CodeSniffer not installed. 
Coder review uses PHP_CodeSniffer to perform better code review checks; Code_Sniffer is not a requirement, but it is helpful. Use "drush install-php-code-sniffer" to help install.

Also running simple phpcs --standard=Backdrop -e command outputs the error:

docker@cli:/var/www/docroot/modules$ phpcs --standard=Backdrop -e

Fatal error: Class 'Generic_Sniffs_Strings_UnnecessaryStringConcatSniff' not found in /var/www/docroot/modules/coder_review/coder_sniffer/Backdrop/Sniffs/Strings/UnnecessaryStringConcatSniff.php on line 30

Call Stack:
    0.0011     371072   1. {main}() /usr/local/bin/phpcs:0
    0.0045     531672   2. PHP_CodeSniffer\Runner->runPHPCS() /usr/local/bin/phpcs:18
    0.0232     901376   3. PHP_CodeSniffer\Runner->init() /usr/local/lib/php/PHP/CodeSniffer/src/Runner.php:70
    0.0309    1138136   4. PHP_CodeSniffer\Ruleset->__construct() /usr/local/lib/php/PHP/CodeSniffer/src/Runner.php:332
    0.1454    1187120   5. PHP_CodeSniffer\Ruleset->registerSniffs() /usr/local/lib/php/PHP/CodeSniffer/src/Ruleset.php:217
    0.1455    1187120   6. PHP_CodeSniffer\Autoload::loadFile() /usr/local/lib/php/PHP/CodeSniffer/src/Ruleset.php:1156
    0.1458    1214456   7. include('/var/www/docroot/modules/coder_review/coder_sniffer/Backdrop/Sniffs/Strings/UnnecessaryStringConcatSniff.php') /usr/local/lib/php/PHP/CodeSniffer/autoload.php:167

docker@cli:/var/www/docroot/modules$ 

Any further hints would be appreciated on how to get PHP_CodeSniffer working with Backdrop.

@alanmels
Copy link
Member Author

alanmels commented Mar 1, 2020

The above way was an attempt to get it working without Composer, however this might need to be resolved together with #3.

@alanmels
Copy link
Member Author

alanmels commented Mar 1, 2020

According to https://www.drupal.org/project/coder/issues/2809335 Codesniffer 3 is not supported, so I downgraded back to PHP_CodeSniffer-2.9.1:

sudo pear uninstall PHP_CodeSniffer
sudo pear install PHP_CodeSniffer-2.9.1

the same command phpcs --standard=Backdrop -e is giving different error instead:

docker@cli:/var/www/docroot/modules$ phpcs --standard=Backdrop -e

Fatal error: Uncaught PHP_CodeSniffer_Exception: Referenced sniff "Generic.Formatting.SpaceAfterCast" does not exist in /usr/local/lib/php/PHP/CodeSniffer.php on line 1167

PHP_CodeSniffer_Exception: Referenced sniff "Generic.Formatting.SpaceAfterCast" does not exist in /usr/local/lib/php/PHP/CodeSniffer.php on line 1167

Call Stack:
    0.0009     371528   1. {main}() /usr/local/bin/phpcs:0
    0.0180    1391640   2. PHP_CodeSniffer_CLI->runphpcs() /usr/local/bin/phpcs:25
    0.0186    1436496   3. PHP_CodeSniffer_CLI->process() /usr/local/lib/php/PHP/CodeSniffer/CLI.php:113
    0.0292    1441448   4. PHP_CodeSniffer_CLI->explainStandard() /usr/local/lib/php/PHP/CodeSniffer/CLI.php:948
    0.0294    1442152   5. PHP_CodeSniffer->process() /usr/local/lib/php/PHP/CodeSniffer/CLI.php:1203
    0.0294    1442152   6. PHP_CodeSniffer->initStandard() /usr/local/lib/php/PHP/CodeSniffer.php:505
    0.0298    1442616   7. PHP_CodeSniffer->processRuleset() /usr/local/lib/php/PHP/CodeSniffer.php:578
    0.1026    1463072   8. PHP_CodeSniffer->_expandRulesetReference() /usr/local/lib/php/PHP/CodeSniffer.php:780

docker@cli:/var/www/docroot/modules$

@jenlampton
Copy link
Member

jenlampton commented Jun 12, 2020

I'm adding PHPCS code reviews for my Backdrop contrib projects using github actions. I was able to get results only by using PHP 5.6, and version 1.5.6 of PHPCS.

I ran into all the same problems you hit @alanmels and downgrading PHPCS to earlier versions was the answer each time.

I think Drupal 7 is on version 2 (to get PHP 7.3 support) and Drupal 8 is on version 3 now. See Related: https://www.drupal.org/project/coder/issues/2863898

@alanmels
Copy link
Member Author

Thank you, Jen, for your input. I think your finding needs to be reflected on Backdrop's UI so users avoid hitting the same problems.

@jenlampton
Copy link
Member

jenlampton commented Jun 13, 2020 via email

@izmeez
Copy link

izmeez commented Oct 15, 2023

I just added the phpcs.phar with a direct download and was able to get it working with VSCode without any composer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants