Skip to content

Commit

Permalink
use script for checking php syntax that exits with status code set to…
Browse files Browse the repository at this point in the history
… 1 if there are deprecation warnings
  • Loading branch information
dannyvankooten committed Jan 11, 2025
1 parent d41f882 commit 87ea80f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions bin/check-php-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env php
<?php

/**
* Checks all PHP files in this project recursively
* and passes them to PHP's built-in linter.
*
* If the output contains "deprecated", the final status code will be 1.
*/

$global_exit_code = 0;
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(".", RecursiveDirectoryIterator::SKIP_DOTS));

foreach ($iterator as $file) {
if (
str_starts_with($file->getPathname(), './vendor/')
|| str_starts_with($file->getPathname(), './node_modules/')
|| false == $file->isFile()
|| $file->getExtension() !== 'php'
) {
continue;
}

$exit_code = 0;
$output = [];
exec("php -l {$file->getPathname()}", $output, $exit_code);
$output = join("\n", $output);
echo $output . "\n";

if ($exit_code || str_contains($output, 'Deprecated')) {
$global_exit_code = 1;
}
}

exit($global_exit_code);
File renamed without changes.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"make-pot": "wp i18n make-pot . languages/mailchimp-for-wp.pot --exclude=assets/js",
"test": "phpunit tests/",
"codestyle": "phpcs -n -s",
"check-syntax": "find . -name '*.php' -not -path './vendor/*' -not -path './node_modules/*' -not -path './assets/*' -print0 | xargs -0 -n1 php -l"
"check-syntax": "./bin/check-php-syntax"
},
"config": {
},
Expand Down

0 comments on commit 87ea80f

Please sign in to comment.