PHPMD Catch / Suppress Fatal Errors

I am trying to automate my testing. As a smoke test, I would like to test my PHP code using PHPMD before continuing with the actual Unit tests. Sound reasonable enough?

The fact is that PHPMD seems to crash when fatal errors occur in my PHP files. For the test, I added an additional evaluation when defining a function, for example:

function foo() {{
    // Stuff
}

If I expected the exit code 1, PHPMD seems to crash completely and returns the exit code instead 0. Providing my automated script is useless. Is there a way to suppress these errors and return the expected exit code? For PHPUnit, the parameter --process-isolationsolved this problem, but I can not find such an option for PHPMD.

Corresponding Auto Test Code

#!/usr/bin/php
<?php

    exec('meta/phpmd', $output, $returnCode);
    if ($returnCode == 1) {
        echo '[Fail] PHP code is breaking', PHP_EOL;
        exit(1);
    } elseif ($returnCode == 2) {
        echo '[Warn] PHP code is unclean', PHP_EOL;
    } else {
        echo '[OK] Code is clean! ', PHP_EOL;
    }
+4
1

( ) , PHPMD. :

#!/usr/bin/php
<?php

$dir_root = dirname(dirname(__DIR__));
$dir_php  = $dir_root . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'App';

exec('find ' . $dir_php . ' -iname *.php | xargs -n1 php -l 2>/dev/null', $output, $returnCode);
if ($returnCode != 0) {
    echo '[Fail] PHP contains syntax errors', PHP_EOL,
         implode(PHP_EOL, $output), PHP_EOL;
    exit($returnCode);
}

exec('meta/phpmd', $output, $returnCode);
if ($returnCode == 1) {
    echo '[Fail] PHP code is breaking', PHP_EOL;
    exit(1);
} elseif ($returnCode == 2) {
    echo '[Warn] PHP code is unclean', PHP_EOL;
}

Winglian Reddit php -l https://www.reddit.com/r/PHP/comments/2t7mvc/lint_an_entire_directory_of_php_files_in_parallel/

0

Source: https://habr.com/ru/post/1614233/


All Articles