2
votes

I am developing a project using PhpStorm and I am using Php 7.1 with Docker. I would like to integrate PHP code sniffer in PhpStorm.

In PhpStorm I go to Settings|Languages&Frameworks|PHP|CodeSniffer and I try to add a new configuration, I provide as PHP Code Sniffer (phpcs) path the path of a script with the following content:

#!/usr/bin/env bash
docker run --rm -ti --volume "$(pwd):/app:rw" -u $(id -u):$(id -g) prooph/php:7.1-cli php vendor/bin/phpcs "$@"

which just runs phpcs in my docker container.

When I click on Validate, PhpStorm gives me the following message:

The input device is not a TTY

The same script works perfectly when it's run from PhpStorm console.

Am I doing something wrong? Or what I am trying to do is just not supported?

2

2 Answers

3
votes

You should run it without -t flag:

#!/usr/bin/env bash
docker run --rm -i --volume "$(pwd):/app:rw" -u $(id -u):$(id -g) prooph/php:7.1-cli php vendor/bin/phpcs "$@"

-t allocates a pseudo-TTY, that's why it works on PhpStorm console.

0
votes

In PhpStorm 2019 it works out of the box, without the need of a bash script wrapper.

First, you need to go to Project Settings > Languages & Frameworks > PHP. Click the button ... next to the field "CLI interpreter" and configure it to works with Docker, selecting your Image name.

Once you have configured the CLI interpreter, go to Project Settings > Languages & Frameworks > PHP > Quality Tools and click on the three dots (...) button next to PHP_CodeSniffer. Add new configuration that uses the CLI interpreter you just added and fill the CodeSniffer path (in my case this is "/opt/project/vendor/bin/phpcs").

VoilĂ !