Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dependency Tracking with Deptrac

Dependency Tracking with Deptrac

069a861584701a8b5f72a838bd7e0f2e?s=128

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
  2. Software Architecture

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

    is.“
  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
  5. None
  6. How to ensure that our code follows the defined architecture?

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

  8. Installation

  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
  10. The depfile.yaml

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

    - .*DependencyInjection.*
  12. # ... layers: - name: Entity collectors: - type: className

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

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

    type: className regex: .*\\App\\Controller\\.*
  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.
  16. Collectors

  17. # directory - name: Controller collectors: - type: directory regex:

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

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

    '#.*App\\.*Controller.*#'
  20. # bool - name: Admin collectors: - type: bool must:

    - type: className regex: .*\\Admin\\.* must_not: - type: className regex: .*\\AdminBundle\\.*
  21. # method - name: Foo services collectors: - type: method

    name: .*foo
  22. # implements - name: Foo collectors: - type: implements name:

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

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

    'App\SomeTrait'
  25. # inherits - name: Foo collectors: - type: inherits name:

    'App\{Interface|Class|Trait}'
  26. Formatters

  27. Console ‣ This is the default formatter.

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

  30. Github Actions

  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
  32. $ deptrac analyze examples/ControllerServiceRepository1.depfile.yml \ -—formatter-junit=1 \ —-formatter-junit-dump-xml=./junit-report.xml JUnit

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

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

  35. More

  36. None
  37. None
  38. # skip_violations skip_violations: App\SomeClass: - App\SomeDependency

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