User Tools

Site Tools


gitlab-ci-code-quality-php-cs-fixer

Gitlab Code Quality Widget and PHP CS Fixer

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

Install

PHP CS Fixer

composer require friendsofphp/php-cs-fixer --dev

Add .gitlab-ci.yml:

.gitlab-ci.yml
stages:
  - test

php-cs-fixer:
  image: composer
  stage: test
  script:
    - composer install
    - ./vendor/bin/php-cs-fixer fix -v --dry-run --format gitlab --using-cache false > gl-php-cs-fixer-report.json || exit 0
  artifacts:
    reports:
      codequality: gl-php-cs-fixer-report.json
    # Optional
    paths: [gl-php-cs-fixer-report.json]

Command explained

./vendor/bin/php-cs-fixer fix -v –dry-run –format gitlab –using-cache false > gl-php-cs-fixer-report.json exit 0
Run analyzer, but do not fix code style Output Gitlab readable JSON format Disable cache Write output to file Optional: Make sure job always passes
gitlab-ci-code-quality-php-cs-fixer.txt · Last modified: 2020/12/02 15:35 by admin