add config to phpstan module
parent
9a90725d1a
commit
37055e36cf
|
@ -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</p>' .
|
||||
'<p><label class="classic" for="run_level">' . __('Level:') . ' </label>' .
|
||||
form::number('run_level', ['min' => 0, 'max' => 9, 'default' => (integer) $this->getSetting('run_level')]) . '</p>' .
|
||||
'<p><label class="classic" for="ignored_vars">' .
|
||||
__('List of ignored variables:') . '<br />' .
|
||||
form::field('ignored_vars', 160, 255, $this->getSetting('ignored_vars')) . '</label>' .
|
||||
'</p>' .
|
||||
'<p class="form-note">' . 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') . '<br />' . __('Some variables like core, _menu, are already set in ignored list.') . '</p>' .
|
||||
'<p class="info">' . __('You must enable improve details to view analyse results !') . '</p>';
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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: *
|
Loading…
Reference in New Issue