From e0ec1a33180b404f11c30c51d9c10338afdbb347 Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Wed, 7 Dec 2011 14:00:53 +0000 Subject: [PATCH] refactor the php checker * move the phpcs code into its own function * just use g:syntastic_phpcs_conf instead of initing a local var every time the checker is invoked --- syntax_checkers/php.vim | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/syntax_checkers/php.vim b/syntax_checkers/php.vim index 6cf5e689..68c0f116 100644 --- a/syntax_checkers/php.vim +++ b/syntax_checkers/php.vim @@ -19,6 +19,11 @@ if !executable("php") finish endif +"Support passing configuration directives to phpcs +if !exists("g:syntastic_phpcs_conf") + let g:syntastic_phpcs_conf = "" +endif + function! SyntaxCheckers_php_Term(item) let unexpected = matchstr(a:item['text'], "unexpected '[^']\\+'") if len(unexpected) < 1 | return '' | end @@ -29,18 +34,7 @@ function! SyntaxCheckers_php_GetLocList() let errors = [] if executable("phpcs") - " Support passing configuration directives to phpcs through - " g:syntastic_phpcs_conf. This matches the method in the javascript.vim - " setup. - if !exists("g:syntastic_phpcs_conf") || empty(g:syntastic_phpcs_conf) - let phpcsconf = "" - else - let phpcsconf = g:syntastic_phpcs_conf - endif - let makeprg = "phpcs " . phpcsconf . " --report=csv ".shellescape(expand('%')) - let g:mpb_makeprg = makeprg - let errorformat = '"%f"\,%l\,%c\,%t%*[a-zA-Z]\,"%m"\,%*[a-zA-Z0-9_.-]\,%*[0-9]' - let errors = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) + let errors = s:GetPHPCSErrors() endif let makeprg = "php -l ".shellescape(expand('%')) @@ -51,3 +45,9 @@ function! SyntaxCheckers_php_GetLocList() return errors endfunction + +function! s:GetPHPCSErrors() + let makeprg = "phpcs " . g:syntastic_phpcs_conf . " --report=csv ".shellescape(expand('%')) + let errorformat = '"%f"\,%l\,%c\,%t%*[a-zA-Z]\,"%m"\,%*[a-zA-Z0-9_.-]\,%*[0-9]' + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) +endfunction