Skip to content

Commit

Permalink
Merge pull request #367 from ernilambar/364-fix-cli-arguments
Browse files Browse the repository at this point in the history
Change logic for finding plugin slug in CLI
  • Loading branch information
mukeshpanchal27 committed Jan 8, 2024
2 parents 505298f + c89110c commit cf35624
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
15 changes: 13 additions & 2 deletions includes/Checker/CLI_Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,19 @@ public static function is_plugin_check() {
* @throws Exception Thrown if the plugin parameter is empty.
*/
protected function get_plugin_param() {
// Get the plugin parameter from the command line arguments.
$plugin = isset( $_SERVER['argv'][3] ) ? $_SERVER['argv'][3] : '';
// Exclude first three reserved elements.
$params = array_slice( $_SERVER['argv'], 3 );

// Remove associative arguments.
$params = array_filter(
$params,
static function ( $val ) {
return ! str_starts_with( $val, '--' );
}
);

// Use only first element. We dont support checking multiple plugins at once yet!
$plugin = count( $params ) > 0 ? reset( $params ) : '';

if ( empty( $plugin ) ) {
throw new Exception(
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ parameters:
- includes/Checker/Checks/Plugin_Readme_Check.php
- includes/Traits/Find_Readme.php
- includes/Traits/File_Editor_URL.php
-
message: '/^Function str_starts_with not found.$/'
path: includes/Checker/CLI_Runner.php

0 comments on commit cf35624

Please sign in to comment.