Skip to content

Commit

Permalink
Merge branch 'trunk' into chore/1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
davidperezgar authored Nov 28, 2024
2 parents 8c11b80 + f104682 commit 840cb6f
Show file tree
Hide file tree
Showing 39 changed files with 769 additions and 203 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/behat-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ jobs:
fail-fast: true
matrix:
php:
- '7.2'
- '7.3'
- '7.4'
- '8.0'
- '8.1'
Expand All @@ -70,7 +68,7 @@ jobs:
- php: '8.2'
wordpress: 'latest'
coverage: true
- php: '7.2'
- php: '7.4'
wordpress: '6.3'
- php: '8.3'
wordpress: 'trunk'
Expand Down Expand Up @@ -157,7 +155,7 @@ jobs:
- name: Upload code coverage report
if: ${{ matrix.coverage }}
uses: codecov/codecov-action@v4.6.0
uses: codecov/codecov-action@v5.0.7
with:
files: ${{ steps.coverage_files.outputs.files }}
flags: feature
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/php-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,32 @@ jobs:

- name: PHPMD
run: composer phpmd

php-lint-sniffs:
name: PHP (Sniffs)
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
php-version: '8.0'

- name: Validate Composer configuration
working-directory: "phpcs-sniffs"
run: composer validate

- name: Install PHP dependencies
uses: ramsey/composer-install@57532f8be5bda426838819c5ee9afb8af389d51a
with:
composer-options: '--prefer-dist'
working-directory: "phpcs-sniffs"

- name: PHP Lint
working-directory: "phpcs-sniffs"
run: composer lint

- name: PHP Lint PHPCS
working-directory: "phpcs-sniffs"
run: composer check-cs
9 changes: 3 additions & 6 deletions .github/workflows/php-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ jobs:
fail-fast: true
matrix:
php:
- '7.3'
- '7.4'
- '8.0'
- '8.1'
wordpress: [ 'latest' ]
include:
- php: '7.2'
- php: '7.4'
wordpress: '6.3'
- php: '8.2'
wordpress: 'latest'
Expand Down Expand Up @@ -101,7 +100,7 @@ jobs:
- name: Upload code coverage report
if: ${{ matrix.coverage }}
uses: codecov/codecov-action@68708a9f7a6b6b5fe33673f782f93725c5eff3c6
uses: codecov/codecov-action@015f24e6818733317a2da2edd6290ab26238649a
with:
file: build/logs/*.xml
flags: unit
Expand All @@ -115,8 +114,6 @@ jobs:
fail-fast: true
matrix:
php:
- '7.2'
- '7.3'
- '7.4'
- '8.0'
- '8.1'
Expand Down Expand Up @@ -149,7 +146,7 @@ jobs:
- name: Upload code coverage report
if: ${{ matrix.coverage }}
uses: codecov/codecov-action@68708a9f7a6b6b5fe33673f782f93725c5eff3c6
uses: codecov/codecov-action@015f24e6818733317a2da2edd6290ab26238649a
with:
file: build/logs/*.xml
flags: phpcs-sniffs
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Thank you for your interest in contributing to the Plugin Check plugin!
In general, all code must follow the [WordPress Coding Standards and best practices](https://developer.wordpress.org/coding-standards/). All code in the Plugin Check plugin must follow these requirements:

- **WordPress**: The plugin's minimum WordPress version requirement is 6.3.
- **PHP**: Always match the latest WordPress version. The minimum required version right now is 7.2.24.
- **PHP**: The minimum required version right now is 7.4.

## Guidelines

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"license": "GPL-2.0-or-later",
"type": "wordpress-plugin",
"require": {
"php": ">=7.2.24",
"php": ">=7.4",
"ext-json": "*",
"afragen/wordpress-plugin-readme-parser": "dev-master#67fba498d0b112acf84386b95e4905c539a33f0b",
"afragen/wordpress-plugin-readme-parser": "dev-master#c3758599348148be684b3c4ad1105d09b6230d51",
"automattic/vipwpcs": "^3.0.0",
"composer/installers": "^2.2",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
Expand Down Expand Up @@ -56,7 +56,7 @@
"phpstan/extension-installer": true
},
"platform": {
"php": "7.2.24"
"php": "7.4"
}
},
"scripts": {
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 45 additions & 28 deletions includes/CLI/Plugin_Check_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ public function __construct( Plugin_Context $plugin_context ) {
* [--warning-severity=<warning-severity>]
* : Warning severity level.
*
* [--include-low-severity-errors]
* : Include errors with lower severity than the threshold as other type.
*
* [--include-low-severity-warnings]
* : Include warnings with lower severity than the threshold as other type.
*
* [--slug=<slug>]
* : Slug to override the default.
*
Expand Down Expand Up @@ -138,15 +144,17 @@ public function check( $args, $assoc_args ) {
$options = $this->get_options(
$assoc_args,
array(
'checks' => '',
'format' => 'table',
'ignore-warnings' => false,
'ignore-errors' => false,
'include-experimental' => false,
'severity' => '',
'error-severity' => '',
'warning-severity' => '',
'slug' => '',
'checks' => '',
'format' => 'table',
'ignore-warnings' => false,
'ignore-errors' => false,
'include-experimental' => false,
'severity' => '',
'error-severity' => '',
'warning-severity' => '',
'include-low-severity-errors' => false,
'include-low-severity-warnings' => false,
'slug' => '',
)
);

Expand Down Expand Up @@ -235,8 +243,10 @@ static function ( $dirs ) use ( $excluded_files ) {
$formatter = $this->get_formatter( $assoc_args, $default_fields );

// Severity.
$error_severity = ! empty( $options['error-severity'] ) ? $options['error-severity'] : $options['severity'];
$warning_severity = ! empty( $options['warning-severity'] ) ? $options['warning-severity'] : $options['severity'];
$error_severity = ! empty( $options['error-severity'] ) ? $options['error-severity'] : $options['severity'];
$warning_severity = ! empty( $options['warning-severity'] ) ? $options['warning-severity'] : $options['severity'];
$include_low_severity_errors = ! empty( $options['include-low-severity-errors'] ) ? true : false;
$include_low_severity_warnings = ! empty( $options['include-low-severity-warnings'] ) ? true : false;

// Print the formatted results.
// Go over all files with errors first and print them, combined with any warnings in the same file.
Expand All @@ -249,7 +259,7 @@ static function ( $dirs ) use ( $excluded_files ) {
$file_results = $this->flatten_file_results( $file_errors, $file_warnings );

if ( '' !== $error_severity || '' !== $warning_severity ) {
$file_results = $this->get_filtered_results_by_severity( $file_results, intval( $error_severity ), intval( $warning_severity ) );
$file_results = $this->get_filtered_results_by_severity( $file_results, intval( $error_severity ), intval( $warning_severity ), $include_low_severity_errors, $include_low_severity_warnings );
}

if ( ! empty( $file_results ) ) {
Expand All @@ -262,7 +272,7 @@ static function ( $dirs ) use ( $excluded_files ) {
$file_results = $this->flatten_file_results( array(), $file_warnings );

if ( '' !== $error_severity || '' !== $warning_severity ) {
$file_results = $this->get_filtered_results_by_severity( $file_results, intval( $error_severity ), intval( $warning_severity ) );
$file_results = $this->get_filtered_results_by_severity( $file_results, intval( $error_severity ), intval( $warning_severity ), $include_low_severity_errors, $include_low_severity_warnings );
}

if ( ! empty( $file_results ) ) {
Expand Down Expand Up @@ -626,25 +636,32 @@ private function display_results( $formatter, $file_name, $file_results ) {
*
* @since 1.1.0
*
* @param array $results Check results.
* @param int $error_severity Error severity level.
* @param int $warning_severity Warning severity level.
* @param array $results Check results.
* @param int $error_severity Error severity level.
* @param int $warning_severity Warning severity level.
* @param bool $include_low_severity_errors Include less level of severity issues as warning.
* @param bool $include_low_severity_warnings Include less level of severity issues as warning.
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
* @return array Filtered results.
*/
private function get_filtered_results_by_severity( $results, $error_severity, $warning_severity ) {
$errors = array_filter(
$results,
function ( $item ) use ( $error_severity ) {
return ( 'ERROR' === $item['type'] && $item['severity'] >= $error_severity );
}
);
private function get_filtered_results_by_severity( $results, $error_severity, $warning_severity, $include_low_severity_errors = false, $include_low_severity_warnings = false ) {
$errors = array();
$warnings = array();

$warnings = array_filter(
$results,
function ( $item ) use ( $warning_severity ) {
return ( 'WARNING' === $item['type'] && $item['severity'] >= $warning_severity );
foreach ( $results as $item ) {
if ( 'ERROR' === $item['type'] && $item['severity'] >= $error_severity ) {
$errors[] = $item;
} elseif ( $include_low_severity_errors && 'ERROR' === $item['type'] && $item['severity'] < $error_severity ) {
$item['type'] = 'ERRORS_LOW_SEVERITY';
$errors[] = $item;
} elseif ( $include_low_severity_warnings && 'WARNING' === $item['type'] && $item['severity'] < $warning_severity ) {
$item['type'] = 'WARNINGS_LOW_SEVERITY';
$warnings[] = $item;
} elseif ( 'WARNING' === $item['type'] && $item['severity'] >= $warning_severity ) {
$warnings[] = $item;
}
);
}

return array_merge( $errors, $warnings );
}
Expand Down
Loading

0 comments on commit 840cb6f

Please sign in to comment.