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

Unable to register extension when requiring deptrac-shim #916

Closed
patrickkusebauch opened this issue Jun 17, 2022 · 8 comments
Closed

Unable to register extension when requiring deptrac-shim #916

patrickkusebauch opened this issue Jun 17, 2022 · 8 comments

Comments

@patrickkusebauch
Copy link
Collaborator

patrickkusebauch commented Jun 17, 2022

patrick@thinkpad ~/PhpstormProjects/deptrac-awesome (main)$ bin/deptrac -vvv

Box Requirements Checker
========================

> Using PHP 8.1.2
> PHP is using the following php.ini file:
  /etc/php/8.1/cli/php.ini

> Checking Box requirements:
  ✔ The application requires the version "^7.4 || ^8.0" or greater.
  ✔ The application requires the extension "zlib".
  ✔ The application requires the extension "json".
  ✔ The package "nikic/php-parser" requires the extension "tokenizer".
  
                                                                                                                                                                                                                                                                         
 [OK] Your system is ready to run the application.                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                         


Box Requirements Checker
========================

> Using PHP 8.1.2
> PHP is using the following php.ini file:
  /tmp/7PlT08

> Checking Box requirements:
  ✔ The application requires the version "^7.4 || ^8.0" or greater.
  ✔ The application requires the extension "zlib".
  ✔ The application requires the extension "json".
  ✔ The package "nikic/php-parser" requires the extension "tokenizer".
  
                                                                                                                                                                                                                                                                         
 [OK] Your system is ready to run the application.                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                         


In AddConsoleCommandPass.php line 61:
                                                                                                                                      
  [_HumbugBox412203342c3b\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]                                   
  The service "0" tagged "console.command" must be a subclass of "_HumbugBox412203342c3b\Symfony\Component\Console\Command\Command".  
                                                                                                                                      

Exception trace:
  at phar:///home/patrick/PhpstormProjects/deptrac-awesome/vendor/qossmic/deptrac-shim/deptrac/vendor/symfony/console/DependencyInjection/AddConsoleCommandPass.php:61
 _HumbugBox412203342c3b\Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass->process() at phar:///home/patrick/PhpstormProjects/deptrac-awesome/vendor/qossmic/deptrac-shim/deptrac/vendor/symfony/dependency-injection/Compiler/Compiler.php:72
 _HumbugBox412203342c3b\Symfony\Component\DependencyInjection\Compiler\Compiler->compile() at phar:///home/patrick/PhpstormProjects/deptrac-awesome/vendor/qossmic/deptrac-shim/deptrac/vendor/symfony/dependency-injection/ContainerBuilder.php:642
 _HumbugBox412203342c3b\Symfony\Component\DependencyInjection\ContainerBuilder->compile() at phar:///home/patrick/PhpstormProjects/deptrac-awesome/vendor/qossmic/deptrac-shim/deptrac/src/DependencyInjection/ServiceContainerBuilder.php:62
 Qossmic\Deptrac\DependencyInjection\ServiceContainerBuilder->build() at phar:///home/patrick/PhpstormProjects/deptrac-awesome/vendor/qossmic/deptrac-shim/deptrac/src/Console/Application.php:58
 Qossmic\Deptrac\Console\Application->doRun() at phar:///home/patrick/PhpstormProjects/deptrac-awesome/vendor/qossmic/deptrac-shim/deptrac/vendor/symfony/console/Application.php:157
 _HumbugBox412203342c3b\Symfony\Component\Console\Application->run() at phar:///home/patrick/PhpstormProjects/deptrac-awesome/vendor/qossmic/deptrac-shim/deptrac/deptrac.php:24
 require() at /home/patrick/PhpstormProjects/deptrac-awesome/vendor/qossmic/deptrac-shim/deptrac:14
 include() at /home/patrick/PhpstormProjects/deptrac-awesome/bin/deptrac:117

Also:

  • Deptrac PHAR installation works
  • PHIVE installation works
@dbrumann
Copy link
Collaborator

If the scoper is at fault, I have to think about a good solution.

Disabling it, would essentially defeat the purpose of having deptrac-shim. Maybe we can exclude Symfony contracts from scoping?

@dbrumann
Copy link
Collaborator

dbrumann commented Sep 8, 2022

This is probably a tricky one. We can definitely look at phpstan for inspiration. As far as I can tell, we need to be able to refer to the project's own autoloader in the depfile and then integrate it with our autoloader.

@patrickkusebauch
Copy link
Collaborator Author

I have read through the box and scoper documentation and from what I understood it is actually much simpler. The reason for scoping is to not clash at runtime with outside code. However this can never happen in deptrac, as:

  • We do not provide/support API where you can call deptrac's PHP code from your code
  • We do not load/execute any outside PHP code in deptrac

Both NikicPHPParser and BetterReflection(possible solution to analyzing method calls) do not actually load the inspected code into the runtime, therefore there are no clashes there.

If we were doing it, you could not run deptrac on itself without packaging it first, but you can. This is a perfectly working command that I use quite often to test I have not broken anything:

# inside deptrac project root folder
php deptrac.php

Maybe I am missing something here...

@gennadigennadigennadi
Copy link
Member

How would we deal with conflicting dependencies? Deptrac right now depends on the v2 of composer/xdebug-handler and not v3. Therefore I could require Deptrac directly.

The shim helps right now with this. How do other projects like PhpStan handle this?

@patrickkusebauch
Copy link
Collaborator Author

With a custom compiler and configs like these: https:/phpstan/phpstan-src/blob/1.9.x/compiler/build/scoper.inc.php. I don't think we have the manpower to replicate and maintain this effort. There are paid developers working on PhpStan, it is not a fair comparison. If you need to deal with conflicting dependencies, you can always install a PHAR version instead.

@dbrumann
Copy link
Collaborator

dbrumann commented Oct 6, 2022

I would prefer people use the phar archive via shim or phive rather than the src. It is mostly to prevent version conflicts between dependencies, but also avoiding issues from people who expect backwards compatibility for Deptrac classes in their vendor directory, which we don't guarantee (as noted in the docs upgrade I recently started).

I really want to look into phpstan's scoper and how much work it would be to provide something similar before deciding to sunset the phar archives.

@ariddlestone
Copy link
Contributor

ariddlestone commented May 5, 2023

How about adding deptrac as an executable in the main repository's composer.json, and then recommending people use https:/bamarni/composer-bin-plugin to keep the dependencies separate?

To make my plugin usable I added a new bin (named deptrac-x) which calls deptrac from the main repo, allowing me to include my plugins and have an executable. See https:/ariddlestone/deptrac-extras.

I can now require my package (rather than deptrac-shim) using composer-bin-plugin, and run deptrac from vendor/bin/deptrac-x. It would be nice if I didn't have to though 😉

@patrickkusebauch
Copy link
Collaborator Author

The deptrac-shim version is no longer distributed starting with the 2.0.x line. We have a scoped release from now on. I consider this resolved.

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

No branches or pull requests

4 participants