Skip to content
Snippets Groups Projects
Verified Commit 718a97e6 authored by Dave Long's avatar Dave Long
Browse files

Issue #3499245 by mondrake, bbrala: [CI] Report PHPStan baseline statistics in job

parent 4364de08
No related branches found
No related tags found
No related merge requests found
Pipeline #474731 passed with warnings
Pipeline: drupal

#474745

    Pipeline: drupal

    #474740

      Pipeline: drupal

      #474733

        ......@@ -391,8 +391,11 @@ default:
        php vendor/bin/phpstan analyze --configuration=./core/phpstan.neon.dist --no-progress --generate-baseline=$CI_PROJECT_DIR/core/.phpstan-baseline.php || true
        sed -i "s/ '\\/\\/build\\/core/ '/g" $CI_PROJECT_DIR/core/.phpstan-baseline.php
        sed -i "s/ '\\/\\/build/ '\\/../g" $CI_PROJECT_DIR/core/.phpstan-baseline.php
        php $CI_PROJECT_DIR/.gitlab-ci/scripts/phpstan-baseline-statistics.php
        exit $EXIT_CODE
        fi
        # Generate baseline statistics.
        - php $CI_PROJECT_DIR/.gitlab-ci/scripts/phpstan-baseline-statistics.php
        artifacts:
        # Only store the baseline if the job fails.
        ......@@ -400,6 +403,7 @@ default:
        reports:
        codequality: phpstan-quality-report.json
        junit: phpstan-junit.xml
        metrics: phpstan-metrics.txt
        paths:
        - $CI_PROJECT_DIR/core/.phpstan-baseline.php
        ......
        #!/usr/bin/env php
        <?php
        /**
        * @file
        * PHPStan baseline statistics.
        */
        if (PHP_SAPI !== 'cli') {
        return;
        }
        $ignoreErrors = [];
        require __DIR__ . '/../../core/.phpstan-baseline.php';
        $stats = ['__total' => 0];
        foreach ($ignoreErrors as $ignore) {
        $identifier = $ignore['identifier'] ?? '* not specified *';
        $count = $ignore['count'] ?? 1;
        $stats['__total'] += $count;
        $stats[$identifier] = isset($stats[$identifier]) ? $stats[$identifier] + $count : $count;
        }
        echo "----------------------------------------\n";
        echo "PHPStan baseline statistics\n";
        echo "----------------------------------------\n";
        echo sprintf("%6d * Total baselined errors\n", $stats['__total']);
        echo "----------------------------------------\n";
        echo "Breakdown by error identifier:\n";
        file_put_contents(__DIR__ . '/../../phpstan-metrics.txt', 'phpstan-baseline ' . $stats['__total'] . PHP_EOL, FILE_APPEND);
        unset($stats['__total']);
        arsort($stats);
        foreach ($stats as $identifier => $stat) {
        echo sprintf("%6d %s\n", $stat, $identifier);
        file_put_contents(__DIR__ . '/../../phpstan-metrics.txt', 'phpstan-baseline.' . $identifier . ' ' . $stat . PHP_EOL, FILE_APPEND);
        }
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please register or to comment