Closed shaneparsons closed 2 years ago
You should be able to get this working using the phpstan.paths
option indeed. So if your local path is ./vendor/phpstan/phpstan-strict-rules/rules.neon
and the remote path is /var/www/html/vendor/phpstan/phpstan-strict-rules/rules.neon
, you should be able to get it working by setting the settings to:
{
"phpstan.configFile" :"./vendor/phpstan/phpstan-strict-rules/rules.neon",
"phpstan.paths": { "./": "/var/www/html/"
}
Not sure if that's the exact config, the paths might need to be absolute but I'm not sure about that. With some fumbling around you should be able to get it to work with the paths option.
I actually tried a few different variations of that in between opening the ticket and your response (and again now)
"phpstan.configFile": "./vendor/phpstan/phpstan-strict-rules/rules.neon",
"phpstan.binCommand": ["php-dme", "vendor/bin/phpstan"],
"phpstan.paths": { "./": "/var/www/html/" },
It seems like starting phpstan.configFile
with anything other than /
always translates to the default ${workspaceFolder}
(i.e. /home/sparsons/repo/dme
)... Is there anything else I can try here?
Is that not correct then? Anything path not starting with a /
indicates a relative path (relative to the workspace folder). Where is the neon file supposed to be? Is it at /vendor/phpstan/phpstan-strict-rules/rules.neon
(so at this abolute path) or is it at ./vendor/phpstan/phpstan-strict-rules/rules.neon
(relative to the project folder)
Looks like I was able to get past that part by changing it to
"phpstan.paths": { "/home/sparsons/repo/dme": "/var/www/html/" },
But now I'm getting the following:
PHPStan process exited successfully but with error message, error= This file is included multiple times:
- /var/www/html/vendor/phpstan/phpstan-strict-rules/rules.neon
It can lead to unexpected results. If you're using phpstan/extension-installer, make sure you have removed corresponding neon files from your project config file.
In my case I am using phpstan/extension-installer
, which is what's attaching the config to the phpstan
call automatically. I'm thinking the only way around this would be for this plugin to accept a null value for phpstan.configFile
thereby skipping the adding of that to the command.
Technically I guess this issue can be renamed "Add support for phpstan/extension-installer
configs"...
Does this make sense / is this something doable? I'm not sure how the plugin logic has been constructed.
To clarify my config setup, I'm using phpstan/phpstan-strict-rules
for the config, which is using phpstan/extension-installer
to automatically apply that config. You can read more about it here.
EDIT: I also just tried using phpstan/phpstan-strict-rules
manually, without phpstan/extension-installer
, which leads to the following:
PHPStan process exited successfully but with error message, error=
No rules detected
You have the following choices:
* while running the analyse option, use the --level option to adjust your rule level - the higher the stricter
* create your own custom ruleset by selecting which rules you want to check by copying the service definitions from the built-in config level files in phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/conf.
* in this case, don't forget to define parameter customRulesetUsed in your config file.
Still debugging this part.
Hmm that wouldn't be too hard to do. Can you try out this demo build? I've removed the -c
arg completely here. Let me know if this works. If it does, it's a pretty easy step to just have the neon file be nullable.
I can't upload .vsix
files because github doesn't allow them. Instead I uploaded a zip file. Just rename it to .vsix and install it like normal.
phpstan-vscode-1.3.2.zip
Alright, I got the "manual" / phpstan/phpstan-strict-rules
part figured out and it's now working! Had to make the following change to my phpstan.neon
:
parameters:
customRulesetUsed: true
includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
So the only thing left here is whether or not you wanted to add support for phpstan/extension-installer
, which the removal of the -c
arg should theoretically achieve. I'll test your build now.
Awesome, that worked! Still need to include a phpstan.neon
with:
parameters:
customRulesetUsed: true
But I think that's probably a limitation of phpstan
/ phpstan-strict-rules
/ extension-installer
rather than being specific to anything going on here.
Thanks for the quick work on this! Looking forward having this plugin used in my day to day workflow.
Ah good to hear. I'll add support for it since it's not too hard.
I'll re-open the issue and let you close it once you've implemented it.
Done :)
I have a similar-ish set up to https://github.com/SanderRonde/phpstan-vscode/issues/1 in that I'm using
phpstan
through docker:Setup details
```json "phpstan.binCommand": ["php-dme", "vendor/bin/phpstan"], ``` `php-dme` (i.e. `/usr/local/bin/php-dme`) is a command for: ``` path=$(printf '%s\n' "${PWD##*/}") command="docker-compose run --rm app "$@"" $command ``` And `dme-app` is my docker container running php.The problem I'm having is w/ the
phpstan.configFile
setting... My config file in this case is in/vendor/phpstan/phpstan-strict-rules/rules.neon
. I've tried different variations of that path (e.g.vendor
,/vendor
), but it always ends with the following error:I think the problem is my
phpstan.rootDir
, but I'm not sure what it should be in this case? This config file is accessible both locally and through the php container, so I'm not sure which path I should be using? My docker container is set up like so:More setup details
```yaml dme-app: build: context: ./ dockerfile: ./Dockerfile volumes: - ./:/var/www/html/ ``` So what's `/vendor/phpstan/phpstan-strict-rules/rules.neon` locally, is technically `/var/www/html/vendor/phpstan/phpstan-strict-rules/rules.neon` in the container. Running `php-dme ./vendor/bin/phpstan analyse src/` manually works as intended, and finds my config automatically because of `phpstan/extension-installer`.I guess the ultimate question is how can I get this to work? If the problem is because my setup is a unique one that hasn't been accounted for, is there any chance that maybe the
phpstan.configFile
can be ignored / fall back to grabbing it through the composer.json? Maybe I can use thephpstan.paths
option somehow? Maybe I'm just overlooking something else?Any help would be greatly appreciated.