Extensions cannot be included, in a portable way, when using global install
jwmwalrus opened this issue · 3 comments
Hi.
I'm trying to setup phpstan-shim with the doctrine and symfony extensions. My global composer.json file is:
{
"require": {
"asm89/twig-lint": "@stable",
"squizlabs/php_codesniffer": "~3.4",
"dealerdirect/phpcodesniffer-composer-installer": "~0.5",
"sirbrillig/phpcs-variable-analysis": "~2.4",
"slevomat/coding-standard": "~4.8",
"phpstan/phpstan-shim": "~0.11",
"phpstan/phpstan-symfony": "~0.11",
"phpstan/phpstan-doctrine": "~0.11",
"phploc/phploc": "~4.0"
}
}In the (Symfony 4) project, my phpstan.neon file looks like this:
includes:
- vendor/phpstan/phpstan-symfony/extension.neon
- vendor/phpstan/phpstan-doctrine/extension.neon
parameters:
autoload_files:
- %currentWorkingDirectory%/vendor/autoload.php
symfony:
container_xml_path: %currentWorkingDirectory%/var/cache/dev/srcApp_KernelDevDebugContainer.xml
level: 2
paths:
- srcWhen I try to run phpstan, it complains that it cannot find /path/to/my/project/vendor/phpstan/phpstan-symfony/extension.neon. Using %rootDir% in the includes: section doesn't work ---i.e., it doesn't expand to the actual path.
The only thing that seems to work is using an absolute path (e.g., /home/myuser/.config/composer/vendor/phpstan/phpstan-symfony/extension.neon, which is not portable).
Once using the absolute path for the extensions, I get namespace-related errors. ---and using %rootDir% for the global autoload.php doesn't work because there's a phar: prefix.
Any ideas on how to solve the issues? Any workarounds?
Hi,
two options come to my mind:
-
Install phpstan-shim and extensions in
require-devin the project's composer.json. That way you and your colleagues, and your CI server will all have the same, repeatable and deterministic build. Combining globally installed tool with local project's config files seems really like a peculiar choice to me. -
If 1) doesn't fly for you, you can go around this by running PHPStan from your global install path, like
/home/myuser/.config/composer. -
Another option would be to play with multiple config files that you include manually, that way you might be able to have an OS-level PHPStan config file that's always included in project's config files, using the
includes:section, and that might somehow help you?
Combining globally installed tool with local project's config files is not a peculiar choice when you consider invoking phpstan from a text editor or IDE, which expects the command to be in a $PATH directory ---but I agree with you in that a relative path works better with the CI server.
I guess I'll try option 1 for now.
¿Have you considered adding %home% or %currentUserHome% to the list of configuration variables?
%rootDir% is now the same for phpstan-shim and phpstan.