User Tools

Site Tools


gitlab-ci-code-quality-phpstan

Gitlab Code Quality Widget and PHPStan

Make sure you run it on master branch first. If no artifact exists on master Gitlab can't compare code quality

Install

PHPStan

composer require --dev phpstan/phpstan

Add .gitlab-ci.yml:

.gitlab-ci.yml
stages:
  - test

php_stan:
  image: composer
  stage: test
  script:
    - composer install --no-ansi
    # Set output to 'gitlab' using '--error-format=gitlab', the artifact gets uploaded
    - ./vendor/bin/phpstan analyse --error-format=gitlab --no-progress Classes/ > gl-phpstan-report.json || exit 0
  artifacts:
    reports:
      # Tell Gitlab about the custom generated reports JSON file
      codequality: gl-phpstan-report.json
    # Optional
    paths: [gl-phpstan-report.json]

Command explained

./vendor/bin/phpstan analyse –error-format=gitlab –no-progress Classes/ > gl-code-quality-report.json exit 0
Run analyzer Output Gitlab readable JSON format Hide progress indicator Folders to analyze Write output to file Optional: Make sure job always passes
gitlab-ci-code-quality-phpstan.txt · Last modified: 2020/12/02 14:34 by admin