File tree Expand file tree Collapse file tree 3 files changed +32
-4
lines changed Expand file tree Collapse file tree 3 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,18 @@ Using [vim-plug](https://github.com/junegunn/vim-plug):
2626
2727You 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
Original file line number Diff line number Diff line change 11function ! 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'
1417endfun
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
Original file line number Diff line number Diff line change @@ -2,8 +2,7 @@ if exists('g:phpstan_plugin_loaded') || &cp
22 finish
33endif
44let 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
87if ! exists (' g:phpstan_analyse_level' )
98 let g: phpstan_analyse_level = 2
You can’t perform that action at this time.
0 commit comments