User Tools

Site Tools


gitlab-ci-code-quality-phpstan

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
gitlab-ci-code-quality-phpstan [2020/12/01 22:28] – created admingitlab-ci-code-quality-phpstan [2020/12/02 14:34] (current) admin
Line 1: Line 1:
 ====== Gitlab Code Quality Widget and PHPStan ====== ====== Gitlab Code Quality Widget and PHPStan ======
 +
 +{{ ::gitlab-code-quality-widget.png?600 |}}
 +
 +<note tip>Make sure you run it on ''master'' branch first. If no artifact exists on master Gitlab can't compare code quality</note>
 +
 +
 +===== Install  =====
 +
 +**PHPStan**
 +
 +<code bash>
 +composer require --dev phpstan/phpstan
 +</code>
 +
 +**Add ''.gitlab-ci.yml'':**
 +
  
 <code yaml .gitlab-ci.yml> <code yaml .gitlab-ci.yml>
Line 5: Line 21:
   - test   - test
  
-code_quality:+php_stan:
   image: composer   image: composer
   stage: test   stage: test
   script:   script:
     - composer install --no-ansi     - composer install --no-ansi
-    # Set output to 'gitlab' using '--error-format=gitlab', 'exit 0' is required and the artifact gets uploaded +    # Set output to 'gitlab' using '--error-format=gitlab', the artifact gets uploaded 
-    - ./vendor/bin/phpstan analyse --error-format=gitlab --no-progress Classes/ > gl-code-quality-report.json || exit 0+    - ./vendor/bin/phpstan analyse --error-format=gitlab --no-progress Classes/ > gl-phpstan-report.json || exit 0
   artifacts:   artifacts:
     reports:     reports:
-      codequality: gl-code-quality-report.json +      # Tell Gitlab about the custom generated reports JSON file 
-    paths: [gl-code-quality-report.json] +      codequality: gl-phpstan-report.json 
 +    # Optional 
 +    paths: [gl-phpstan-report.json]
 </code> </code>
 +
 +===== 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.1606861691.txt.gz · Last modified: 2020/12/01 22:28 by admin