Skip to content

Commit

Permalink
Fix unit tests failing on PHP nightly for the WordPress.WP.I18n sniff.
Browse files Browse the repository at this point in the history
This solves the following error:
`An error occurred during processing; checking has been aborted. The error message was: "count(): Parameter must be an array or an object that implements Countable" at /home/travis/build/WordPress-Coding-Standards/WordPress-Coding-Standards/WordPress/Sniffs/WP/I18nSniff.php:233`

`array_shift()` returns null if the array is empty or not an array which may have happened when less arguments where passed to the i18n function then expected.
In that case `$tokens` will be null and start throwing the `countable` error for PHP nightly.
  • Loading branch information
jrfnl committed Jan 5, 2017
1 parent 68456eb commit 312e6bf
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion WordPress/Sniffs/WP/I18nSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ protected function check_argument_tokens( PHP_CodeSniffer_File $phpcs_file, $con
$method = empty( $context['warning'] ) ? 'addError' : 'addWarning';
$content = $tokens[0]['content'];

if ( 0 === count( $tokens ) ) {
if ( empty( $tokens ) || 0 === count( $tokens ) ) {
$code = 'MissingArg' . ucfirst( $arg_name );
if ( 'domain' !== $arg_name || ! empty( $this->text_domain ) ) {
$phpcs_file->$method( 'Missing $%s arg.', $stack_ptr, $code, array( $arg_name ) );
Expand Down

0 comments on commit 312e6bf

Please sign in to comment.