Skip to content

Commit

Permalink
Validate fields names
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Dec 27, 2023
1 parent 72f3eb3 commit c918279
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions includes/CLI/Plugin_Check_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ final class Plugin_Check_Command {
'json',
);

/**
* Field names.
*
* @since n.e.x.t
* @var string[]
*/
protected $fields = array(
'line',
'column',
'type',
'code',
'message',
);

/**
* Constructor.
*
Expand Down Expand Up @@ -129,6 +143,15 @@ public function check( $args, $assoc_args ) {
// Get options based on the CLI arguments.
$options = $this->get_options( $assoc_args );

// May be we have invalid fields.
$invalid_fields = array_diff( wp_parse_list( $options['fields'] ), $this->fields );

if ( count( $invalid_fields ) > 0 ) {
// translators: %s: Field names.
$message = ( 1 === count( $invalid_fields ) ) ? __( 'Invalid field: %s', 'plugin-check' ) : __( 'Invalid fields: %s', 'plugin-check' );
WP_CLI::error( sprintf( $message, join( ', ', $invalid_fields ) ) );

Check warning on line 152 in includes/CLI/Plugin_Check_Command.php

View check run for this annotation

Codecov / codecov/patch

includes/CLI/Plugin_Check_Command.php#L151-L152

Added lines #L151 - L152 were not covered by tests
}

// Create the plugin and checks array from CLI arguments.
$plugin = isset( $args[0] ) ? $args[0] : '';
$checks = wp_parse_list( $options['checks'] );
Expand Down

0 comments on commit c918279

Please sign in to comment.