From f450396b2ab46a93ee7969db69e654dc079ddaff Mon Sep 17 00:00:00 2001 From: Gustavo Bordoni Date: Fri, 24 Nov 2023 01:51:17 -0500 Subject: [PATCH 1/5] Partially copy the version 1.0.0 usage of PHPCS in more Envs --- checks/phpcs.php | 76 +++++++++++++-- inc/class-phpcs-runner.php | 195 +++++++++++++++++++++++++++++++++++++ readme.txt | 2 + 3 files changed, 263 insertions(+), 10 deletions(-) create mode 100644 inc/class-phpcs-runner.php diff --git a/checks/phpcs.php b/checks/phpcs.php index 61debecb8..5948c1a3b 100644 --- a/checks/phpcs.php +++ b/checks/phpcs.php @@ -3,14 +3,12 @@ use const WordPressdotorg\Plugin_Check\{ PLUGIN_DIR, HAS_VENDOR }; use WordPressdotorg\Plugin_Check\{Error, Guideline_Violation, Message, Notice, Warning}; use WordPressdotorg\Plugin_Check\PHPCS; - -include PLUGIN_DIR . '/inc/class-php-cli.php'; -include PLUGIN_DIR . '/inc/class-phpcs.php'; +use WordPressdotorg\Plugin_Check\PHPCS_Runner; class PHPCS_Checks extends Check_Base { const NOTICE_TYPES = [ - // This should be an Error, but this is triggered for all variablse with SQL which isn't always a problem. + // This should be an Error, but this is triggered for all variables with SQL which isn't always a problem. //'WordPress.DB.PreparedSQL.InterpolatedNotPrepared' => Warning::class, ]; @@ -27,7 +25,31 @@ public function check_against_phpcs() { ); } + /** + * Attempts to load Codesniffer and return a status if it's safe to use the runner. + * + * @since 0.2.2 + * + * @return bool + */ + protected function load_codesniffer_runner(): bool { + if ( class_exists( '\PHP_CodeSniffer\Runner' ) ) { + return true; + } + + // Include the PHPCS autoloader. + $autoloader = PLUGIN_DIR . '/vendor/squizlabs/php_codesniffer/autoload.php'; + + if ( file_exists( $autoloader ) ) { + include_once $autoloader; + } + + return class_exists( '\PHP_CodeSniffer\Runner' ); + } + public function check_against_phpcs_review() { + return null; + if ( ! HAS_VENDOR ) { return new Notice( 'phpcs_not_tested', @@ -35,12 +57,15 @@ public function check_against_phpcs_review() { ); } - return $this->run_phpcs_standard( + return $this->run_cli_phpcs_standard( __DIR__ . '/phpcs/plugin-check-needs-review.xml' ); } - protected function run_phpcs_standard( string $standard, array $args = [] ) { + protected function run_cli_phpcs_standard( string $standard, array $args = [] ) { + include_once PLUGIN_DIR . '/inc/class-php-cli.php'; + include_once PLUGIN_DIR . '/inc/class-phpcs.php'; + $phpcs = new PHPCS(); $phpcs->set_standard( $standard ); @@ -74,6 +99,32 @@ protected function run_phpcs_standard( string $standard, array $args = [] ) { return $this->phpcs_result_to_warnings( $report ); } + protected function run_phpcs_standard( string $standard, array $args = [] ) { + include_once PLUGIN_DIR . '/inc/class-phpcs-runner.php'; + + if ( ! $this->load_codesniffer_runner() ) { + return new Notice( + 'phpcs_runner_not_found', + esc_html__( 'PHP Code Sniffer rulesets have not been tested, as the Code Sniffer Runner class is missing.', 'plugin-check' ) + ); + } + + $phpcs = new PHPCS_Runner(); + $phpcs->set_path( $this->path ); + $phpcs->set_standard( $standard ); + + $results = $phpcs->run(); + + if ( is_wp_error( $results ) ) { + return new Error( + $results->get_error_code(), + $results->get_error_message() + ); + } + + return $this->phpcs_result_to_warnings( $results ); + } + protected function phpcs_result_to_warnings( $result ) { $return = []; @@ -109,7 +160,9 @@ protected function phpcs_result_to_warnings( $result ) { $notice_class = self::NOTICE_TYPES[ $message['source'] ]; } - $source_code = esc_html( trim( file( $this->path . '/' . $filename )[ $message['line'] - 1 ] ) ); + $file_path = dirname( $this->path ) . '/' . $filename; + + $source_code = esc_html( trim( file( $file_path )[ $message['line'] - 1 ] ) ); if ( current_user_can( 'edit_plugins' ) ) { $edit_link = sprintf( @@ -128,7 +181,7 @@ protected function phpcs_result_to_warnings( $result ) { $message['source'], sprintf( /* translators: 1: Type of Error 2: Line 3: File 4: Message 5: Code Example 6: Edit Link */ - __( '%1$s Line %2$d of file %3$s.
%4$s.
%5$s%6$s', 'plugin-check' ), + __( '%1$s

Line %2$d of file %3$s.
%4$s.
%5$s%6$s', 'plugin-check' ), "{$message['source']}", $message['line'], $filename, @@ -153,7 +206,7 @@ protected function phpcs_result_to_warnings( $result ) { * * @return string|null File editor URL or null if not available. */ - private function get_file_editor_url( $filename, $line ) { + protected function get_file_editor_url( $filename, $line ) { if ( ! isset( $filename, $line ) ) { return null; } @@ -228,12 +281,15 @@ private function get_file_editor_url( $filename, $line ) { // Fall back to using the plugin editor if no external editor is offered. if ( ! $edit_url ) { $plugin_data = get_plugins( '/' . $this->slug ); + if ( ! str_starts_with( $filename, $this->slug ) ) { + $filename = $this->slug . '/' . $filename; + } return esc_url( add_query_arg( [ 'plugin' => rawurlencode( $this->slug . '/' . array_key_first( $plugin_data ) ), - 'file' => rawurlencode( $this->slug . '/' . $filename ), + 'file' => rawurlencode( $filename ), 'line' => rawurlencode( $line ), ], admin_url( 'plugin-editor.php' ) diff --git a/inc/class-phpcs-runner.php b/inc/class-phpcs-runner.php new file mode 100644 index 000000000..26dd799eb --- /dev/null +++ b/inc/class-phpcs-runner.php @@ -0,0 +1,195 @@ + true, + 'extensions' => true, + 'sniffs' => true, + 'exclude' => true, //phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude + ]; + + /** + * Plugin path which will be used for the runner. + * + * @since 0.2.2 + * + * @var string + */ + protected $path; + + /** + * Which standard file we will use. + * + * @since 0.2.2 + * + * @var string + */ + protected $standard; + + public function set_path( $path ) { + $this->path = $path; + } + + public function get_path() { + return $this->path; + } + + public function set_standard( $standard ) { + $this->standard = $standard; + } + + public function get_standard() { + return $this->standard; + } + + /** + * Returns an associative array of arguments to pass to PHPCS. + * + * @since 0.2.2 + * + * @return array { + * An associative array of PHPCS CLI arguments. Can include one or more of the following options. + * + * @type string $standard The name or path to the coding standard to check against. + * @type string $extensions A comma separated list of file extensions to check against. + * @type string $sniffs A comma separated list of sniff codes to include from checks. + * @type string $exclude A comma separated list of sniff codes to exclude from checks. + * } + */ + protected function get_args() { + return [ + 'extensions' => 'php', + 'standard' => $this->get_standard(), + ]; + } + + /** + * Amends the given result by running the check on the associated plugin. + * + * @since 0.2.2 + * + * @return string|WP_Error|null + */ + public function run() { + // Backup the original command line arguments. + $orig_cmd_args = $_SERVER['argv']; + + // Create the default arguments for PHPCS. + $defaults = [ + '', + $this->get_path(), + '--report=Json', + '--report-width=9999', + ]; + + // Set the check arguments for PHPCS. + $_SERVER['argv'] = $this->parse_argv( $this->get_args(), $defaults ); + + // Reset PHP_CodeSniffer config. + $this->reset_php_codesniffer_config(); + + // Run PHPCS. + try { + ob_start(); + $runner = new \PHP_CodeSniffer\Runner(); + $runner->runPHPCS(); + $reports = ob_get_clean(); + } catch ( \Exception $e ) { + return new \WP_Error( + 'plugin_check_no_php_files_found', + esc_html__( 'PHP Code Sniffer cannot be completed.', 'plugin-check' ), + [ + 'error_code' => $e->getCode(), + 'error_message' => $e->getMessage(), + ] + ); + } + + // Restore original arguments. + $_SERVER['argv'] = $orig_cmd_args; + + // Parse the reports into data to add to the overall $result. + $reports = json_decode( trim( $reports ), true ); + + if ( empty( $reports['files'] ) ) { + return new \WP_Error( + 'plugin_check_no_php_files_found', + esc_html__( 'Cannot find any PHP file to check, make sure your plugin contains PHP files.', 'plugin-check' ) + ); + } + + $base_dir = trailingslashit( basename( $this->get_path() ) ); + $plugin_path = $this->get_path(); + + $files_paths = array_map( static function( $file_path ) use ( $base_dir, $plugin_path ) { + return str_replace( $plugin_path, $base_dir, $file_path ); + }, array_keys( $reports['files'] ) ); + $files_values = array_values( $reports['files'] ); + + $reports['files'] = array_combine( $files_paths, $files_values ); + + return $reports; + } + + /** + * Parse the command arguments. + * + * @since 0.2.2 + * + * @param array $argv An array of arguments to pass. + * @param array $defaults An array of default arguments. + * + * @return array An indexed array of PHPCS CLI arguments. + */ + protected function parse_argv( $argv, $defaults ) { + // Only accept allowed PHPCS arguments from check arguments array. + $check_args = array_intersect_key( $argv, $this->allowed_args ); + + // Format check arguments for PHPCS. + foreach ( $check_args as $key => $value ) { + $defaults[] = "--{$key}=$value"; + } + + return $defaults; + } + + /** + * Resets \PHP_CodeSniffer\Config::$overriddenDefaults to prevent + * incorrect results when running multiple checks. + * + * @since 0.2.2 + */ + protected function reset_php_codesniffer_config() { + if ( class_exists( '\PHP_CodeSniffer\Config' ) ) { + /* + * PHPStan ignore reason: PHPStan raised an issue because we can't + * use class in ReflectionClass. + * + * @phpstan-ignore-next-line + */ + $reflected_phpcs_config = new \ReflectionClass( '\PHP_CodeSniffer\Config' ); + $overridden_defaults = $reflected_phpcs_config->getProperty( 'overriddenDefaults' ); + $overridden_defaults->setAccessible( true ); + $overridden_defaults->setValue( [] ); + $overridden_defaults->setAccessible( false ); + } + } +} \ No newline at end of file diff --git a/readme.txt b/readme.txt index f782bc73e..a7040e7c1 100644 --- a/readme.txt +++ b/readme.txt @@ -44,6 +44,8 @@ This plugin checker is not perfect, and never will be. It is only a tool to help = [0.2.2] 2023-11-XX = +* Enhancement - Include support for Windows Servers. +* Enhancement - Avoid using PHP CLI directly, which enables plugin developers to use PCP in a variety of new environments. * Fix - Remove extra period on the end of the sentence for Phar warning. Props @bordoni, @pixolin. [#275](https://github.com/10up/plugin-check/pull/265) = [0.2.1] 2023-09-22 = From 95878afe410ea59ca03c8f566a24cc9c978013d1 Mon Sep 17 00:00:00 2001 From: Gustavo Bordoni Date: Wed, 13 Dec 2023 16:10:38 -0500 Subject: [PATCH 2/5] Remove unused CLI version of the checks for PHPCS and fix tests --- checks/phpcs.php | 66 ++----- inc/class-php-cli.php | 71 ------- inc/class-phpcs-runner.php | 2 +- inc/class-phpcs.php | 261 -------------------------- package.json | 2 +- readme.txt | 2 +- tests/class-plugin-check-testcase.php | 13 +- 7 files changed, 24 insertions(+), 393 deletions(-) delete mode 100644 inc/class-php-cli.php delete mode 100644 inc/class-phpcs.php diff --git a/checks/phpcs.php b/checks/phpcs.php index 5948c1a3b..0673b9842 100644 --- a/checks/phpcs.php +++ b/checks/phpcs.php @@ -25,6 +25,20 @@ public function check_against_phpcs() { ); } + + public function check_against_phpcs_review() { + if ( ! HAS_VENDOR ) { + return new Notice( + 'phpcs_not_tested', + __( 'PHP Code Sniffer rulesets have not been tested, as the vendor directory is missing. Perhaps you need to run `composer install`.', 'plugin-check' ) + ); + } + + return $this->run_phpcs_standard( + __DIR__ . '/phpcs/plugin-check-needs-review.xml' + ); + } + /** * Attempts to load Codesniffer and return a status if it's safe to use the runner. * @@ -47,58 +61,6 @@ protected function load_codesniffer_runner(): bool { return class_exists( '\PHP_CodeSniffer\Runner' ); } - public function check_against_phpcs_review() { - return null; - - if ( ! HAS_VENDOR ) { - return new Notice( - 'phpcs_not_tested', - __( 'PHP Code Sniffer rulesets have not been tested, as the vendor directory is missing. Perhaps you need to run `composer install`.', 'plugin-check' ) - ); - } - - return $this->run_cli_phpcs_standard( - __DIR__ . '/phpcs/plugin-check-needs-review.xml' - ); - } - - protected function run_cli_phpcs_standard( string $standard, array $args = [] ) { - include_once PLUGIN_DIR . '/inc/class-php-cli.php'; - include_once PLUGIN_DIR . '/inc/class-phpcs.php'; - - $phpcs = new PHPCS(); - $phpcs->set_standard( $standard ); - - $args = wp_parse_args( - $args, - array( - 'extensions' => 'php', // Only check php files. - 's' => true, // Show the name of the sniff triggering a violation. - // --ignore-annotations - ) - ); - - $report = $phpcs->run_json_report( - $this->path, - $args, - 'array' - ); - - if ( is_wp_error( $report ) ) { - return new Error( - $report->get_error_code(), - $report->get_error_message() - ); - } - - // If no response, either malformed output or PHP encountered an error. - if ( ! $report || empty( $report['files'] ) ) { - return false; - } - - return $this->phpcs_result_to_warnings( $report ); - } - protected function run_phpcs_standard( string $standard, array $args = [] ) { include_once PLUGIN_DIR . '/inc/class-phpcs-runner.php'; diff --git a/inc/class-php-cli.php b/inc/class-php-cli.php deleted file mode 100644 index e55db290a..000000000 --- a/inc/class-php-cli.php +++ /dev/null @@ -1,71 +0,0 @@ -get_php_binary(); - - $php_cmd_parts[] = '-dmemory_limit=1G'; - - // Give the CLI process the same max_execution_time as the calling script. - if ( ini_get( 'max_execution_time' ) ) { - $php_cmd_parts[] = '-dmax_execution_time=' . ini_get( 'max_execution_time' ); - } - - return implode( ' ', $php_cmd_parts ); - } - - /** - * Gets the full command to run. - * - * @since 0.2.0 - * - * @param string $append - * - * @return string - */ - public function get_cmd( string $append = '' ): string { - return $this->get_php_cmd() . ' ' . $append; - } - -} \ No newline at end of file diff --git a/inc/class-phpcs-runner.php b/inc/class-phpcs-runner.php index 26dd799eb..0b31fd213 100644 --- a/inc/class-phpcs-runner.php +++ b/inc/class-phpcs-runner.php @@ -135,7 +135,7 @@ public function run() { esc_html__( 'Cannot find any PHP file to check, make sure your plugin contains PHP files.', 'plugin-check' ) ); } - + $base_dir = trailingslashit( basename( $this->get_path() ) ); $plugin_path = $this->get_path(); diff --git a/inc/class-phpcs.php b/inc/class-phpcs.php deleted file mode 100644 index 85638ac18..000000000 --- a/inc/class-phpcs.php +++ /dev/null @@ -1,261 +0,0 @@ - true, - 'parallel' => 3, - 'report-width' => 80, - 'tab-width' => 4, - ); - - /** - * PHPCS constructor. - */ - public function __construct() { - $this->phpcs = dirname( __DIR__ ) . '/vendor/squizlabs/php_codesniffer/bin/phpcs'; - if ( is_callable( 'get_temp_dir' ) ) { - $this->cache_file = get_temp_dir() . 'wporg-code-analysis/phpcs-cache'; - } else { - $this->cache_file = '/tmp/wporg-code-analysis/phpcs-cache'; - } - - $this->php = new PHP_CLI(); - } - - /** - * Set the name or path of the coding standard that will be used when running phpcs. - * - * @param string $standard The name or path of the coding standard to use. - * - * @return void - */ - public function set_standard( $standard ) { - $this->standard = $standard; - } - - /** - * Toggle the cache state to "enabled". - * - * @return void - */ - public function enable_cache() { - $this->cache = 'enabled'; - $this->common_args['cache'] = $this->cache_file; - } - - /** - * Toggle the cache state to "disabled". - * - * @return void - */ - public function disable_cache() { - $this->cache = 'disabled'; - unset( $this->common_args['cache'] ); - } - - /** - * Delete the cache file. - * - * @return void - */ - public function clear_cache() { - @unlink( $this->cache_file ); - } - - /** - * Run phpcs on a given path with a given set of arguments. - * - * The arguments array can take any of the arguments described in phpcs's Usage blurb, but there are some that - * should be set in other ways instead: - * - standard This should be set using the `set_standard` class method instead. This makes it simpler - * to run phpcs on several different directories in the same session. - * - cache and no-cache These should be set using the `enable_cache` and `disable_cache` class methods instead. - * As of v3.5.8 phpcs doesn't have a simple way to clear its own cache. - * (See https://github.com/squizlabs/PHP_CodeSniffer/issues/2993.) - * To get around this we set a custom cache file, which can then be deleted with the - * `clear_cache` class method. - * - * @param string $path The directory/file on which to to run phpcs. - * @param array $args Command line args as key => value pairs. Valueless keys should be set to true. - * See https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage. - * Note that the `standard` arg should be set using the `set_standard` class method. - * - * @return string|WP_Error|null - */ - public function run( $path, array $args = array() ) { - if ( ! file_exists( $this->phpcs ) ) { - return new \WP_Error( - 'missing_dependency', - 'PHP Code Sniffer is not available. Try running composer install first.' - ); - } - - if ( ! is_readable( $path ) ) { - return new \WP_Error( - 'invalid_path', - 'The given path is not readable.' - ); - } - - if ( isset( $args['cache'] ) ) { - $this->enable_cache(); - unset( $args['cache'] ); - } elseif ( isset( $args['no-cache'] ) ) { - $this->disable_cache(); - } - - $args = array_merge( - array( - 'basepath' => $path, - 'standard' => $this->standard, - ), - $this->common_args, - $args - ); - - $arg_array = array(); - foreach ( $args as $key => $value ) { - $prefix = '--'; - if ( 1 === strlen( $key ) || in_array( $key, array( 'vv', 'vvv' ), true ) ) { - $prefix = '-'; - } - - if ( true === $value ) { - $arg_array[] = "{$prefix}{$key}"; - } else { - $arg_array[] = "{$prefix}{$key}={$value}"; - } - } - $arg_string = implode( ' ', $arg_array ); - - $command = $this->php->get_cmd( "{$this->phpcs} $arg_string $path 2>&1" ); - $response = shell_exec( $command ); - - if ( strpos( $response, 'No such file or directory' ) !== false ) { - return new \WP_Error( - 'plugin_check_php_binary_not_found', - __( 'Cannot find the PHP Binary file, please define it using the `PLUGIN_CHECK_PHP_BIN` constant', 'plugin-check' ) - ); - } - - return $response; - } - - /** - * Get the summary. - * - * @param string $path The directory/file on which to to run phpcs. - * @param array $args Command line args. See the `run` method. - * - * @return string|WP_Error|null - */ - public function run_summary_report( $path, array $args = array() ) { - $args = array_merge( - $args, - array( - 'report' => 'summary', - ) - ); - - return $this->run( $path, $args ); - } - - /** - * Get the full report. - * - * @param string $path The directory/file on which to to run phpcs. - * @param array $args Command line args. See the `run` method. - * - * @return string|WP_Error|null - */ - public function run_full_report( $path, array $args = array() ) { - $args = array_merge( - $args, - array( - 'report' => 'full', - ) - ); - - return $this->run( $path, $args ); - } - - /** - * Get the full report as JSON. - * - * @param string $path The directory/file on which to to run phpcs. - * @param array $args Command line args. See the `run` method. - * @param string $output The format of the return data. Possible values raw|object|array. - * "raw" means an un-decoded JSON string. Default raw. - * - * @return mixed|string|WP_Error|null - */ - public function run_json_report( $path, array $args = array(), $output = 'raw' ) { - $args = array_merge( - $args, - array( - 'report' => 'json', - ) - ); - - $result = $this->run( $path, $args ); - - if ( is_wp_error( $result ) ) { - return new Error( - $result->get_error_code(), - $result->get_error_message() - ); - } - - if ( in_array( $output, array( 'object', 'array' ), true ) ) { - $assoc = 'array' === $output; - $result = json_decode( $result, $assoc ); - // Does this belong here? - if ( $result ) { - array_walk_recursive( $result, function( &$value, $key ) { - if ( is_string( $value ) ) { - $value = stripcslashes( $value ); - } - } ); - } - } - - return $result; - } -} diff --git a/package.json b/package.json index a63a3e6d6..707f9a5bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plugin-check", - "version": "0.2.0", + "version": "0.2.2", "description": "WordPress.org Plugin Check", "directories": { "test": "tests" diff --git a/readme.txt b/readme.txt index a7040e7c1..87de82fd9 100644 --- a/readme.txt +++ b/readme.txt @@ -1,4 +1,4 @@ -Plugin Check +Plugin Check (PCP) =============== * Contributors: dd32, davidperez, bordoni, frantorres, eherman24, alexsanford1 * Requires at least: 6.2 diff --git a/tests/class-plugin-check-testcase.php b/tests/class-plugin-check-testcase.php index 606d2fa4b..e85cb768d 100644 --- a/tests/class-plugin-check-testcase.php +++ b/tests/class-plugin-check-testcase.php @@ -1,11 +1,12 @@ run_against_virtual_files( [ - 'plugin.php' => $string + 'plugin.php' => $string, ], $args ); @@ -21,12 +22,12 @@ public function run_against_virtual_files( $files, $args = [] ) { foreach ( $files as $filename => $string ) { $full_filename = "{$tempname}/{$filename}"; - if ( str_ends_with( $filename, '.php' ) && ! str_starts_with( $string, '<' . '?php' ) ) { + if ( str_ends_with( $filename, '.php' ) && ! str_starts_with( $string, '<' . '?php' ) ) { $string = " Date: Wed, 13 Dec 2023 22:24:58 -0500 Subject: [PATCH 3/5] Improve docblocks for Runner class --- inc/class-phpcs-runner.php | 61 +++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/inc/class-phpcs-runner.php b/inc/class-phpcs-runner.php index 0b31fd213..01475b8ed 100644 --- a/inc/class-phpcs-runner.php +++ b/inc/class-phpcs-runner.php @@ -6,7 +6,7 @@ /** * Class PHPCS_Runner * - * @since TBD + * @since 0.2.2 * * @package WordPressdotorg\Plugin_Check */ @@ -19,7 +19,7 @@ class PHPCS_Runner { * * @var array */ - protected $allowed_args = [ + protected array $allowed_args = [ 'standard' => true, 'extensions' => true, 'sniffs' => true, @@ -33,7 +33,7 @@ class PHPCS_Runner { * * @var string */ - protected $path; + protected string $path; /** * Which standard file we will use. @@ -42,21 +42,54 @@ class PHPCS_Runner { * * @var string */ - protected $standard; + protected string $standard; - public function set_path( $path ) { + /** + * Sets the plugin path which will be used for the runner. + * + * @since 0.2.2 + * + * @param string $path The plugin path. + * + * @return void + */ + public function set_path( string $path ): void { $this->path = $path; } - public function get_path() { + /** + * Gets the path for the plugin. + * + * @since 0.2.2 + * + * @return string + */ + public function get_path(): string { return $this->path; } - public function set_standard( $standard ) { + /** + * Sets the standards file which will be used for the runner. + * Normally this will be a .xml file. + * + * @since 0.2.2 + * + * @param string $standard + * + * @return void + */ + public function set_standard( string $standard ): void { $this->standard = $standard; } - public function get_standard() { + /** + * Gets the standard file for the runner. + * + * @since 0.2.2 + * + * @return string + */ + public function get_standard(): string { return $this->standard; } @@ -74,7 +107,7 @@ public function get_standard() { * @type string $exclude A comma separated list of sniff codes to exclude from checks. * } */ - protected function get_args() { + protected function get_args(): array { return [ 'extensions' => 'php', 'standard' => $this->get_standard(), @@ -135,11 +168,11 @@ public function run() { esc_html__( 'Cannot find any PHP file to check, make sure your plugin contains PHP files.', 'plugin-check' ) ); } - - $base_dir = trailingslashit( basename( $this->get_path() ) ); + + $base_dir = trailingslashit( basename( $this->get_path() ) ); $plugin_path = $this->get_path(); - $files_paths = array_map( static function( $file_path ) use ( $base_dir, $plugin_path ) { + $files_paths = array_map( static function ( $file_path ) use ( $base_dir, $plugin_path ) { return str_replace( $plugin_path, $base_dir, $file_path ); }, array_keys( $reports['files'] ) ); $files_values = array_values( $reports['files'] ); @@ -159,7 +192,7 @@ public function run() { * * @return array An indexed array of PHPCS CLI arguments. */ - protected function parse_argv( $argv, $defaults ) { + protected function parse_argv( $argv, $defaults ): array { // Only accept allowed PHPCS arguments from check arguments array. $check_args = array_intersect_key( $argv, $this->allowed_args ); @@ -177,7 +210,7 @@ protected function parse_argv( $argv, $defaults ) { * * @since 0.2.2 */ - protected function reset_php_codesniffer_config() { + protected function reset_php_codesniffer_config(): void { if ( class_exists( '\PHP_CodeSniffer\Config' ) ) { /* * PHPStan ignore reason: PHPStan raised an issue because we can't From 528fe385708dabac55b5f4daadcb79594ad5b4b8 Mon Sep 17 00:00:00 2001 From: Gustavo Bordoni Date: Wed, 13 Dec 2023 22:28:26 -0500 Subject: [PATCH 4/5] Update versions and dates + extra changelog --- readme.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/readme.txt b/readme.txt index 5ecf33ec2..a83442446 100644 --- a/readme.txt +++ b/readme.txt @@ -2,13 +2,13 @@ Plugin Check (PCP) =============== * Contributors: dd32, davidperez, bordoni, frantorres, eherman24, alexsanford1 * Requires at least: 6.2 -* Tested up to: 6.3.1 +* Tested up to: 6.4.2 * Stable tag: 0.2.2 * License: GPLv2 or later * Requires PHP: 7.2 * License URI: http://www.gnu.org/licenses/gpl-2.0.html * Author URI: https://make.wordpress.org/plugins/ -* Plugin URL: https://github.com/10up/plugin-check/ +* Plugin URL: https://github.com/WordPress/plugin-check/ Plugin Check is a tool from the WordPress.org plugin review team, it provides an initial check of whether your plugin meets our requirements for hosting. @@ -28,7 +28,7 @@ All development for this plugin is handled via [GitHub](https://github.com/10up/ = What if the plugin reports as "error" something that's correct? = -We strived to write a plugin in a way that minimizes false positives but If you find one, please report it in the GitHub repo. +We strove to write a plugin in a way that minimizes false positives but If you find one, please report it in the GitHub repo. If you can, please consider submitting a Pull Request to fix it. @@ -42,13 +42,13 @@ This plugin checker is not perfect, and never will be. It is only a tool to help == Changelog == -= [0.2.2] 2023-11-XX = - += [0.2.2] 2023-12-13 = * Enhancement - Include support for Windows Servers. * Enhancement - Avoid using PHP CLI directly, which enables plugin developers to use PCP in a variety of new environments. -* Fix - Prevent problems with Readme parser warning related to `contributor_ignored` for when running the check outside of WP.org. Props @bordoni, @dev4press. [#276](https://github.com/10up/plugin-check/pull/276) -* Fix - Remove extra period on the end of the sentence for Phar warning. Props @bordoni, @pixolin. [#275](https://github.com/10up/plugin-check/pull/275) +* Fix - Remove dependency on `shell_exec` and `exec` functions, which enables plugin developers to use PCP in a variety of new environments. +* Fix - Prevent problems with Readme parser warning related to `contributor_ignored` for when running the check outside WP.org. Props @dev4press. [#276](https://github.com/10up/plugin-check/pull/276) +* Fix - Remove extra period on the end of the sentence for Phar warning. Props @pixolin. [#275](https://github.com/10up/plugin-check/pull/275) = [0.2.1] 2023-09-22 = From 398b569e627d6cbb244d8cd303a196887dec27c7 Mon Sep 17 00:00:00 2001 From: Gustavo Bordoni Date: Wed, 13 Dec 2023 22:29:58 -0500 Subject: [PATCH 5/5] Remove references to 10up repo and include PCP into the name --- plugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.php b/plugin.php index 07154bef5..14cfdb777 100644 --- a/plugin.php +++ b/plugin.php @@ -1,7 +1,7 @@