How to use PHPInsights in GitLab?

How to use PHPInsights in GitLab?

We've covered PHPStan in the last post. This time let's get PHPInsight's working in GitLab alongside PHPStan.

Both PHPStan and PHP Insights can both output the results into the same code climate report for UI viewing on a per-file basis.

Unlike PHPStan, Insight's doesn't have a baseline that we can start with. But, what we do have is we can set a minimum score for each category.

If you're not ready (lol who is?!) to get everything to 100% in your project, I recommend running locally and then setting those numbers as your minimum to prevent slipping. Then slowly you can bump the percentage down as you fix files.

To get started just add the following to your current .gitlab-ci.yml

insights:
  stage: testing
  needs:
  - composer
  script:
  - php artisan insights  -n --ansi --format=codeclimate > codeclimate-report.json
  artifacts:
    paths:
    - "./codeclimate-report.json"
    when: always
    reports:
      codequality: codeclimate-report.json
    expire_in: 1 week

Of course, change your needs and stage to match your current build.

Set your minimums for what will error out the job with:

--min-quality=80 --min-complexity=90 --min-architecture=75 --min-style=95

The full command will be:

  - vendor/bin/phpinsights -n --ansi --min-quality=80 --min-complexity=90 --min-architecture=75 --min-style=95 --format=codeclimate > codeclimate-report.json

Want to use artisan:

  - php artisan insights -n --ansi --min-quality=80 --min-complexity=90 --min-architecture=75 --min-style=95 --format=codeclimate > codeclimate-report.json

Thanks, for reading, please let me know if you found this helpful or have questions over on Twitter: twitter.com/DigiGuyDev or in the comments below!

Did you find this article valuable?

Support Guy Warner by becoming a sponsor. Any amount is appreciated!