Skip to content

How to set up Scrutinizer

samuelgfeller edited this page May 14, 2024 · 2 revisions

Introduction

Scruitinizer is a continuous inspection platform to continuously measure and track code quality.

Below is a guide on how to set up Scrutinizer for PHP projects with this Configuration structure of the slim-example-project, slim-api-starter and the slim-starter project templates.

Scrutinizer local config

The database name and credentials used by Scrutinizer must be set in the config/env/env.scrutinizer.php file.

File: config/env/env.scrutinizer.php

<?php

// Include testing configuration. Must be "require" and not require_once
require __DIR__ . '/env.test.php';

// Database
$settings['db']['host'] = '127.0.0.1';
$settings['db']['database'] = 'slim_example_project_test'; // replace with your test database name
$settings['db']['username'] = 'root';
$settings['db']['password'] = '';

The .scrutinizer.yml file (below) sets the APP_ENV to 'scrutinizer' which means that the env.scrutinizer.php file will be loaded when building the settings array in config/settings.php.

Scrutinizer settings

The Scrutinizer settings file .scrutinizer.yml stored in the project root folder defines the build configuration.
Replace the database name with the name of your test database as specified in config/env/env.scrutinizer.php.

File: .scrutinizer.yml

filter:
  paths: [ "src/*" ]
  excluded_paths: [ "vendor/*", "tests/*", "resources/", "public/", ]

checks:
  php:
    code_rating: true
    duplication: true

tools:
  external_code_coverage: false

build:
  services:
    mysql: 8.0.29
  environment:
    php:
      version: 8.2
      ini:
        xdebug.mode: coverage
    mysql: 5.7
    node: false
    postgresql: false
    mongodb: false
    elasticsearch: false
    redis: false
    memcached: false
    neo4j: false
    rabbitmq: false
    variables:
      APP_ENV: 'scrutinizer'
  nodes:
    analysis:
      tests:
        override:
          - php-scrutinizer-run
  dependencies:
    before:
      - composer self-update
      - mysql -uroot -e "CREATE DATABASE IF NOT EXISTS slim_example_project_test CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
  tests:
    before:
      - command: composer test:coverage
        coverage:
          file: 'build/logs/clover.xml'
          format: 'clover'

The composer test:coverage shortcut command has to be defined in the scripts section of the composer.json file with the coverage report path matching the one defined in the Scrutinizer settings above.

Now this file can be pushed to the remote repository and the project registered on the Scrutinizer website.

  1. Create an account.
  2. Add your repository by following the instructions on the website.
Clone this wiki locally