Unable to register extension when requiring deptrac-shim
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
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?
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.
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...
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?
With a custom compiler and configs like these: https://github.com/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.
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.
How about adding deptrac as an executable in the main repository's composer.json, and then recommending people use https://github.com/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://github.com/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 😉
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.