-
Notifications
You must be signed in to change notification settings - Fork 136
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
Is it possible to disallow direct extension, but allow indirect extension? #1186
Comments
No need to look for another tool. It is possible. Give me a few hours to finish at work and I will post a solution. |
Can you provide me with the text of the Violation as shown in the console? It would help me craft the code for you. Or the repo in question, if it is public? |
The violation I'm getting is this one Violation Company\Infrastructure\SomeClass must not depend on RuntimeException (Base_Php_Exceptions)
Company\Infrastructure\SomeClass::12 ->
Company\Exception\SystemException::13 ->
RuntimeException::24
src/Exception/CompanyRuntimeException.php:24 Unfortunately I cannot share the repository, but if this isn't enough information, I can recreate the issue in a separate repo |
The short answer is - you can use a custom Deptrac even already does this internally, if you look here: https:/qossmic/deptrac/blob/main/internal/deptrac/IgnoreDependenciesOnContract.php and how it is registered here: Line 18 in a446b66
Line 2 in a446b66
You just need to match the violation in question and stop propagation right there. |
Small reproducing repo would certainly be helpful. |
Here is a small example project with this structure reproducing the problem. https:/pckuijper/custom-exceptions I'm trying to figure out how to set up what you describe in the short answer, but unfortunately to no avail just yet. |
No promises, but give me 24 hours. |
Provided in pckuijper/custom-exceptions#1 |
Thanks for helping with implementing this! It was a great help. One final issue I'm running into is quite likely related to the version of deptrac we're using (0.24) due to php + symfony constraints. It looks like the code should still work in the same way and I'm trying to tag my event listener by using services:
- class: Company\Tests\Framework\StaticAnalysis\Deptrac\AllowCustomExceptionsRule
tags:
- { name: kernel.event_listener, event: Qossmic\Deptrac\Contract\Analyser\ProcessEvent } Copied over from https:/qossmic/deptrac/blob/0.24.0/deptrac.yaml Is there any known issues with that version and extending deptrac with custom services? I've updated my example project with version 0.24 (pckuijper/custom-exceptions@038846f) |
For event listener it might not get executed if there was a listener with higher priority that was executed before yours with the default priority that has called |
Hi, so I looked into it, and yes, PHP Fatal error: Uncaught Error: Call to undefined method Qossmic\Deptrac\Core\Dependency\Dependency::getType() in /home/patrick/PhpstormProjects/custom-exceptions/src/CustomExceptionRule.php:32 |
I have found a "workaround", it's probably not as optimal as it could be but it's good enough for us for now! I'll leave the repository up in case this is of any help to anybody in the future. The main branch has a working setup with the current latest version of Repo: Thanks a lot for your help!! |
I wanna start of with by thanking everybody working on this tool for what it makes possible! It's great and helps me and my team to build better software in guidance with our architectural rules.
My question comes from a want to only allow our internal code to make use of our own exception layer.
The setup is roughly as follows:
The config I'm trying to work with is roughly follows
The issue I am running into, is that something in the
Company
layer is using theCompany_Php_Exceptions
layer, which itself relies on theBase_Php_Exceptions
, a violation is raised because it checks the whole dependency graph and not just the first layer.I've tried using the
InheritanceLevel
collector, but to no avail.Now I'm starting to wonder if this is possible at all using Deptrac, or if I have to rely on other tooling.
Any thoughts, or guidance is much appreciated!
The text was updated successfully, but these errors were encountered: