phpcontinuous-integrationstatic-code-analysisphpcsscrutinizer

How to fail a build on Scrutinizer based on phpcs output?


I've tried configuring Scrutinizer to fail whenever the CodeSniffer analysis returns some errors with no luck.

Here's what I tried so far:

V1:

build:
  tests:
    override:
        command: './vendor/bin/phpcs ./src --report=checkstyle --report-file=cs-data'
        analysis:
          file: 'cs-data'
          format: 'php-cs-checkstyle'

V2:

build:
  tests:
    override:
      - 'phpcs-run'

My tools and build_failure_conditions:

tools:
  php_code_sniffer:
    config:
      standard: "PSR2"
checks:
  php:
    code_rating: true
    duplication: true
build_failure_conditions:
  - 'issues.label("coding-style").new.exists'

What's missing?


Solution

  • TLDR; It looks like you're not specifying which folders to scan for errors.

    Try using the following:

    build:
      tests:
        override:
          - 'phpcs-run --standard=custom/standard/ruleset.xml --ignore=app/*/*/Test/ app/dir1/ app/dir2/ app/other/folder'
    

    Some things that required clarification for me:

    I'm currently using:

    build_failure_conditions:
      - 'issues.label("coding-style").new.exists'
    

    Which makes the inspection look like this

    More info about how to set-up failure conditions: https://scrutinizer-ci.com/docs/configuration/build_status