<commit_before># Deptrac

## What is Deptrac

Deptrac is a static code analysis tool that helps to enforce rules for dependencies between software layers.

For example, you can define a rule like "controllers may not depend on models".
To ensure this, deptrac analyzes your code to find any usages of models in your controllers and will show you where
this rule was violated.

![ModelController1](examples/ControllerServiceRepository1.png)

### Introduction Video
[![ScreenShot](examples/youtube.png)](https://www.youtube.com/watch?v=T5oWc4ujmOo)


## Getting Started

The easiest way to get started is to download the [deptrac.phar](http://get.sensiolabs.de/deptrac.phar).

At first, you need a so called *depfile*, which is written in YAML.
You can generate a bootstrapped `depfile.yml` with

```bash
php deptrac.phar init
```

In this file you define (mainly) three things:

1. The location of your source code.
2. The layers of you application.
3. The allowed dependencies between your layers.


### The depfile

Let's have a look at the generated file:

```yaml
# depfile.yml 
paths:
  - ./src
exclude_files:
  - .*test.*
layers:
  - name: Controller
    collectors:
      - type: className
        regex: .*Controller.*
  - name: Repository
    collectors:
      - type: className
        regex: .*Repository.*
  - name: Service
    collectors:
      - type: className
        regex: .*Service.*
ruleset:
  Controller:
    - Service
  Service:
    - Repository
  Repository: ~
```


#### Explanation

In the first section, `paths`, you declare where deptrac should look for your code.
As this is an array of directories, you can specify multiple locations.

With the `exclude_files` section, you can specify one or more regular expressions for files that should be excluded,
the most common being probably anything containing the "test" word in the path.

We defined three `layers` in the example: *Controller*, *Repository* and *Service*.
Deptrac is using so called `collectors` to group classes into `layers` (in this case by the name of the class).

The `ruleset` section defines, how these layers may or may not depend on other layers.
In the example, every class of the *Controller*-layer may depend on classes that reside in the *Service*-layer,
and classes in the *Service*-layer may depend on classes in the *Repository*-layer.

Classes in the *Repository*-layer may NOT depend on any classes in other layers.
The `ruleset` acts as a whitelist, therefore the *Repository*-layer rules can be omitted, however
explicitly stating that the layer may not depend on other layers is more declarative.

If a class in the *Repository*-layer uses a class in the *Service*-layer, deptrac wil recognize the dependency
and throws a violation for this case. The same counts if a *Service*-layer-class uses a *Controller*-layer-class.


## Installation

### Download the phar (recommended)

Download the [deptrac.phar](http://get.sensiolabs.de/deptrac.phar) and run it using `php deptrac.phar`.
Feel free to add it to your PATH (i.e. `/usr/local/bin/box`)

```bash
curl -LS https://get.sensiolabs.de/deptrac.phar -o deptract.phar

# optional
sudo chmod +x deptrac.phar
sudo mv deptract.phar /usr/bin/local/deptrac
```

(In this guide, we assume, you have the [deptrac.phar](http://get.sensiolabs.de/deptrac.phar) in your project root)


### Optional dependency: Graphviz

If you want to create graphical diagrams with your class dependencies, you will also need the `dot` command provided by [Graphviz](http://www.graphviz.org/).
Graphviz can be install using common package managers:

```bash
# for osx + brew
brew install graphviz

# for ubuntu and debian
sudo apt-get install graphviz
```

<commit_msg>Fixed typo in filename<commit_after># Deptrac

## What is Deptrac

Deptrac is a static code analysis tool that helps to enforce rules for dependencies between software layers.

For example, you can define a rule like "controllers may not depend on models".
To ensure this, deptrac analyzes your code to find any usages of models in your controllers and will show you where
this rule was violated.

![ModelController1](examples/ControllerServiceRepository1.png)

### Introduction Video
[![ScreenShot](examples/youtube.png)](https://www.youtube.com/watch?v=T5oWc4ujmOo)


## Getting Started

The easiest way to get started is to download the [deptrac.phar](http://get.sensiolabs.de/deptrac.phar).

At first, you need a so called *depfile*, which is written in YAML.
You can generate a bootstrapped `depfile.yml` with

```bash
php deptrac.phar init
```

In this file you define (mainly) three things:

1. The location of your source code.
2. The layers of you application.
3. The allowed dependencies between your layers.


### The depfile

Let's have a look at the generated file:

```yaml
# depfile.yml 
paths:
  - ./src
exclude_files:
  - .*test.*
layers:
  - name: Controller
    collectors:
      - type: className
        regex: .*Controller.*
  - name: Repository
    collectors:
      - type: className
        regex: .*Repository.*
  - name: Service
    collectors:
      - type: className
        regex: .*Service.*
ruleset:
  Controller:
    - Service
  Service:
    - Repository
  Repository: ~
```


#### Explanation

In the first section, `paths`, you declare where deptrac should look for your code.
As this is an array of directories, you can specify multiple locations.

With the `exclude_files` section, you can specify one or more regular expressions for files that should be excluded,
the most common being probably anything containing the "test" word in the path.

We defined three `layers` in the example: *Controller*, *Repository* and *Service*.
Deptrac is using so called `collectors` to group classes into `layers` (in this case by the name of the class).

The `ruleset` section defines, how these layers may or may not depend on other layers.
In the example, every class of the *Controller*-layer may depend on classes that reside in the *Service*-layer,
and classes in the *Service*-layer may depend on classes in the *Repository*-layer.

Classes in the *Repository*-layer may NOT depend on any classes in other layers.
The `ruleset` acts as a whitelist, therefore the *Repository*-layer rules can be omitted, however
explicitly stating that the layer may not depend on other layers is more declarative.

If a class in the *Repository*-layer uses a class in the *Service*-layer, deptrac wil recognize the dependency
and throws a violation for this case. The same counts if a *Service*-layer-class uses a *Controller*-layer-class.


## Installation

### Download the phar (recommended)

Download the [deptrac.phar](http://get.sensiolabs.de/deptrac.phar) and run it using `php deptrac.phar`.
Feel free to add it to your PATH (i.e. `/usr/local/bin/box`)

```bash
curl -LS https://get.sensiolabs.de/deptrac.phar -o deptrac.phar

# optional
sudo chmod +x deptrac.phar
sudo mv deptrac.phar /usr/bin/local/deptrac
```

(In this guide, we assume, you have the [deptrac.phar](http://get.sensiolabs.de/deptrac.phar) in your project root)


### Optional dependency: Graphviz

If you want to create graphical diagrams with your class dependencies, you will also need the `dot` command provided by [Graphviz](http://www.graphviz.org/).
Graphviz can be install using common package managers:

```bash
# for osx + brew
brew install graphviz

# for ubuntu and debian
sudo apt-get install graphviz
```


{'fraction_non_alphanumeric': 0.08846931894807822, 'fraction_numerical': 0.001888064733648011, 'mean_word_length': 3.990578734858681, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4679387', 'n_tokens_mistral': 2239, 'n_tokens_neox': 2133, 'n_words': 963}