phpro / grumphp

A PHP code-quality tool
MIT License
4.11k stars 429 forks source link

Add support for devenv #1089

Closed sneakyvv closed 1 year ago

sneakyvv commented 1 year ago
Q A
Branch master for features and deprecations
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Documented? no
Fixed tickets

This PR adds support for usage of GrumPHP when developing with a devenv environment.

Problem

Devenv basically allows to run different PHP versions per project (amongst other services), but unlike Docker the services run natively.

In my setup, devenv is running in a WSL2 environment (Ubuntu). Doing commits from within WSL2 is not a problem, because direnv is automatically hooking into each bash command so that the correct PHP version is used for example.

The problem is that my git client (Fork) is running in Windows itself (and is proxying its git commands to WSL2 via wslgit). Therefore when the pre-commit hook is running its PHP command, the devenv shell is not loaded, so it's using the wrong PHP version, resulting in Psalm errors (but there might be others of course due to the wrong environment being used).

Solution

Alter the pre-commit hook install script so that the GrumPHP command is running inside the devenv shell


PS: I also wondered if the commit-msg hook should also be adapted, but since that's only using git afaics it's not necessary.

veewee commented 1 year ago

Hello,

Thanks for the pr. I'm wondering why you can't just configure the command to run through devenv by configuring EXEC_GRUMPHP_COMMAND? Similar to configuring docker and other tools: https://github.com/phpro/grumphp/blob/master/doc/parameters.md

sneakyvv commented 1 year ago

Thanks for the pointer. That will probably work! I'll test it asap.

sneakyvv commented 1 year ago

For anyone looking, this worked:

  git_hook_variables:
    EXEC_GRUMPHP_COMMAND: $HOME/.nix-profile/bin/devenv shell