$30 off During Our Annual Pro Sale. View Details »

Dependency Tracking with Deptrac

Dependency Tracking with Deptrac

Jan Schädlich

October 13, 2020
Tweet

More Decks by Jan Schädlich

Other Decks in Programming

Transcript

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

    View Slide

  2. Software Architecture

    View Slide

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

    View Slide

  4. 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

    View Slide

  5. View Slide

  6. How to ensure that our code follows the
    defined architecture?

    View Slide

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

    View Slide

  8. Installation

    View Slide

  9. ✓ 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

    View Slide

  10. The depfile.yaml

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  15. # ...
    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.

    View Slide

  16. Collectors

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  26. Formatters

    View Slide

  27. Console
    ‣ This is the default formatter.

    View Slide

  28. View Slide

  29. Github Actions
    ‣ Default formatter in Github Actions environment.

    View Slide

  30. Github Actions

    View Slide

  31. $ 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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  35. More

    View Slide

  36. View Slide

  37. View Slide

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

    View Slide

  39. View Slide

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

    View Slide