Slide 1

Slide 1 text

Dependency Tracking with Deptrac Jan Schädlich @jschaedl SensioLabs 2020-10-13 | Symfony User Group Hamburg An Introduction with Examples

Slide 2

Slide 2 text

Software Architecture

Slide 3

Slide 3 text

–Ralph Johnson „Architecture is about the important stuff. Whatever that is.“

Slide 4

Slide 4 text

Core Admin Customer Driven Driving Hexagonal Architecture Onion Architecture Separation of Concerns ‣ Separation is achieved by dividing the software into layers ‣ At least one layer for business rules and another for interfaces

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

How to ensure that our code follows the defined architecture?

Slide 7

Slide 7 text

https://github.com/sensiolabs-de/deptrac Deptrac

Slide 8

Slide 8 text

Installation

Slide 9

Slide 9 text

✓ PHAR | https://github.com/sensiolabs-de/deptrac/releases ✓ phive install -g sensiolabs-de/deptrac ✓ composer require --dev sensiolabs-de/deptrac-shim X composer require --dev sensiolabs-de/deptrac

Slide 10

Slide 10 text

The depfile.yaml

Slide 11

Slide 11 text

# depfile.yaml paths: - ./src exclude_files: - .*Tests.* - .*Resources.* - .*DependencyInjection.*

Slide 12

Slide 12 text

# ... layers: - name: Entity collectors: - type: className regex: .*\\App\\Entity\\.* ‣ There are also other collector types available.

Slide 13

Slide 13 text

# ... layers: # ... - name: UseCase collectors: - type: className regex: .*\\App\\UseCase\\.*

Slide 14

Slide 14 text

# ... layers: # ... - name: Controller collectors: - type: className regex: .*\\App\\Controller\\.*

Slide 15

Slide 15 text

# ... ruleset: Entity: ~ UseCase: - Entity Controller: - Entity - UseCase The Entity layer must not depend on other layers. The UseCase layer only depends on the Entity layer. The Controller layer can depend on the Entity and the UseCase layer.

Slide 16

Slide 16 text

Collectors

Slide 17

Slide 17 text

# directory - name: Controller collectors: - type: directory regex: ./App/Controller/.*

Slide 18

Slide 18 text

# className - name: Controller collectors: - type: className regex: .*App\\.*Controller.*

Slide 19

Slide 19 text

# classNameRegex - name: Controller collectors: - type: classNameRegex regex: '#.*App\\.*Controller.*#'

Slide 20

Slide 20 text

# bool - name: Admin collectors: - type: bool must: - type: className regex: .*\\Admin\\.* must_not: - type: className regex: .*\\AdminBundle\\.*

Slide 21

Slide 21 text

# method - name: Foo services collectors: - type: method name: .*foo

Slide 22

Slide 22 text

# implements - name: Foo collectors: - type: implements name: 'App\SomeInterface'

Slide 23

Slide 23 text

# extends - name: Foo collectors: - type: extends name: 'App\SomeClass'

Slide 24

Slide 24 text

# uses - name: Foo collectors: - type: uses name: 'App\SomeTrait'

Slide 25

Slide 25 text

# inherits - name: Foo collectors: - type: inherits name: 'App\{Interface|Class|Trait}'

Slide 26

Slide 26 text

Formatters

Slide 27

Slide 27 text

Console ‣ This is the default formatter.

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

Github Actions ‣ Default formatter in Github Actions environment.

Slide 30

Slide 30 text

Github Actions

Slide 31

Slide 31 text

$ deptrac analyze examples/ControllerServiceRepository1.depfile.yml \ -—formatter-graphviz=1 \ --formatter-graphviz-display=1 \ --formatter-graphviz-dump-image=path/to/file.png \ --formatter-graphviz-dump-dot=path/to/file.dot \ —-formatter-graphviz-dump-html=path/to/file.html Graphviz

Slide 32

Slide 32 text

$ deptrac analyze examples/ControllerServiceRepository1.depfile.yml \ -—formatter-junit=1 \ —-formatter-junit-dump-xml=./junit-report.xml JUnit

Slide 33

Slide 33 text

$ deptrac analyze examples/ControllerServiceRepository1.depfile.yml \ -—formatter-xml=1 \ —-formatter-xml-dump-xml=./deptrac-report.xml XML

Slide 34

Slide 34 text

https://github.com/jschaedl/sfughh-deptrac Demo

Slide 35

Slide 35 text

More

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

# skip_violations skip_violations: App\SomeClass: - App\SomeDependency

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

Thank you! https://speakerdeck.com/jschaedl