diff --git a/inc/lib.improve.action.phpstan.php b/inc/lib.improve.action.phpstan.php index 5b14193..2dddb30 100644 --- a/inc/lib.improve.action.phpstan.php +++ b/inc/lib.improve.action.phpstan.php @@ -36,7 +36,8 @@ class ImproveActionPhpstan extends ImproveAction if (!empty($_POST['save'])) { $this->setSettings([ 'phpexe_path' => (!empty($_POST['phpexe_path']) ? $_POST['phpexe_path'] : ''), - 'run_level' => (integer) $_POST['run_level'] + 'run_level' => (integer) $_POST['run_level'], + 'ignored_vars' => (!empty($_POST['ignored_vars']) ? $_POST['ignored_vars'] : '') ]); $this->redirect($url); } @@ -51,6 +52,14 @@ class ImproveActionPhpstan extends ImproveAction ' C:\path_to\php
' . '' . form::number('run_level', ['min' => 0, 'max' => 9, 'default' => (integer) $this->getSetting('run_level')]) . '
' . + '' . + '
' . + '' . sprintf(
+ __('If you have errors like "%s", you can add this var here. Use ; as separator and do not put $ ahead.'),
+ 'Variable $var might not be defined'
+ ) . ' ' . __('For exemple: var;_othervar;avar') . '
' . __('Some variables like core, _menu, are already set in ignored list.') . '
' . __('You must enable improve details to view analyse results !') . '
'; } @@ -93,17 +102,17 @@ class ImproveActionPhpstan extends ImproveAction } } - private function getPhpPath() + private function getPhpPath(): string { $phpexe_path = $this->getSetting('phpexe_path'); if (empty($phpexe_path) && !empty(PHP_BINDIR)) { $phpexe_path = PHP_BINDIR; } - return path::real($phpexe_path); + return (string) path::real($phpexe_path); } - private function writeConf() + private function writeConf(): bool { $content = "parameters:\n" . @@ -117,15 +126,24 @@ class ImproveActionPhpstan extends ImproveAction " excludePaths:\n" . " - " . $this->module['sroot'] . "/*/libs/*\n\n" . " bootstrapFiles:\n" . - " - " . dirname(__FILE__) . "/libs/dc.phpstan.bootstrap.php\n\n" . - " fileExtensions:\n" . - " - php\n" . - " - in\n\n" . - // extra - " checkMissingIterableValueType: false\n" . - " checkGenericClassInNonGenericObjectType: false\n"; + " - " . dirname(__FILE__) . "/libs/dc.phpstan.bootstrap.php\n\n"; - return file_put_contents(DC_VAR . '/phpstan.neon', $content); + // common + $content .= file_get_contents(dirname(__FILE__) . "/libs/dc.phpstan.neon.conf"); + $ignored = explode(';', $this->getSetting('ignored_vars')); + foreach($ignored as $var) { + $var = trim($var); + if (empty($var)) { + continue; + } + + $content .= + ' # $' . $var .' variable may not be defined (globally)' . "\n" . + ' - message: \'#Variable \$' . $var . ' might not be defined#\'' . "\n" . + ' path: *' . "\n\n"; + } + + return (boolean) file_put_contents(DC_VAR . '/phpstan.neon', $content); } } diff --git a/inc/libs/dc.phpstan.neon.conf b/inc/libs/dc.phpstan.neon.conf new file mode 100644 index 0000000..24e30e6 --- /dev/null +++ b/inc/libs/dc.phpstan.neon.conf @@ -0,0 +1,99 @@ + fileExtensions: + - php + - in + + checkMissingIterableValueType: false + checkGenericClassInNonGenericObjectType: false + + ignoreErrors: + + # $core variable may not be defined (globally) + - message: '#Variable \$core might not be defined#' + path: * + + # $_lang variable may not be defined (globally) + - message: '#Variable \$_lang might not be defined#' + path: * + + # $p_url variable may not be defined (plugins) + - message: '#Variable \$p_url might not be defined#' + path: *.php + + # $__widgets variable not may be defined (plugins) + - message: '#Variable \$__widgets might not be defined#' + path: *.php + + # $__default_widgets variable may not be defined (plugins) + - message: '#Variable \$__default_widgets might not be defined#' + path: *.php + + # $this variable may not be defined (plugins/themes) + - message: '#Variable \$this might not be defined#' + paths: + - */_define.php + - */_install.php + - */_uninstall.php + + # $_menu variable may not be defined (plugins/themes) + - message: '#Variable \$_menu might not be defined#' + path: */_admin.php + + # record object and auto properties + - message: '#Access to an undefined property record::#' + path: * + + # dcWidgets object and auto properties + - message: '#Access to an undefined property dcWidgets::#' + path: * + + # xmlTag object and auto properties + - message : '#Access to an undefined property xmlTag::#' + path: * + + # xmlTag object methods + - message : '#Call to an undefined method xmlTag::#' + path: * + + # dcSettings object and auto properties + - message : '#Access to an undefined property dcSettings::#' + path: * + + # dcPrefs object and auto properties + - message : '#Access to an undefined property dcPrefs::#' + path: * + + # dbStruct object and auto properties + - message : '#Access to an undefined property dbStruct::#' + path: * + + # fileItem object and auto properties + - message : '#Access to an undefined property fileItem::#' + path: * + + # cursor object and auto properties + - message : '#Access to an undefined property cursor::#' + path: * + + # static record extensions + - message: '#Call to an undefined method record::#' + path: * + + # Intensive use of magic __set/__get/__call/__invoke causes theses wrong warnings + - message: '#Call to an undefined method form[a-zA-Z0-9\\_]+::#' + path: * + + # Intensive use of magic __set/__get/__call/__invoke causes theses wrong warnings + - message: '#Access to an undefined property form[a-zA-Z0-9\\_]+::#' + path: * + + # form<*>filters + - message: '#Access to an undefined property admin[a-zA-Z0-9\\_]+Filter::\$[a-zA-Z0-9\\_]+.#' + path: * + + # dcAdminfilters + - message: '#Access to an undefined property dcAdminFilter::\$[a-zA-Z0-9\\_]+.#' + path: * + + # adminMediaPage + - message: '#Access to an undefined property adminMediaPage::\$[a-zA-Z0-9\\_]+.#' + path: *