phpcs: Could not open input file

When I open my project, I get a toast message about PHP_CodeSniffer not being able to find input file. I'm unable to figure out the exact settings I need to use.

My project root has a phpcs.xml file with our coding standard, that's consumed by some GitLab pipeline. The application runs inside a Docker container and all the code is in a volume. Potentially, I have three ways to run phpcs:

  1. Preferred option would be a dedicated phpcs container. In a terminal, I can do this just fine:
    docker run -it -v "$(pwd)":/code phpcs --report=full
  2. I also have a local PHP interpreter in host machine (Kubuntu) with a global PHP_CodeSniffer installation. In a terminal:
    phpcs --report=full
  3. And PHP_CodeSniffer is also available inside the application container, as DEV dependency for some third-party package, although we'll probably remove it at some point:
    docker exec -it app-container-name vendor/bin/phpcs --report=full
    Edit: this one doesn't actually work, it targets an invalid PHP version.

I'm lost in PHP_CodeSniffer settings dialogue. There's a side pane with three interpreters (two of them come from the CLI Interpreters section, where I've defined my app container and my local binary; the other one is called "System PHP" and I don't know where it comes from), I've been trying several combinations and I never make it work. I can't even understand how to let PhpStorm know which of the interpreters to use.

1 comment

I think I fixed it!

First I did some PHP interpreter cleanup at Settings/ PHP (remove a duplicate one and give them betters names), and I added a new one for the Docker image where PHP_CodeSniffer is installed (after all, that container has PHP available too for obvious reasons). Then I went to Settings/ PHP/ Quality tools, I removed all the configurations and I created a new item using the new PHP interpreter. I had to enter the full path for all commands* but, once done that, it finally passed validation and PhpStorm is reporting style violations now.


docker run -it -v "$(pwd)":/code  which phpcs
docker run -it -v "$(pwd)":/code  which phpcbf




Please sign in to leave a comment.