Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

composer doesn't allow to check exclusion from one of the packages #1420

Open
pizgariu opened this issue May 30, 2024 · 2 comments
Open

composer doesn't allow to check exclusion from one of the packages #1420

pizgariu opened this issue May 30, 2024 · 2 comments

Comments

@pizgariu
Copy link

pizgariu commented May 30, 2024

deptrac:
  paths:
    - './src/'
  exclude_files:
    - '#.*[tT]est.php#'
    - '#Kernel\.php$#'
    - '#.*Response.php$#'
  layers:
    - name: Domain
      collectors:
        - type: directory
          value: src/Domain/.*
    - name: Application
      collectors:
        - type: directory
          value: src/Application/.*
    - name: Infrastructure
      collectors:
        - type: directory
          value: src/Infrastructure/.*
    - name: UI
      collectors:
        - type: directory
          value: src/UI/.*
    - name: Shared
      collectors:
        - type: directory
          value: src/Shared/.*
    - name: Symfony
      collectors:
        - type: composer
          composerPath: composer.json
          composerLockPath: composer.lock
          packages:
            - symfony/amqp-messenger
            - symfony/apache-pack
            - symfony/asset
            - symfony/console
            - symfony/doctrine-messenger
            - symfony/dotenv
            - symfony/expression-language
            - symfony/flex
            - symfony/form
            - symfony/framework-bundle
            - symfony/http-client
            - symfony/intl
            - symfony/mailer
            - symfony/mime
            - symfony/monolog-bundle
            - symfony/notifier
            - symfony/process
            - symfony/property-access
            - symfony/property-info
            - symfony/proxy-manager-bridge
            - symfony/runtime
            - symfony/security-bundle
            - symfony/serializer
            - symfony/string
            - symfony/translation
            - symfony/twig-bundle
            - symfony/uid
            - symfony/validator
            - symfony/web-link
            - symfony/webpack-encore-bundle
            - symfony/yaml
    - name: SymfonyValidator
      collectors:
        - type: classLike
          value: 'Symfony\\Component\\Validator\\Constraint'
  ruleset:
    Shared:
      - Symfony
    Domain:
      - Shared
    Application:
      - Domain
      - Shared
      # TODO: Symfony are ONLY allowed in the Application layer cause we use DTOs and Symfony Validator which violates the ruleset, need to allow ONLY for this package
#      - Symfony
      - SymfonyValidator
    Infrastructure:
      - Application
      - Domain
      - Shared
      - Symfony
      - UI
    UI:
      - Infrastructure
      - Application
      - Domain
      - Shared
      - Symfony
      - SymfonyValidator
  formatters:
    graphviz:
      hidden_layers:
        - Symfony

If we switch to the Symfony this will work, but also could include ALL from Symfony packages which is not good for onion architecture.
Can You please explain me if this is a bug or maybe I don't know how to work with deptrac :)

Thanks for any help!

PS. I've found attribute and I was sure that was the collector what I was looking for - its for Assert fot DTO's. But with this config it's still not working & duplicate same errors:

    - name: SymfonyValidator
      collectors:
        - type: attribute
          value: 'Symfony\Component\Validator\Constraints'
@pizgariu
Copy link
Author

pizgariu commented May 31, 2024

image

May I use to write my own attribute check if this not working? Can anyone reproduce? My DTO class:

<?php

namespace MiningCity\DirectMiningService\Application\Post\DTO\Request;

use Symfony\Component\Validator\Constraints as Assert;

final class UpdatePostRequest
{
    #[Assert\NotBlank]
    #[Assert\Type('string')]
    #[Assert\Length(min: 10)]
    public string $content;

    public ?\DateTime $publishedAt = null;
}

When I use this extra later and additionaly remove it from Symfony composer collector shows issues on two layers used on Application.

@pizgariu
Copy link
Author

I think I get it - You check for ClassLikeReference or FunctionReference, but I can't see any ClassPropertyReference... Am I right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant