Skip to content

Commit 7d82e67

Browse files
authored
Merge pull request #367 from wp-cli/fix/wpcs-3.0-issues
2 parents 27c8be3 + e3610e1 commit 7d82e67

17 files changed

+56
-57
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"require-dev": {
2020
"wp-cli/scaffold-command": "^1.2 || ^2",
21-
"wp-cli/wp-cli-tests": "^3.1"
21+
"wp-cli/wp-cli-tests": "^4"
2222
},
2323
"suggest": {
2424
"ext-json": "Used for reading and generating JSON translation files",

i18n-command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
'i18n make-pot',
1919
'\WP_CLI\I18n\MakePotCommand',
2020
array(
21-
'before_invoke' => static function() {
21+
'before_invoke' => static function () {
2222
if ( ! function_exists( 'mb_ereg' ) ) {
2323
WP_CLI::error( 'The mbstring extension is required for string extraction to work reliably.' );
2424
}

phpcs.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
<!-- Whitelist property name for a a JSON-decoded object. -->
6464
<rule ref="WordPress.NamingConventions.ValidVariableName">
6565
<properties>
66-
<property name="customPropertiesWhitelist" type="array">
66+
<property name="allowed_custom_properties" type="array">
6767
<element value="sourcesContent"/>
6868
<element value="functionsScannerClass"/>
6969
</property>

src/BladeCodeExtractor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ final class BladeCodeExtractor extends BladeGettextExtractor {
4747
/**
4848
* {@inheritdoc}
4949
*/
50-
public static function fromString( $string, Translations $translations, array $options = [] ) {
50+
public static function fromString( $text, Translations $translations, array $options = [] ) {
5151
WP_CLI::debug( "Parsing file {$options['file']}", 'make-pot' );
5252

5353
try {
54-
static::fromStringMultiple( $string, [ $translations ], $options );
54+
self::fromStringMultiple( $text, [ $translations ], $options );
5555
} catch ( Exception $exception ) {
5656
WP_CLI::debug(
5757
sprintf(

src/BladeGettextExtractor.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ protected static function getBladeCompiler() {
3232
/**
3333
* Compiles the Blade template string into a PHP string in one step.
3434
*
35-
* @param string $string Blade string to be compiled to a PHP string
35+
* @param string $text Blade string to be compiled to a PHP string
3636
* @return string
3737
*/
38-
protected static function compileBladeToPhp( $string ) {
39-
return static::getBladeCompiler()->compileString( $string );
38+
protected static function compileBladeToPhp( $text ) {
39+
return static::getBladeCompiler()->compileString( $text );
4040
}
4141

4242
/**
4343
* {@inheritdoc}
4444
*
4545
* Note: In the parent PhpCode class fromString() uses fromStringMultiple() (overriden here)
4646
*/
47-
public static function fromStringMultiple( $string, array $translations, array $options = [] ) {
48-
$php_string = static::compileBladeToPhp( $string );
47+
public static function fromStringMultiple( $text, array $translations, array $options = [] ) {
48+
$php_string = static::compileBladeToPhp( $text );
4949
return parent::fromStringMultiple( $php_string, $translations, $options );
5050
}
5151
}

src/BlockExtractor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ final class BlockExtractor extends JsonSchemaExtractor {
99
/**
1010
* @inheritdoc
1111
*/
12-
public static function fromString( $string, Translations $translations, array $options = [] ) {
12+
public static function fromString( $text, Translations $translations, array $options = [] ) {
1313
$file = $options['file'];
1414
WP_CLI::debug( "Parsing file $file", 'make-pot' );
1515

16-
$json = json_decode( $string, true );
16+
$json = json_decode( $text, true );
1717

1818
if ( null === $json ) {
1919
WP_CLI::debug(
@@ -35,6 +35,6 @@ public static function fromString( $string, Translations $translations, array $o
3535
return;
3636
}
3737

38-
parent::fromString( $string, $translations, $options );
38+
parent::fromString( $text, $translations, $options );
3939
}
4040
}

src/FileDataExtractor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ public static function get_file_data( $file, $headers ) {
3939
/**
4040
* Retrieves metadata from a string.
4141
*
42-
* @param string $string String to look for metadata in.
42+
* @param string $text String to look for metadata in.
4343
* @param array $headers List of headers.
4444
*
4545
* @return array Array of file headers in `HeaderKey => Header Value` format.
4646
*/
47-
public static function get_file_data_from_string( $string, $headers ) {
47+
public static function get_file_data_from_string( $text, $headers ) {
4848
foreach ( $headers as $field => $regex ) {
49-
if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $string, $match ) && $match[1] ) {
49+
if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $text, $match ) && $match[1] ) {
5050
$headers[ $field ] = static::_cleanup_header_comment( $match[1] );
5151
} else {
5252
$headers[ $field ] = '';

src/IterableCodeExtractor.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public static function fromFile( $file_or_files, Translations $translations, arr
4141
// Make sure a relative file path is added as a comment.
4242
$options['file'] = ltrim( str_replace( static::$dir, '', Utils\normalize_path( $file ) ), '/' );
4343

44-
$string = file_get_contents( $file );
44+
$text = file_get_contents( $file );
4545

46-
if ( ! $string ) {
46+
if ( ! $text ) {
4747
WP_CLI::debug(
4848
sprintf(
4949
'Could not load file %1s',
@@ -56,7 +56,7 @@ public static function fromFile( $file_or_files, Translations $translations, arr
5656
}
5757

5858
if ( ! empty( $options['wpExtractTemplates'] ) ) {
59-
$headers = FileDataExtractor::get_file_data_from_string( $string, [ 'Template Name' => 'Template Name' ] );
59+
$headers = FileDataExtractor::get_file_data_from_string( $text, [ 'Template Name' => 'Template Name' ] );
6060

6161
if ( ! empty( $headers['Template Name'] ) ) {
6262
$translation = new Translation( '', $headers['Template Name'] );
@@ -69,7 +69,7 @@ public static function fromFile( $file_or_files, Translations $translations, arr
6969
// Patterns are only supported when in a top-level patterns/ folder.
7070
if ( ! empty( $options['wpExtractPatterns'] ) && 0 === strpos( $options['file'], 'patterns/' ) ) {
7171
$headers = FileDataExtractor::get_file_data_from_string(
72-
$string,
72+
$text,
7373
[
7474
'Title' => 'Title',
7575
'Description' => 'Description',
@@ -91,7 +91,7 @@ public static function fromFile( $file_or_files, Translations $translations, arr
9191
}
9292
}
9393

94-
static::fromString( $string, $translations, $options );
94+
static::fromString( $text, $translations, $options );
9595
}
9696
}
9797

@@ -225,29 +225,29 @@ protected static function containsMatchingChildren( SplFileInfo $dir, array $mat
225225
* Recursively gets all PHP files within a directory.
226226
*
227227
* @param string $dir A path of a directory.
228-
* @param array $include List of files and directories to include.
229-
* @param array $exclude List of files and directories to skip.
228+
* @param array $includes List of files and directories to include.
229+
* @param array $excludes List of files and directories to skip.
230230
* @param array $extensions List of filename extensions to process.
231231
*
232232
* @return array File list.
233233
*/
234-
public static function getFilesFromDirectory( $dir, array $include = [], array $exclude = [], $extensions = [] ) {
234+
public static function getFilesFromDirectory( $dir, array $includes = [], array $excludes = [], $extensions = [] ) {
235235
$filtered_files = [];
236236

237237
$files = new RecursiveIteratorIterator(
238238
new RecursiveCallbackFilterIterator(
239239
new RecursiveDirectoryIterator( $dir, RecursiveDirectoryIterator::SKIP_DOTS | RecursiveDirectoryIterator::UNIX_PATHS | RecursiveDirectoryIterator::FOLLOW_SYMLINKS ),
240-
static function ( $file, $key, $iterator ) use ( $include, $exclude, $extensions ) {
240+
static function ( $file, $key, $iterator ) use ( $includes, $excludes, $extensions ) {
241241
/** @var RecursiveCallbackFilterIterator $iterator */
242242
/** @var SplFileInfo $file */
243243

244244
// Normalize include and exclude paths.
245-
$include = array_map( self::class . '::trim_leading_slash', $include );
246-
$exclude = array_map( self::class . '::trim_leading_slash', $exclude );
245+
$includes = array_map( self::class . '::trim_leading_slash', $includes );
246+
$excludes = array_map( self::class . '::trim_leading_slash', $excludes );
247247

248-
// If no $include is passed everything gets the weakest possible matching score.
249-
$inclusion_score = empty( $include ) ? 0.1 : static::calculateMatchScore( $file, $include );
250-
$exclusion_score = static::calculateMatchScore( $file, $exclude );
248+
// If no $includes is passed everything gets the weakest possible matching score.
249+
$inclusion_score = empty( $includes ) ? 0.1 : static::calculateMatchScore( $file, $includes );
250+
$exclusion_score = static::calculateMatchScore( $file, $excludes );
251251

252252
// Always include directories that aren't excluded.
253253
if ( 0 === $exclusion_score && $iterator->hasChildren() ) {
@@ -256,7 +256,7 @@ static function ( $file, $key, $iterator ) use ( $include, $exclude, $extensions
256256

257257
if ( ( 0 === $inclusion_score || $exclusion_score > $inclusion_score ) && $iterator->hasChildren() ) {
258258
// Always include directories that may have matching children even if they are excluded.
259-
return static::containsMatchingChildren( $file, $include );
259+
return static::containsMatchingChildren( $file, $includes );
260260
}
261261

262262
// Include directories that are excluded but include score is higher.

src/JsCodeExtractor.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ final class JsCodeExtractor extends JsCode {
2727
/**
2828
* @inheritdoc
2929
*/
30-
public static function fromString( $string, Translations $translations, array $options = [] ) {
30+
public static function fromString( $text, Translations $translations, array $options = [] ) {
3131
WP_CLI::debug( "Parsing file {$options['file']}", 'make-pot' );
3232

3333
try {
34-
static::fromStringMultiple( $string, [ $translations ], $options );
34+
self::fromStringMultiple( $text, [ $translations ], $options );
3535
} catch ( PeastException $exception ) {
3636
WP_CLI::debug(
3737
sprintf(
@@ -58,11 +58,11 @@ public static function fromString( $string, Translations $translations, array $o
5858
/**
5959
* @inheritDoc
6060
*/
61-
public static function fromStringMultiple( $string, array $translations, array $options = [] ) {
62-
$options += static::$options;
61+
public static function fromStringMultiple( $text, array $translations, array $options = [] ) {
62+
$options += self::$options;
6363

6464
/** @var JsFunctionsScanner $functions */
65-
$functions = new static::$functionsScannerClass( $string );
65+
$functions = new self::$functionsScannerClass( $text );
6666
$functions->enableCommentsExtraction( $options['extractComments'] );
6767
$functions->saveGettextFunctions( $translations, $options );
6868
}

src/JsonSchemaExtractor.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ protected static function load_schema( $schema, $fallback ) {
8282
/**
8383
* @inheritdoc
8484
*/
85-
public static function fromString( $string, Translations $translations, array $options = [] ) {
85+
public static function fromString( $text, Translations $translations, array $options = [] ) {
8686
$file = $options['file'];
8787
WP_CLI::debug( "Parsing file {$file}", 'make-pot' );
8888

8989
$schema = self::load_schema( $options['schema'], $options['schemaFallback'] );
9090

91-
$json = json_decode( $string, true );
91+
$json = json_decode( $text, true );
9292

9393
if ( null === $json ) {
9494
WP_CLI::debug(
@@ -182,5 +182,4 @@ private static function remote_get( $url ) {
182182

183183
return trim( $response->body );
184184
}
185-
186185
}

0 commit comments

Comments
 (0)