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

vsprintf error in files.php #3555

Closed
esprange opened this issue Mar 8, 2022 · 1 comment
Closed

vsprintf error in files.php #3555

esprange opened this issue Mar 8, 2022 · 1 comment

Comments

@esprange
Copy link

esprange commented Mar 8, 2022

Describe the bug
A clear and concise description of what the bug is.

The following error occurs:
CodeSniffer exited with code 255
stdout:
stderr: PHP Fatal error: Uncaught TypeError: vsprintf(): Argument #2 ($values) must be of type array, string given in /opt/docker/app/.composer/vendor/squizlabs/php_codesniffer/src/Files/File.php:1056
Stack trace:
#0 /opt/docker/app/.composer/vendor/squizlabs/php_codesniffer/src/Files/File.php(1056): vsprintf()
#1 /opt/docker/app/.composer/vendor/squizlabs/php_codesniffer/src/Files/File.php(672): PHP_CodeSniffer\Files\File->addMessage()
#2 /opt/docker/app/.composer/vendor/squizlabs/php_codesniffer/src/Files/File.php(780): PHP_CodeSniffer\Files\File->addError()
#3 /opt/docker/app/.composer/vendor/wp-coding-standards/wpcs/WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php(205): PHP_CodeSniffer\Files\File->addFixableError()
#4 /opt/docker/app/.composer/vendor/wp-coding-standards/wpcs/WordPress/Sniff.php(910): WordPressCS\WordPress\Sniffs\WhiteSpace\ControlStructureSpacingSniff->process_token()
#5 /opt/docker/app/.composer/vendor/squizlabs/php_codesniffer/src/Files/File.php(498): WordPressCS\WordPress\Sniff->process()
#6 /opt/docker/app/.composer/vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(92): PHP_CodeSniffer\Files\File->process()
#7 /opt/docker/app/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php(631): PHP_CodeSniffer\Files\LocalFile->process()
#8 /opt/docker/app/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php(434): PHP_CodeSniffer\Runner->processFile()
#9 /opt/docker/app/.composer/vendor/squizlabs/php_codesniffer/src/Runner.php(114): PHP_CodeSniffer\Runner->run()
#10 /opt/docker/app/.composer/vendor/squizlabs/php_codesniffer/bin/phpcs(18): PHP_CodeSniffer\Runner->runPHPCS()
#11 /opt/docker/app/.composer/vendor/bin/phpcs(117): include('...')
#12 {main}
thrown in /opt/docker/app/.composer/vendor/squizlabs/php_codesniffer/src/Files/File.php on line 1056

Code sample

// see my comments at 'to reproduce'

Custom ruleset

<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards for Plugins">
	<description>Generally-applicable sniffs for WordPress plugins</description>

	<rule ref="WordPress-Core" >
		<exclude name="Generic.Arrays.DisallowShortArraySyntax"/>
		<exclude name="WordPress.PHP.DisallowShortTernary"/>
		<exclude name="WordPress.DateTime.RestrictedFunctions.date_date"/>
	</rule>
	<rule ref="WordPress-Docs" />
	<rule ref="WordPress-Extra">
		<exclude name="WordPress.WP.AlternativeFunctions.file_system_read_fopen"/>
		<exclude name="WordPress.WP.AlternativeFunctions.file_system_read_fclose"/>
		<exclude name="WordPress.WP.AlternativeFunctions.file_system_read_fwrite"/>
	</rule>
	<!-- Check all PHP files in directory tree by default. -->
	<arg name="extensions" value="php"/>
	<file>.</file>

	<!-- Show sniff codes in all reports -->
	<arg value="s"/>

	<exclude-pattern>*/vendor/*</exclude-pattern>
	<exclude-pattern>*/node_modules/*</exclude-pattern>
	<exclude-pattern>*/tmp/*</exclude-pattern>

</ruleset>

To reproduce
I believe it the error dump is caused when a space character is detected in a function definition. According the Wordpress styling rules the function name should immediately be followed with an opening bracket.
So if a file contains something like ' private static function myfunc (' the error occurs, while if the space character is removed ( '... myfyunc( ' ) it does not.

Expected behavior
A clear and concise description of what you expected to happen.

Versions (please complete the following information):

  • OS: not relevant (Windows 10 and Linux)
  • PHP: 8.1
  • PHPCS: 3.6.2
  • Standard: Wordpress

Additional context
Add any other context about the problem here.

@jrfnl
Copy link
Contributor

jrfnl commented Mar 8, 2022

This is not an issue with PHPCS itself, but with the WordPress standard which hasn't released a new version containing the fix for the above issue yet. (a fix has been committed though, so no need to report it there)

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