├── vim-phpstan-qf.png ├── plugin ├── phpstan.vim └── phpstan_filter ├── autoload └── phpstan.vim ├── LICENSE └── README.md /vim-phpstan-qf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phpstan/vim-phpstan/HEAD/vim-phpstan-qf.png -------------------------------------------------------------------------------- /plugin/phpstan.vim: -------------------------------------------------------------------------------- 1 | if exists('g:phpstan_plugin_loaded') || &cp 2 | finish 3 | endif 4 | let g:phpstan_plugin_loaded = 1 5 | 6 | let g:phpstan_plugin_path = expand(':p:h') 7 | 8 | if !exists('g:phpstan_analyse_level') 9 | let g:phpstan_analyse_level = 2 10 | endif 11 | 12 | " A command to call 13 | command! -nargs=+ PHPStanAnalyse call phpstan#PHPStanAnalyse() 14 | -------------------------------------------------------------------------------- /autoload/phpstan.vim: -------------------------------------------------------------------------------- 1 | function! phpstan#PHPStanAnalyse(...) 2 | let paths = join(a:000, '\ ') 3 | exe "setlocal makeprg=phpstan\\ analyse\\ --no-progress\\ -l" . g:phpstan_analyse_level . "\\ " . paths 4 | " File: path/to/file.php, line: 12, error: error message 5 | setlocal efm=File%.\ %f%.\ line%.\ %l%.\ error%.\ %m 6 | setlocal efm+=%-G " Ignore empty lines 7 | 8 | exe "silent make\ \\\|&\ " . g:phpstan_plugin_path . "/phpstan_filter" 9 | exe "cwindow" 10 | endfun 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Robert Basic 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-phpstan 2 | 3 | A Vim plugin for [PHPStan](https://github.com/phpstan/phpstan). It calls `phpstan` to do static analysis of your PHP code and displays the errors in Vim's quickfix list. 4 | 5 | See `:help quickfix` for more on how to use the quickfix. 6 | 7 | # Usage 8 | 9 | Call the `PHPStanAnalyse` command and pass the directories you want analysed as arguments: 10 | 11 | ``` vim 12 | :PHPStanAnalyse src test 13 | ``` 14 | 15 | And the quickfix list will be populated with something like this: 16 | 17 | ![vim phpstan quickfix screenshot](https://github.com/phpstan/vim-phpstan/blob/master/vim-phpstan-qf.png) 18 | 19 | # Installation 20 | 21 | Using [vim-plug](https://github.com/junegunn/vim-plug): 22 | 23 | `Plug 'phpstan/vim-phpstan'` 24 | 25 | # Configuration 26 | 27 | You can configure the level PHPStan uses. By default the level is 2. 28 | 29 | `let g:phpstan_analyse_level = 4` in your `.vimrc` file to change the level to fit your needs. 30 | 31 | # Assumptions 32 | 33 | This plugin assumes that the `phpstan` executable is available in the `$PATH`. 34 | 35 | # Authors 36 | 37 | | Authors | | 38 | |------------------|--------------------------------| 39 | | Robert Basic | https://github.com/robertbasic | 40 | -------------------------------------------------------------------------------- /plugin/phpstan_filter: -------------------------------------------------------------------------------- 1 | #! /usr/bin/php 2 | 3 | 0) { 59 | $output .= "File: " . $currentFile . ", line: " . $lineNumber . ", error: " . implode(' ', $errorMessages) . PHP_EOL; 60 | $errorMessages = []; 61 | } 62 | } 63 | 64 | echo trim($output); 65 | --------------------------------------------------------------------------------