Configuring VIM ALE plugin with PHPSTAN
I am using ALE for my PHP developing.
There is possibility to use phpstan as one of linters, but no matter what I do there is notification that phpstan cannot load class / method definitions:
Function foo not found while trying to analyse it - autoloading is probably not configured properly.
Default configuration of ALE unfortunately does not help, because it expects phpstan to be in $PATH, and even if it is there it still complains about missing autoloading.
php vim vim-plugin phpstan
add a comment |
I am using ALE for my PHP developing.
There is possibility to use phpstan as one of linters, but no matter what I do there is notification that phpstan cannot load class / method definitions:
Function foo not found while trying to analyse it - autoloading is probably not configured properly.
Default configuration of ALE unfortunately does not help, because it expects phpstan to be in $PATH, and even if it is there it still complains about missing autoloading.
php vim vim-plugin phpstan
add a comment |
I am using ALE for my PHP developing.
There is possibility to use phpstan as one of linters, but no matter what I do there is notification that phpstan cannot load class / method definitions:
Function foo not found while trying to analyse it - autoloading is probably not configured properly.
Default configuration of ALE unfortunately does not help, because it expects phpstan to be in $PATH, and even if it is there it still complains about missing autoloading.
php vim vim-plugin phpstan
I am using ALE for my PHP developing.
There is possibility to use phpstan as one of linters, but no matter what I do there is notification that phpstan cannot load class / method definitions:
Function foo not found while trying to analyse it - autoloading is probably not configured properly.
Default configuration of ALE unfortunately does not help, because it expects phpstan to be in $PATH, and even if it is there it still complains about missing autoloading.
php vim vim-plugin phpstan
php vim vim-plugin phpstan
asked Nov 15 '18 at 20:31
DevilaNDevilaN
698415
698415
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
This solution is git and composer specific.
I have not found good solution without either any vcs or composer.
So first of all we assume that there is composer being used in project, so there is autoload.php file generated. If you are not using this feature you probably should, because it maps classes to files and makes autoloading simple.
Unfortunately using global phpstan binary is futile. This is because of phpstan looks in current directory for autoload or neon config file that tells it where to look for class definitions. So if you don't want to be forced to open each file in project from root project's directory, then there should be another solution.
Using phpstan binary installed by composer in your project (in vendor/bin/phpstan) solves this problem. Local binary is using the same autoload.php and correctly finds each class definition. So we need to tell ale where phpstan binary is.
Inserting in vimrc file (or better in .vim/ftplugin/php.vim) following line:
let g:ale_php_phpstan_executable = system('if ! type git &> /dev/null; then echo phpstan; else PSE=`git rev-parse --show-toplevel 2> /dev/null`/vendor/bin/phpstan; if [ -x "$PSE" ]; then echo -n $PSE; else echo phpstan; fi; fi')
It tells ALE path to phpstan executable, which is determined by running shell comand.
if ! type git part checks if there is git command in system. If not, then default phpstan text is being returned to variable.
git rev-parse --show-toplevel is trying to find out whether we are in git repository and what is it's top level directory. When found correctly, it determines path to phpstan by adding /vendor/bin/phpstan to top level directory. This is where locally installed phpstan should reside.
If there is no such file or it is not executable, then default phpstan variable value is being returned.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327471%2fconfiguring-vim-ale-plugin-with-phpstan%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This solution is git and composer specific.
I have not found good solution without either any vcs or composer.
So first of all we assume that there is composer being used in project, so there is autoload.php file generated. If you are not using this feature you probably should, because it maps classes to files and makes autoloading simple.
Unfortunately using global phpstan binary is futile. This is because of phpstan looks in current directory for autoload or neon config file that tells it where to look for class definitions. So if you don't want to be forced to open each file in project from root project's directory, then there should be another solution.
Using phpstan binary installed by composer in your project (in vendor/bin/phpstan) solves this problem. Local binary is using the same autoload.php and correctly finds each class definition. So we need to tell ale where phpstan binary is.
Inserting in vimrc file (or better in .vim/ftplugin/php.vim) following line:
let g:ale_php_phpstan_executable = system('if ! type git &> /dev/null; then echo phpstan; else PSE=`git rev-parse --show-toplevel 2> /dev/null`/vendor/bin/phpstan; if [ -x "$PSE" ]; then echo -n $PSE; else echo phpstan; fi; fi')
It tells ALE path to phpstan executable, which is determined by running shell comand.
if ! type git part checks if there is git command in system. If not, then default phpstan text is being returned to variable.
git rev-parse --show-toplevel is trying to find out whether we are in git repository and what is it's top level directory. When found correctly, it determines path to phpstan by adding /vendor/bin/phpstan to top level directory. This is where locally installed phpstan should reside.
If there is no such file or it is not executable, then default phpstan variable value is being returned.
add a comment |
This solution is git and composer specific.
I have not found good solution without either any vcs or composer.
So first of all we assume that there is composer being used in project, so there is autoload.php file generated. If you are not using this feature you probably should, because it maps classes to files and makes autoloading simple.
Unfortunately using global phpstan binary is futile. This is because of phpstan looks in current directory for autoload or neon config file that tells it where to look for class definitions. So if you don't want to be forced to open each file in project from root project's directory, then there should be another solution.
Using phpstan binary installed by composer in your project (in vendor/bin/phpstan) solves this problem. Local binary is using the same autoload.php and correctly finds each class definition. So we need to tell ale where phpstan binary is.
Inserting in vimrc file (or better in .vim/ftplugin/php.vim) following line:
let g:ale_php_phpstan_executable = system('if ! type git &> /dev/null; then echo phpstan; else PSE=`git rev-parse --show-toplevel 2> /dev/null`/vendor/bin/phpstan; if [ -x "$PSE" ]; then echo -n $PSE; else echo phpstan; fi; fi')
It tells ALE path to phpstan executable, which is determined by running shell comand.
if ! type git part checks if there is git command in system. If not, then default phpstan text is being returned to variable.
git rev-parse --show-toplevel is trying to find out whether we are in git repository and what is it's top level directory. When found correctly, it determines path to phpstan by adding /vendor/bin/phpstan to top level directory. This is where locally installed phpstan should reside.
If there is no such file or it is not executable, then default phpstan variable value is being returned.
add a comment |
This solution is git and composer specific.
I have not found good solution without either any vcs or composer.
So first of all we assume that there is composer being used in project, so there is autoload.php file generated. If you are not using this feature you probably should, because it maps classes to files and makes autoloading simple.
Unfortunately using global phpstan binary is futile. This is because of phpstan looks in current directory for autoload or neon config file that tells it where to look for class definitions. So if you don't want to be forced to open each file in project from root project's directory, then there should be another solution.
Using phpstan binary installed by composer in your project (in vendor/bin/phpstan) solves this problem. Local binary is using the same autoload.php and correctly finds each class definition. So we need to tell ale where phpstan binary is.
Inserting in vimrc file (or better in .vim/ftplugin/php.vim) following line:
let g:ale_php_phpstan_executable = system('if ! type git &> /dev/null; then echo phpstan; else PSE=`git rev-parse --show-toplevel 2> /dev/null`/vendor/bin/phpstan; if [ -x "$PSE" ]; then echo -n $PSE; else echo phpstan; fi; fi')
It tells ALE path to phpstan executable, which is determined by running shell comand.
if ! type git part checks if there is git command in system. If not, then default phpstan text is being returned to variable.
git rev-parse --show-toplevel is trying to find out whether we are in git repository and what is it's top level directory. When found correctly, it determines path to phpstan by adding /vendor/bin/phpstan to top level directory. This is where locally installed phpstan should reside.
If there is no such file or it is not executable, then default phpstan variable value is being returned.
This solution is git and composer specific.
I have not found good solution without either any vcs or composer.
So first of all we assume that there is composer being used in project, so there is autoload.php file generated. If you are not using this feature you probably should, because it maps classes to files and makes autoloading simple.
Unfortunately using global phpstan binary is futile. This is because of phpstan looks in current directory for autoload or neon config file that tells it where to look for class definitions. So if you don't want to be forced to open each file in project from root project's directory, then there should be another solution.
Using phpstan binary installed by composer in your project (in vendor/bin/phpstan) solves this problem. Local binary is using the same autoload.php and correctly finds each class definition. So we need to tell ale where phpstan binary is.
Inserting in vimrc file (or better in .vim/ftplugin/php.vim) following line:
let g:ale_php_phpstan_executable = system('if ! type git &> /dev/null; then echo phpstan; else PSE=`git rev-parse --show-toplevel 2> /dev/null`/vendor/bin/phpstan; if [ -x "$PSE" ]; then echo -n $PSE; else echo phpstan; fi; fi')
It tells ALE path to phpstan executable, which is determined by running shell comand.
if ! type git part checks if there is git command in system. If not, then default phpstan text is being returned to variable.
git rev-parse --show-toplevel is trying to find out whether we are in git repository and what is it's top level directory. When found correctly, it determines path to phpstan by adding /vendor/bin/phpstan to top level directory. This is where locally installed phpstan should reside.
If there is no such file or it is not executable, then default phpstan variable value is being returned.
answered Nov 15 '18 at 20:31
DevilaNDevilaN
698415
698415
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327471%2fconfiguring-vim-ale-plugin-with-phpstan%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown