Skip to content

Commit 979a961

Browse files
committed
Configure phpstan paths
1 parent e7f9338 commit 979a961

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,18 @@ Using [vim-plug](https://github.com/junegunn/vim-plug):
2626

2727
You can configure the level PHPStan uses. By default the level is 2.
2828

29-
`let g:phpstan_analyse_level = 4` in your `.vimrc` file to change the level to fit your needs.
29+
```
30+
let g:phpstan_analyse_level = 4
31+
```
32+
33+
By default the plugin will look for PHPStan in `./vendor/bin/phpstan`, then
34+
`./bin/phpstan` and fallback to the global `phpstan` global executable if it exists.
35+
36+
You can override the path with
37+
38+
```
39+
let g:phpstan_path = '/path//to/phpstan'
40+
```
3041

3142
# Assumptions
3243

autoload/phpstan.vim

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
function! phpstan#PHPStanAnalyse(...)
22
let paths = join(a:000, '\ ')
3-
let cmd = './vendor/bin/phpstan analyse --errorFormat=raw --no-progress -l' . g:phpstan_analyse_level . ' ' . paths
3+
4+
let phpstan_path = phpstan#_resolvePhpstanPath()
5+
6+
let cmd = phpstan_path . ' analyse --errorFormat=raw --no-progress -l' . g:phpstan_analyse_level . ' ' . paths
47
let result = system(cmd)
58

69
let list = []
@@ -12,3 +15,18 @@ function! phpstan#PHPStanAnalyse(...)
1215
call setqflist(list)
1316
execute ':cwindow'
1417
endfun
18+
19+
function! phpstan#_resolvePhpstanPath()
20+
echo g:phpstan_paths
21+
for phpstan_path in g:phpstan_paths
22+
if filereadable(phpstan_path)
23+
return phpstan_path
24+
endif
25+
endfor
26+
27+
if !executable('phpstan')
28+
throw 'PHPStan doesn't seem to be globally installed or detected locally'
29+
endif
30+
31+
return 'phpstan'
32+
endfun

plugin/phpstan.vim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ if exists('g:phpstan_plugin_loaded') || &cp
22
finish
33
endif
44
let g:phpstan_plugin_loaded = 1
5-
6-
let g:phpstan_plugin_path = expand('<sfile>:p:h')
5+
let phpstan_paths = [ './vendor/bin/phpstan', './bin/phpstan' ]
76

87
if !exists('g:phpstan_analyse_level')
98
let g:phpstan_analyse_level = 2

0 commit comments

Comments
 (0)