coala / coala-bears

Bears for coala
https://coala.io/
GNU Affero General Public License v3.0
295 stars 580 forks source link

Integrate phpstan #1426

Open SanketDG opened 7 years ago

SanketDG commented 7 years ago

https://github.com/phpstan/phpstan

damngamerz commented 7 years ago

I would like to work on this bear proposal :smile:

damngamerz commented 7 years ago

Tested phpstan!! The linter is good. While converting it to bear I m having issues. As phpstan is being installed through composer. I Tried installing both composer and phpstan globally. php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "if (hash_file('SHA384', 'composer-setup.php') === '55d6ead61b29c7bdee5cccfb50076874187bd9f21f65d8991d46ec5cc90518f447387fb9f76ebae1fbbacf329e583e30') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php php -r "unlink('composer-setup.php');" mv composer.phar /usr/local/bin/composer composer global require phpstan/phpstan added phpstan to $PATH As suggested by @SanketDG to checkout which phpstan on CLI It doesnt show any path wheareas whereis phpstan shows the package. Because of this issue Im unable to run this bear. Attaching Screenshots for reference screenshot from 2017-02-17 18-25-27

Makman2 commented 7 years ago

whereis is different from which, as it tries to find the given binary not only in the PATH. Though still it's weird that which can't find it. Do you use maybe the docker alias? That's why which may not find it^^

EDIT: Shouldn't be the problem, which then displays that it's an alias...

Makman2 commented 7 years ago

On the docker image of phpstan I've a valid path:

 mak  ~  docker run -i --entrypoint sh phpstan/phpstan:0.6 
which phpstan
/composer/vendor/bin/phpstan
damngamerz commented 7 years ago

@Makman2 by following those above commands even i have valid path.But its strange i have added this alias to ~/.bashrc alias phpstan='docker run -v $PWD:/app --rm phpstan/phpstan:0.6' still its not having valid path while invoking which in my CLI.Any thoughts ?

Makman2 commented 7 years ago

This is what I get:

 mak  ~  which phpstan
alias phpstan='docker run -v $PWD:/app --rm phpstan/phpstan:0.6'
    /usr/bin/docker

What shell do you use? maybe your shell does not display aliases with which^^

damngamerz commented 7 years ago

@Makman2 Im using bash which is default shell for ubuntu.My setup is Ubuntu 16.04 LTS.Any Thoughts?Im stuck at this point.Cant go any further if the bear doesnt detect phpstan installation.

Makman2 commented 7 years ago

Try to write the bear using executable=phpstan, and let's see how we get it to work and how we can install phpstan on CI. I'll try it then too on my machine :+1:

damngamerz commented 7 years ago

@Makman2 I have already written it! But im unable to test it cause coala is not able to detect the installation of phpstan.Here http://pastebin.com/eiqZJA5N now while running

coala --bear-dirs=. --bears=PhpstanBear --files=hello.php --flush-cache

gives

[ERROR][03:43:52] The bear PhpstanBear does not fulfill all requirements. 'phpstan' is not installed.
Makman2 commented 7 years ago

ah wait I know... you can't use .bashrc as this is the bash shell environment, not your system environment! :D @linter directly executes a program without shell, so it relies on the system defaults and paths. Maybe this link helps: http://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path

damngamerz commented 7 years ago

@Makman2 Worked like a magic!! your magic is strong :wink: which doesn't takes care of ~/while in PATH.whereas bash takes care of it while invoking for running a program. so added export PATH="$HOME/.config/composer/vendor/bin/:$PATH" to ~/.bashrc file now

which phpstan
/home/damngamerz/.config/composer/vendor/bin//phpstan

and my linter works perfectly.yay! screenshot from 2017-02-28 01-52-50 Thanks!! I will make a PR soon :+1: