Skip to content

Configuration

The configuration file describes your layers, ruleset and adjusts output formatting.

We suggest you also check out Deptrac's configuration for checking its own architecture as it uses most available options.

Deptrac

The following table shows the available config keys for Deptrac.

Property Path Input description Example usage
analyser.internal_tag Specifies a custom doc block tag which deptrac should use to identify layer-internal class-like structures. The tag @deptrac-internal will always be used for this purpose. This option allows an additional tag to be specified, such as @layer-internal or plain @internal.
deptrac:
  analyser:
    internal_tag: "@layer-internal"
analyser.types A list with at least one of the following supported dependency types:
  • class default — analyses class definitions for everything apart from superglobal usage.
  • class_superglobal — analyses class definitions for superglobal usage.
  • use default — analyses file definitions for use statements.
  • file — analyses file for everything apart from use statements and function/class definitions.
  • function — analyses function definitions for everything apart from superglobal usage.
  • function_superglobal — analyses function definitions for superglobal usage.
  • function_call — analyses calls to custom(user-defined) functions
deptrac:
  analyser:
    types:
      - "use"
      - "file"
      - "class_superglobal"
      - "function_superglobal"
      - "function_call"
paths List of paths where Deptrac should look for dependencies to be analysed. Usually, this is where your code is stored, e.g. src/, or lib/ or something similar.
deptrac:
  paths:
    - src/
exclude_files A list of regular expression-patterns to determine which files or directories to exclude, e.g. test files or config
deptrac:
  exclude_files:
    - '#.*Test\.php$#'
formatters.graphviz.groups Key is the name of the group and values are the layers belonging to that group
deptrac:
  formatters:
    graphviz:
      groups:
        Entrypoints:
          - Controllers
          - Commands
        Persistence:
          - Repositories
          - Entities
formatters.graphviz.hidden_layers List of layers to be excluded from the Graphviz output
deptrac:
  formatters:
    graphviz:
      hidden_layers:
        - Controllers
formatters.codeclimate.severity Assigns a severity to each section reported by Deptrac. The following severity types are supported by codeclimate:
  • info
  • minor
  • major
  • critical
  • blocker
deptrac:
  formatters:
    codeclimate:
      severity:
        failure: blocker
        skipped: major
        uncovered: major
deptrac.ignore_uncovered_internal_classes Whether PHP-internal classes like DateTimeImmutable should count towards uncovered classes, when they are not part of any layer.
deptrac:
  ignore_uncovered_internal_classes: false # default: true
deptrac.layers Defines your architectural layers by collecting dependencies using collectors
deptrac:
  layers:
    -
      name: Controller
      collectors:
        -
          type: classLike
          value: .*Controller.*
deptrac.ruleset Assign communication rules by specifying which layers a layer can communicate with (if any). If you prepend a layer with + then not only this layer is allowed, but also all layers it allows.
deptrac:
  ruleset:
    Controllers: [Services]
    Services:
      - Repositories
    Repositories: ~
deptrac.skip_violations Define a dictionary of dependencies and their known violations. This violations will be ignored in your pipeline and not trigger a failing return code.
deptrac:
  skip_violations:
    Library\LibClass:
      - Core\CoreClass

Imports

If your config file becomes too large, you can split it up into multiple files that can then be imported in the main file using the imports section. This is also useful to separate your baseline from the rest of the configuration, so it can be regenerated by the baseline formatter.

Example:

imports:
  - deptrac.baseline.yaml

Services

Please see Symfony docs. This allows you to register new services, e.g. custom formatters or collectors.

services:
  - class: Internal\Qossmic\Deptrac\IgnoreDependenciesOnContract
    tags:
      - { name: kernel.event_listener, event: Qossmic\Deptrac\Contract\Analyser\ProcessEvent }

Parameters

Deptrac provides parameters that can be user in your configuration.

  • %currentWorkingDirectory% The path Deptrac runs in
  • %projectDirectory% The path where the configuration is stored.
  • %cache_file% contains the filename and path for the cache file. Note: This parameter is overwritten by --cache-file= if it is set.

You can specify your own parameters and reuse them in your configuration:

Example:

parameters:
  Project: MyProject

deptrac:
  layers:
    -
      name: Foo
      collectors:
        -
          type: implements
          value: '%Project%\SomeInterface'