You can run PHP Insights in your CI by defining a level you want to reach with the options
If the minimum level defined is not reached, the console will return an exit error code.
./vendor/bin/phpinsights --no-interaction --min-quality=80 --min-complexity=90 --min-architecture=75 --min-style=95 # Within Laravel php artisan insights --no-interaction --min-quality=80 --min-complexity=90 --min-architecture=75 --min-style=95
These options can also be found in the configuration file, so no arguments needs to be passed when calling the command. Command arguments has higher priority than configuration values.
--no-interaction option is mandatory when it's launched in CI to avoid prompts.
All others are optional, so if you want to focus only on style, add the
--min-style and forget others.
Disable Security Check
In case you develop a library or a plugin, it could be compatible with a large panel of dependencies versions.
So you can launch your
composer update with
--prefer-lower flag to tests theses minimum version.
phpinsights returns an exit error code if security issues are found, you can disable this check by adding the
--disable-security-check option :
./vendor/bin/phpinsights --no-interaction --disable-security-check
Note : For a project inspection, you should never use this option to keep your project safe.
If you use Github Action, you can launch PHP Insights with
With that, annotations with issues will be added in Pull request.
#.github/workflows/pr.yml name: CI on: - pull_request jobs: phpinsights: runs-on: ubuntu-latest name: PHP Insights checks steps: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 with: php-version: 8.0 - run: composer install --prefer-dist --no-progress --no-suggest - run: vendor/bin/phpinsights -n --ansi --format=github-action
^2.0GitLab Code Quality
If you use GitLab, you can launch PHP Insights with
With that, annotations with issues will be added in a merge request with Code Quality.
#.gitlab-ci.yml insights: script: - vendor/bin/phpinsights -n --ansi --format=codeclimate > codeclimate-report.json artifacts: reports: codequality: codeclimate-report.json