diff --git a/composer.json b/composer.json index dbc0648..54d6b5c 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ }, "require-dev": { "wp-cli/scaffold-command": "^1.2 || ^2", - "wp-cli/wp-cli-tests": "^3.1" + "wp-cli/wp-cli-tests": "^4" }, "suggest": { "ext-json": "Used for reading and generating JSON translation files", diff --git a/i18n-command.php b/i18n-command.php index df056b2..b461e70 100644 --- a/i18n-command.php +++ b/i18n-command.php @@ -18,7 +18,7 @@ 'i18n make-pot', '\WP_CLI\I18n\MakePotCommand', array( - 'before_invoke' => static function() { + 'before_invoke' => static function () { if ( ! function_exists( 'mb_ereg' ) ) { WP_CLI::error( 'The mbstring extension is required for string extraction to work reliably.' ); } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 8ab06b9..b6cc28c 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -63,7 +63,7 @@ - + diff --git a/src/BladeCodeExtractor.php b/src/BladeCodeExtractor.php index 3f3b756..482c68c 100644 --- a/src/BladeCodeExtractor.php +++ b/src/BladeCodeExtractor.php @@ -47,11 +47,11 @@ final class BladeCodeExtractor extends BladeGettextExtractor { /** * {@inheritdoc} */ - public static function fromString( $string, Translations $translations, array $options = [] ) { + public static function fromString( $text, Translations $translations, array $options = [] ) { WP_CLI::debug( "Parsing file {$options['file']}", 'make-pot' ); try { - static::fromStringMultiple( $string, [ $translations ], $options ); + self::fromStringMultiple( $text, [ $translations ], $options ); } catch ( Exception $exception ) { WP_CLI::debug( sprintf( diff --git a/src/BladeGettextExtractor.php b/src/BladeGettextExtractor.php index a523353..d698967 100644 --- a/src/BladeGettextExtractor.php +++ b/src/BladeGettextExtractor.php @@ -32,11 +32,11 @@ protected static function getBladeCompiler() { /** * Compiles the Blade template string into a PHP string in one step. * - * @param string $string Blade string to be compiled to a PHP string + * @param string $text Blade string to be compiled to a PHP string * @return string */ - protected static function compileBladeToPhp( $string ) { - return static::getBladeCompiler()->compileString( $string ); + protected static function compileBladeToPhp( $text ) { + return static::getBladeCompiler()->compileString( $text ); } /** @@ -44,8 +44,8 @@ protected static function compileBladeToPhp( $string ) { * * Note: In the parent PhpCode class fromString() uses fromStringMultiple() (overriden here) */ - public static function fromStringMultiple( $string, array $translations, array $options = [] ) { - $php_string = static::compileBladeToPhp( $string ); + public static function fromStringMultiple( $text, array $translations, array $options = [] ) { + $php_string = static::compileBladeToPhp( $text ); return parent::fromStringMultiple( $php_string, $translations, $options ); } } diff --git a/src/BlockExtractor.php b/src/BlockExtractor.php index 3725a84..d47af48 100644 --- a/src/BlockExtractor.php +++ b/src/BlockExtractor.php @@ -9,11 +9,11 @@ final class BlockExtractor extends JsonSchemaExtractor { /** * @inheritdoc */ - public static function fromString( $string, Translations $translations, array $options = [] ) { + public static function fromString( $text, Translations $translations, array $options = [] ) { $file = $options['file']; WP_CLI::debug( "Parsing file $file", 'make-pot' ); - $json = json_decode( $string, true ); + $json = json_decode( $text, true ); if ( null === $json ) { WP_CLI::debug( @@ -35,6 +35,6 @@ public static function fromString( $string, Translations $translations, array $o return; } - parent::fromString( $string, $translations, $options ); + parent::fromString( $text, $translations, $options ); } } diff --git a/src/FileDataExtractor.php b/src/FileDataExtractor.php index eb24dc6..0d97c86 100644 --- a/src/FileDataExtractor.php +++ b/src/FileDataExtractor.php @@ -39,14 +39,14 @@ public static function get_file_data( $file, $headers ) { /** * Retrieves metadata from a string. * - * @param string $string String to look for metadata in. + * @param string $text String to look for metadata in. * @param array $headers List of headers. * * @return array Array of file headers in `HeaderKey => Header Value` format. */ - public static function get_file_data_from_string( $string, $headers ) { + public static function get_file_data_from_string( $text, $headers ) { foreach ( $headers as $field => $regex ) { - if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $string, $match ) && $match[1] ) { + if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $text, $match ) && $match[1] ) { $headers[ $field ] = static::_cleanup_header_comment( $match[1] ); } else { $headers[ $field ] = ''; diff --git a/src/IterableCodeExtractor.php b/src/IterableCodeExtractor.php index f29740a..8611ca2 100644 --- a/src/IterableCodeExtractor.php +++ b/src/IterableCodeExtractor.php @@ -41,9 +41,9 @@ public static function fromFile( $file_or_files, Translations $translations, arr // Make sure a relative file path is added as a comment. $options['file'] = ltrim( str_replace( static::$dir, '', Utils\normalize_path( $file ) ), '/' ); - $string = file_get_contents( $file ); + $text = file_get_contents( $file ); - if ( ! $string ) { + if ( ! $text ) { WP_CLI::debug( sprintf( 'Could not load file %1s', @@ -56,7 +56,7 @@ public static function fromFile( $file_or_files, Translations $translations, arr } if ( ! empty( $options['wpExtractTemplates'] ) ) { - $headers = FileDataExtractor::get_file_data_from_string( $string, [ 'Template Name' => 'Template Name' ] ); + $headers = FileDataExtractor::get_file_data_from_string( $text, [ 'Template Name' => 'Template Name' ] ); if ( ! empty( $headers['Template Name'] ) ) { $translation = new Translation( '', $headers['Template Name'] ); @@ -69,7 +69,7 @@ public static function fromFile( $file_or_files, Translations $translations, arr // Patterns are only supported when in a top-level patterns/ folder. if ( ! empty( $options['wpExtractPatterns'] ) && 0 === strpos( $options['file'], 'patterns/' ) ) { $headers = FileDataExtractor::get_file_data_from_string( - $string, + $text, [ 'Title' => 'Title', 'Description' => 'Description', @@ -91,7 +91,7 @@ public static function fromFile( $file_or_files, Translations $translations, arr } } - static::fromString( $string, $translations, $options ); + static::fromString( $text, $translations, $options ); } } @@ -225,29 +225,29 @@ protected static function containsMatchingChildren( SplFileInfo $dir, array $mat * Recursively gets all PHP files within a directory. * * @param string $dir A path of a directory. - * @param array $include List of files and directories to include. - * @param array $exclude List of files and directories to skip. + * @param array $includes List of files and directories to include. + * @param array $excludes List of files and directories to skip. * @param array $extensions List of filename extensions to process. * * @return array File list. */ - public static function getFilesFromDirectory( $dir, array $include = [], array $exclude = [], $extensions = [] ) { + public static function getFilesFromDirectory( $dir, array $includes = [], array $excludes = [], $extensions = [] ) { $filtered_files = []; $files = new RecursiveIteratorIterator( new RecursiveCallbackFilterIterator( new RecursiveDirectoryIterator( $dir, RecursiveDirectoryIterator::SKIP_DOTS | RecursiveDirectoryIterator::UNIX_PATHS | RecursiveDirectoryIterator::FOLLOW_SYMLINKS ), - static function ( $file, $key, $iterator ) use ( $include, $exclude, $extensions ) { + static function ( $file, $key, $iterator ) use ( $includes, $excludes, $extensions ) { /** @var RecursiveCallbackFilterIterator $iterator */ /** @var SplFileInfo $file */ // Normalize include and exclude paths. - $include = array_map( self::class . '::trim_leading_slash', $include ); - $exclude = array_map( self::class . '::trim_leading_slash', $exclude ); + $includes = array_map( self::class . '::trim_leading_slash', $includes ); + $excludes = array_map( self::class . '::trim_leading_slash', $excludes ); - // If no $include is passed everything gets the weakest possible matching score. - $inclusion_score = empty( $include ) ? 0.1 : static::calculateMatchScore( $file, $include ); - $exclusion_score = static::calculateMatchScore( $file, $exclude ); + // If no $includes is passed everything gets the weakest possible matching score. + $inclusion_score = empty( $includes ) ? 0.1 : static::calculateMatchScore( $file, $includes ); + $exclusion_score = static::calculateMatchScore( $file, $excludes ); // Always include directories that aren't excluded. if ( 0 === $exclusion_score && $iterator->hasChildren() ) { @@ -256,7 +256,7 @@ static function ( $file, $key, $iterator ) use ( $include, $exclude, $extensions if ( ( 0 === $inclusion_score || $exclusion_score > $inclusion_score ) && $iterator->hasChildren() ) { // Always include directories that may have matching children even if they are excluded. - return static::containsMatchingChildren( $file, $include ); + return static::containsMatchingChildren( $file, $includes ); } // Include directories that are excluded but include score is higher. diff --git a/src/JsCodeExtractor.php b/src/JsCodeExtractor.php index f751f3c..4c03ee5 100644 --- a/src/JsCodeExtractor.php +++ b/src/JsCodeExtractor.php @@ -27,11 +27,11 @@ final class JsCodeExtractor extends JsCode { /** * @inheritdoc */ - public static function fromString( $string, Translations $translations, array $options = [] ) { + public static function fromString( $text, Translations $translations, array $options = [] ) { WP_CLI::debug( "Parsing file {$options['file']}", 'make-pot' ); try { - static::fromStringMultiple( $string, [ $translations ], $options ); + self::fromStringMultiple( $text, [ $translations ], $options ); } catch ( PeastException $exception ) { WP_CLI::debug( sprintf( @@ -58,11 +58,11 @@ public static function fromString( $string, Translations $translations, array $o /** * @inheritDoc */ - public static function fromStringMultiple( $string, array $translations, array $options = [] ) { - $options += static::$options; + public static function fromStringMultiple( $text, array $translations, array $options = [] ) { + $options += self::$options; /** @var JsFunctionsScanner $functions */ - $functions = new static::$functionsScannerClass( $string ); + $functions = new self::$functionsScannerClass( $text ); $functions->enableCommentsExtraction( $options['extractComments'] ); $functions->saveGettextFunctions( $translations, $options ); } diff --git a/src/JsonSchemaExtractor.php b/src/JsonSchemaExtractor.php index ed362a7..63ae0f5 100644 --- a/src/JsonSchemaExtractor.php +++ b/src/JsonSchemaExtractor.php @@ -82,13 +82,13 @@ protected static function load_schema( $schema, $fallback ) { /** * @inheritdoc */ - public static function fromString( $string, Translations $translations, array $options = [] ) { + public static function fromString( $text, Translations $translations, array $options = [] ) { $file = $options['file']; WP_CLI::debug( "Parsing file {$file}", 'make-pot' ); $schema = self::load_schema( $options['schema'], $options['schemaFallback'] ); - $json = json_decode( $string, true ); + $json = json_decode( $text, true ); if ( null === $json ) { WP_CLI::debug( @@ -182,5 +182,4 @@ private static function remote_get( $url ) { return trim( $response->body ); } - } diff --git a/src/MakeMoCommand.php b/src/MakeMoCommand.php index 2290784..ac82fed 100644 --- a/src/MakeMoCommand.php +++ b/src/MakeMoCommand.php @@ -80,7 +80,7 @@ public function __invoke( $args, $assoc_args ) { continue; } - $result_count++; + ++$result_count; } WP_CLI::success( sprintf( 'Created %d %s.', $result_count, Utils\pluralize( 'file', $result_count ) ) ); diff --git a/src/MakePotCommand.php b/src/MakePotCommand.php index 1e32551..14aea97 100644 --- a/src/MakePotCommand.php +++ b/src/MakePotCommand.php @@ -449,11 +449,11 @@ function ( $file ) { /** * Removes leading and trailing slashes of a string. * - * @param string $string What to add and remove slashes from. + * @param string $text What to add and remove slashes from. * @return string String without leading and trailing slashes. */ - protected function unslashit( $string ) { - return ltrim( rtrim( trim( $string ), '/\\' ), '/\\' ); + protected function unslashit( $text ) { + return ltrim( rtrim( trim( $text ), '/\\' ), '/\\' ); } /** diff --git a/src/MapCodeExtractor.php b/src/MapCodeExtractor.php index 1d2c0a0..d3b8c67 100644 --- a/src/MapCodeExtractor.php +++ b/src/MapCodeExtractor.php @@ -24,26 +24,26 @@ final class MapCodeExtractor extends JsCode { /** * {@inheritdoc} */ - public static function fromString( $string, Translations $translations, array $options = [] ) { + public static function fromString( $text, Translations $translations, array $options = [] ) { if ( ! array_key_exists( 'file', $options ) || substr( $options['file'], -7 ) !== '.js.map' ) { return; } $options['file'] = substr( $options['file'], 0, -7 ) . '.js'; try { - $options += static::$options; + $options += self::$options; - $map_object = json_decode( $string ); + $map_object = json_decode( $text ); if ( ! isset( $map_object->sourcesContent ) || ! is_array( $map_object->sourcesContent ) ) { return; } - $string = implode( "\n", $map_object->sourcesContent ); + $text = implode( "\n", $map_object->sourcesContent ); WP_CLI::debug( "Parsing file {$options['file']}", 'make-pot' ); - $functions = new JsFunctionsScanner( $string ); + $functions = new JsFunctionsScanner( $text ); $functions->enableCommentsExtraction( $options['extractComments'] ); $functions->saveGettextFunctions( $translations, $options ); diff --git a/src/PhpCodeExtractor.php b/src/PhpCodeExtractor.php index 364afca..6014848 100644 --- a/src/PhpCodeExtractor.php +++ b/src/PhpCodeExtractor.php @@ -48,11 +48,11 @@ final class PhpCodeExtractor extends PhpCode { /** * {@inheritdoc} */ - public static function fromString( $string, Translations $translations, array $options = [] ) { + public static function fromString( $text, Translations $translations, array $options = [] ) { WP_CLI::debug( "Parsing file {$options['file']}", 'make-pot' ); try { - static::fromStringMultiple( $string, [ $translations ], $options ); + self::fromStringMultiple( $text, [ $translations ], $options ); } catch ( Exception $exception ) { WP_CLI::debug( sprintf( diff --git a/src/PotGenerator.php b/src/PotGenerator.php index 5a56c32..ed2f9a5 100644 --- a/src/PotGenerator.php +++ b/src/PotGenerator.php @@ -89,7 +89,7 @@ public static function toString( Translations $translations, array $options = [] if ( $translation->hasPlural() ) { self::addLines( $lines, $prefix . 'msgid_plural', $translation->getPlural() ); - for ( $i = 0; $i <= $plural_size; $i ++ ) { + for ( $i = 0; $i <= $plural_size; $i++ ) { self::addLines( $lines, $prefix . 'msgstr[' . $i . ']', '' ); } } else { @@ -105,12 +105,12 @@ public static function toString( Translations $translations, array $options = [] /** * Escapes and adds double quotes to a string. * - * @param string $string Multiline string. + * @param string $text Multiline string. * * @return string[] */ - protected static function multilineQuote( $string ) { - $lines = explode( "\n", $string ); + protected static function multilineQuote( $text ) { + $lines = explode( "\n", $text ); $last = count( $lines ) - 1; foreach ( $lines as $k => $line ) { diff --git a/src/ThemeJsonExtractor.php b/src/ThemeJsonExtractor.php index f7ef638..c8981aa 100644 --- a/src/ThemeJsonExtractor.php +++ b/src/ThemeJsonExtractor.php @@ -13,7 +13,7 @@ final class ThemeJsonExtractor extends JsonSchemaExtractor { /** * @inheritdoc */ - public static function fromString( $string, Translations $translations, array $options = [] ) { + public static function fromString( $text, Translations $translations, array $options = [] ) { $file = $options['file']; // Only support top-level theme.json file or any JSON file within a top-level styles/ folder. @@ -24,6 +24,6 @@ public static function fromString( $string, Translations $translations, array $o return; } - parent::fromString( $string, $translations, $options ); + parent::fromString( $text, $translations, $options ); } } diff --git a/src/UpdatePoCommand.php b/src/UpdatePoCommand.php index 422e18d..556236f 100644 --- a/src/UpdatePoCommand.php +++ b/src/UpdatePoCommand.php @@ -78,7 +78,7 @@ public function __invoke( $args, $assoc_args ) { continue; } - $result_count++; + ++$result_count; } WP_CLI::success( sprintf( 'Updated %d %s.', $result_count, Utils\pluralize( 'file', $result_count ) ) );