Skip to main content

Command Palette

Search for a command to run...

How to use PHPInsights in GitLab?

Published
2 min read
How to use PHPInsights in GitLab?
G

I am a self-taught developer currently in Salt Lake City. Currently, work in Laravel but have experience in plain PHP, PERL, and CakePHP.

Entrepreneurial VP of tech and CTO with a strong grasp of both the business and engineering. PHP developer for 10 years with experience in CakePHP and Laravel

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: https://twitter.com/DigiGuyDev or in the comments below!

More from this blog

Laravel & PHP by Guy Warner

18 posts

Self taught programmer -> Freelancer -> Senior Developer -> CTO

Laravel, PHP and all that comes with it.