WordPress / WordPress-Coding-Standards

PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions
MIT License
2.54k stars 479 forks source link

Error message when running PHPCBF #1957

Closed jackjpdiscos closed 1 year ago

jackjpdiscos commented 3 years ago

Hi,

I get the following error when running the following command:

phpcbf --standard=WordPress _foldername_

vendor/bin/phpcbf : PHP Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: Trying to access array offset on value of type null in C:\xampp\php\vendor\wp-coding-standards\wpcs\WordPress\Sniff.php on line 1291 in C:\xampp\php\vendor\squizlabs\php_codesniffer\src\Runner.php:606 At line:1 char:1

vendor/bin/phpcbf --standard=WordPress MDJM\includes\actions.php

  • CategoryInfo : NotSpecified: (PHP Fatal error...\Runner.php:606:String) [], RemoteException
  • FullyQualifiedErrorId : NativeCommandError

Stack trace:

Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: Trying to access array offset on value of type null in C:\xampp\php \vendor\wp-coding-standards\wpcs\WordPress\Sniff.php on line 1291 in C:\xampp\php\vendor\squizlabs\php_codesniffer\src\Runner.php:606 Stack trace:

0 C:\xampp\php\vendor\wp-coding-standards\wpcs\WordPress\Sniff.php(1291): PHP_CodeSniffer\Runner->handleErrors(8, 'Trying to acces...

', 'C:\xampp\php\ve...', 1291, Array)

1 C:\xampp\php\vendor\wp-coding-standards\wpcs\WordPress\Sniffs\CSRF\NonceVerificationSniff.php(153): WordPress\Sniff->has_nonce_chec

k(117)

2 C:\xampp\php\vendor\wp-coding-standards\wpcs\WordPress\Sniff.php(832): WordPress\Sniffs\CSRF\NonceVerificationSniff->process_token(

117)

3 C:\xampp\php\vendor\squizlabs\php_codesniffer\src\Files\File.php(496): WordPress\Sniff->process(Object(PHP_CodeSniffer\Files\LocalF

ile), 117)

4 C:\xampp\php\vendor\squizlabs\php_codesniffer\src\Files\LocalFile.php(91): PHP_CodeSniffer\Files\File->process()

5 C:\xampp\php\vendor\squizlabs\php_cod in C:\xampp\php\vendor\squizlabs\php_codesniffer\src\Runner.php on line 606

0 C:\xampp\php\vendor\wp-coding-standards\wpcs\WordPress\Sniff.php(1291): PHP_CodeSniffer\Runner->handleErrors(8, 'Trying to

acces...', 'C:\xampp\php\ve...', 1291, Array)

1 C:\xampp\php\vendor\wp-coding-standards\wpcs\WordPress\Sniffs\CSRF\NonceVerificationSniff.php(153):

WordPress\Sniff->has_nonce_check(117)

2 C:\xampp\php\vendor\wp-coding-standards\wpcs\WordPress\Sniff.php(832):

WordPress\Sniffs\CSRF\NonceVerificationSniff->process_token(117)

3 C:\xampp\php\vendor\squizlabs\php_codesniffer\src\Files\File.php(496):

WordPress\Sniff->process(Object(PHP_CodeSniffer\Files\LocalFile), 117)

4 C:\xampp\php\vendor\squizlabs\php_codesniffer\src\Files\LocalFile.php(91): PHP_CodeSniffer\Files\File->process()

5 C:\xampp\php\vendor\squizlabs\php_cod in C:\xampp\php\vendor\squizlabs\php_codesniffer\src\Runner.php on line 606

dingo-d commented 3 years ago

Hi!

You'll need to provide a bit more details. Which version of PHPCS and WPCS are you using? Did you install it via composer or globally? What PHP version are you running it on?

On what kind of code do you get such an error? A minimum code example would also help in trying to reproduce the error.

There is a whole bug issue template that you just removed. It would help us if you filled it out correctly.

djstini commented 2 years ago

``I have the same issue, using PHPCS/PHPCBF version 3.6.2

Code is just basic stuff, like spaces instead of tabs for indentation.

I installed it globally

Running PHP 8

Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: Trying to access array offset on value of type null in /Users/sk/wpcs/WordPress/Sniff.php on line 1480 in phar:///usr/local/Cellar/php-code-sniffer/3.6.2_1/bin/phpcbf/src/Runner.php:607
Stack trace:

#0 /Users/sk/wpcs/WordPress/Sniff.php(1480): PHP_CodeSniffer\Runner->handleErrors(2, 'Trying to acces...', '/Users/sk/wpcs/...', 1480)

#1 /Users/sk/wpcs/WordPress/Sniffs/Security/NonceVerificationSniff.php(124): WordPressCS\WordPress\Sniff->has_nonce_check(28)

#2 /Users/sk/wpcs/WordPress/Sniff.php(900): WordPressCS\WordPress\Sniffs\Security\NonceVerificationSniff->process_token(28)

#3 phar:///usr/local/Cellar/php-code-sniffer/3.6.2_1/bin/phpcbf/src/Files/File.php(498): WordPressCS\WordPress\Sniff->process(Object(PHP_CodeSniffer\Files\LocalFile), 28)

#4 phar:///usr/local/Cellar/php-code-sniffer/3.6.2_1/bin/phpcbf/src/Files/LocalFile.php(92): PHP_CodeSniffer\Files\File->process()

#5 phar:///usr/local/Cellar/php-code-sniffer/3.6.2_1/bin/phpcbf/src/Fixer.php(174): PHP_CodeSniffer\Files\LocalFile->process()

#6 phar:///usr/local/Cellar/php-code-sniffer/3.6.2_1/bin/phpcbf/src/Reports/Cbf.php(52): PHP_CodeSniffer\Fixer->fixFile()

#7 phar:///usr/local/Cellar/php-code-sniffer/3.6.2_1/bin/phpcbf/src/Reporter.php(285): PHP_CodeSniffer\Reports\Cbf->generateFileReport(Array, Object(PHP_CodeSniffer\Files\LocalFile), false, 190)

#8 phar:///usr/local/Cellar/php-code-sniffer/3.6.2_1/bin/phpcbf/src/Runner.php(657): PHP_CodeSniffer\Reporter->cacheFileReport(Object(PHP_CodeSniffer\Files\LocalFile), Object(PHP_CodeSniffer\Config))

#9 phar:///usr/local/Cellar/php-code-sniffer/3.6.2_1/bin/phpcbf/src/Runner.php(434): PHP_CodeSniffer\Runner->processFile(Object(PHP_CodeSniffer\Files\LocalFile))

#10 phar:///usr/local/Cellar/php-code-sniffer/3.6.2_1/bin/phpcbf/src/Runner.php(200): PHP_CodeSniffer\Runner->run()

#11 /usr/local/Cellar/php-code-sniffer/3.6.2_1/bin/phpcbf(6): PHP_CodeSniffer\Runner->runPHPCBF()

#12 {main}
  thrown in phar:///usr/local/Cellar/php-code-sniffer/3.6.2_1/bin/phpcbf/src/Runner.php on line 607`
jrfnl commented 2 years ago

Please provide a code sample with which the error can be reproduced. Without that, I'm going to close this issue in two weeks time.

djstini commented 2 years ago

Literally any php code produces this error for me... for example:

`<?php

print_r( $_POST );

`

Notice the print_r has leading spaces, wich should be removed.

image

just noticed that another "wpcs" error shows in the tooltip when i hover over the first formatting error:

image
jrfnl commented 2 years ago

@djstini That's a different error and unrelated to this issue.

djstini commented 2 years ago

yes, i know, but the original error still exists, just added the info about the additional error, because it might help troubleshooting

jrfnl commented 2 years ago

@djstini Thanks, but it doesn't.

jrfnl commented 1 year ago

Closing for lack of actionable information with which to reproduce the issue.