Skip to content

vsprintf error in files.php  #3555

@esprange

Description

@esprange

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions