User Tools

Site Tools


gitlab-ci-code-quality-phpstan

This is an old revision of the document!


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

code_quality:
  image: composer
  stage: test
  script:
    - composer install --no-ansi
    # Set output to 'gitlab' using '--error-format=gitlab', 'exit 0' is required and the artifact gets uploaded
    - ./vendor/bin/phpstan analyse --error-format=gitlab --no-progress Classes/ > gl-code-quality-report.json || exit 0
  artifacts:
    reports:
      # Tell Gitlab about the custom generated reports JSON file
      codequality: gl-code-quality-report.json
    paths: [gl-code-quality-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 Make sure job always passes
gitlab-ci-code-quality-phpstan.1606863865.txt.gz · Last modified: 2020/12/01 23:04 by admin