add option to clear cache and to ignore some rules
This commit is contained in:
parent
40f4cc14ad
commit
62252a5ca2
3 changed files with 228 additions and 142 deletions
|
@ -105,14 +105,16 @@ class phpstan extends Action
|
|||
{
|
||||
if (!empty($_POST['save'])) {
|
||||
$this->setSettings([
|
||||
'phpexe_path' => (!empty($_POST['phpexe_path']) ? $_POST['phpexe_path'] : ''),
|
||||
'run_level' => (int) $_POST['run_level'],
|
||||
'ignored_vars' => (!empty($_POST['ignored_vars']) ? $_POST['ignored_vars'] : ''),
|
||||
'split_report' => !empty($_POST['split_report']),
|
||||
'phpexe_path' => (!empty($_POST['phpexe_path']) ? $_POST['phpexe_path'] : ''),
|
||||
'run_level' => (int) $_POST['run_level'],
|
||||
'ignored_vars' => (!empty($_POST['ignored_vars']) ? $_POST['ignored_vars'] : ''),
|
||||
'ignored_default' => !empty($_POST['ignored_default']),
|
||||
'split_report' => !empty($_POST['split_report']),
|
||||
'clear_cache' => !empty($_POST['clear_cache']),
|
||||
]);
|
||||
$this->redirect($url);
|
||||
}
|
||||
$content = (string) file_get_contents(__DIR__ . '/phpstan/phpstan.rules.conf');
|
||||
$content = (string) file_get_contents(__DIR__ . '/phpstan/phpstan.rules.full.conf');
|
||||
|
||||
return (new Div())->items([
|
||||
(new Note())->text(__('You must enable improve details to view analyse results !'))->class('form-note'),
|
||||
|
@ -139,12 +141,24 @@ class phpstan extends Action
|
|||
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.')
|
||||
)->class('form-note'),
|
||||
// ignored_default
|
||||
(new Para())->items([
|
||||
(new Checkbox('ignored_default', !empty($this->getSetting('ignored_default'))))->value(1),
|
||||
(new Label(__('Do not use rules from default ignored errors list.'), Label::OUTSIDE_LABEL_AFTER))->for('ignored_default')->class('classic'),
|
||||
]),
|
||||
(new Note())->text(__('See ignored errors from configuration file below.'))->class('form-note'),
|
||||
// split_report
|
||||
(new Para())->items([
|
||||
(new Checkbox('split_report', !empty($this->getSetting('split_report'))))->value(1),
|
||||
(new Label(__('Split report by file rather than all in the end.'), Label::OUTSIDE_LABEL_AFTER))->for('split_report')->class('classic'),
|
||||
]),
|
||||
(new Note())->text(__('Enable this can cause timeout.'))->class('form-note'),
|
||||
// clear_cache
|
||||
(new Para())->items([
|
||||
(new Checkbox('clear_cache', !empty($this->getSetting('clear_cache'))))->value(1),
|
||||
(new Label(__('Clear result cache before each analizes.'), Label::OUTSIDE_LABEL_AFTER))->for('clear_cache')->class('classic'),
|
||||
]),
|
||||
(new Note())->text(__('Enable this can cause timeout.'))->class('form-note'),
|
||||
]),
|
||||
(new Fieldset())->class('fieldset')->legend((new Legend(__('Bootstrap'))))->fields([
|
||||
// file_content
|
||||
|
@ -179,7 +193,9 @@ class phpstan extends Action
|
|||
return null;
|
||||
}
|
||||
|
||||
return $this->execFixer($this->path_full);
|
||||
$clear = $this->getSetting('clear_cache') ? $this->execClear($this->path_full) : true;
|
||||
|
||||
return $clear && $this->execFixer($this->path_full);
|
||||
}
|
||||
|
||||
public function closeModule(): ?bool
|
||||
|
@ -191,7 +207,22 @@ class phpstan extends Action
|
|||
return false;
|
||||
}
|
||||
|
||||
return $this->execFixer();
|
||||
$clear = $this->getSetting('clear_cache') ? $this->execClear() : true;
|
||||
|
||||
return $clear && $this->execFixer();
|
||||
}
|
||||
|
||||
private function execClear(string $path = null): bool
|
||||
{
|
||||
if (!empty($path)) {
|
||||
$path .= ' ';
|
||||
}
|
||||
|
||||
return $this->execCmd(sprintf(
|
||||
'%sphp %s/phpstan/libs/phpstan.phar clear-result-cache',
|
||||
$this->phpexe_path,
|
||||
__DIR__
|
||||
), true);
|
||||
}
|
||||
|
||||
private function execFixer(string $path = null): bool
|
||||
|
@ -200,13 +231,16 @@ class phpstan extends Action
|
|||
$path .= ' ';
|
||||
}
|
||||
|
||||
$command = sprintf(
|
||||
return $this->execCmd(sprintf(
|
||||
'%sphp %s/phpstan/libs/phpstan.phar analyse ' . $path . '--configuration=%s',
|
||||
$this->phpexe_path,
|
||||
__DIR__,
|
||||
DC_VAR . '/phpstan.neon'
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
private function execCmd(string $command, bool $from_clear = false): bool
|
||||
{
|
||||
try {
|
||||
exec($command, $output, $error);
|
||||
|
||||
|
@ -214,7 +248,7 @@ class phpstan extends Action
|
|||
throw new Exception('oops');
|
||||
}
|
||||
if (count($output) < 4) {
|
||||
$this->setSuccess(__('No errors found'));
|
||||
$this->setSuccess($from_clear ? __('Cache cleared') : __('No errors found'));
|
||||
} else {
|
||||
$this->setWarning(sprintf('<pre>%s</pre>', implode('<br />', $output)));
|
||||
}
|
||||
|
@ -248,6 +282,7 @@ class phpstan extends Action
|
|||
|
||||
private function writeConf(): bool
|
||||
{
|
||||
$full = $this->getSetting('ignored_default') ? '' : 'full.';
|
||||
$content = str_replace(
|
||||
[
|
||||
'%LEVEL%',
|
||||
|
@ -257,11 +292,11 @@ class phpstan extends Action
|
|||
],
|
||||
[
|
||||
$this->run_level,
|
||||
$this->module['sroot'],
|
||||
DC_ROOT,
|
||||
__DIR__ . '/phpstan',
|
||||
(string) path::real($this->module['sroot'], false),
|
||||
(string) path::real(DC_ROOT, false),
|
||||
(string) path::real( __DIR__ . '/phpstan', false),
|
||||
],
|
||||
(string) file_get_contents(__DIR__ . '/phpstan/phpstan.rules.conf')
|
||||
(string) file_get_contents(__DIR__ . '/phpstan/phpstan.rules.' . $full . 'conf')
|
||||
);
|
||||
|
||||
$ignored = explode(';', $this->ignored_vars);
|
||||
|
|
|
@ -80,131 +80,3 @@ parameters:
|
|||
# $this variable may not be defined (plugins/themes)
|
||||
- message: '#Variable \$this might not be defined#'
|
||||
path: */*/_define.php
|
||||
|
||||
# dcAdmin object and auto properties
|
||||
- message: '#Access to an undefined property dcAdmin::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# dcNamespace object and auto properties
|
||||
- message: '#Access to an undefined property dcNamespace::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# context object and auto properties
|
||||
- message: '#Access to an undefined property context::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# record object and auto properties
|
||||
- message: '#Access to an undefined property record::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# dcWidgets object and auto properties
|
||||
- message: '#Access to an undefined property dcWidgets::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# dcWidgets object methods
|
||||
- message: '#Call to an undefined method dcWidgets::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# dcWidget object and auto properties
|
||||
- message: '#Access to an undefined property dcWidget::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# dcWidget object methods
|
||||
- message: '#Call to an undefined method dcWidget::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# xmlTag object and auto properties
|
||||
- message : '#Access to an undefined property xmlTag::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# xmlTag object methods
|
||||
- message : '#Call to an undefined method xmlTag::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# dcSettings object and auto properties
|
||||
- message : '#Access to an undefined property dcSettings::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# dcPrefs object and auto properties
|
||||
- message : '#Access to an undefined property dcPrefs::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# dbStruct object and auto properties
|
||||
- message : '#Access to an undefined property dbStruct::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# fileItem object and auto properties
|
||||
- message : '#Access to an undefined property fileItem::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# cursor object and auto properties
|
||||
- message : '#Access to an undefined property cursor::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# dcRecord object and auto properties
|
||||
- message: '#Access to an undefined property dcRecord::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# dcRecord object methods
|
||||
- message: '#Call to an undefined method dcRecord::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# Intensive use of magic __set/__get/__call/__invoke causes theses wrong warnings
|
||||
- message: '#Call to an undefined method form[a-zA-Z0-9\\_]+::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# Intensive use of magic __set/__get/__call/__invoke causes theses wrong warnings
|
||||
- message: '#Access to an undefined property form[a-zA-Z0-9\\_]+::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# form<*>filters
|
||||
- message: '#Access to an undefined property admin[a-zA-Z0-9\\_]+Filter::\$[a-zA-Z0-9\\_]+.#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# dcAdminfilters
|
||||
- message: '#Access to an undefined property dcAdminFilter::\$[a-zA-Z0-9\\_]+.#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# adminMediaPage
|
||||
- message: '#Access to an undefined property adminMediaPage::\$[a-zA-Z0-9\\_]+.#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# arrayObject/type
|
||||
- message: '#ArrayObject\<\*NEVER\*, \*NEVER\*\> does not accept#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# dcAdmin::$widgets user-defined properties
|
||||
- message: '#Access to an undefined property dcCore::\$widgets.#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# dcAdmin::$default_widgets user-defined properties
|
||||
- message: '#Access to an undefined property dcCore::\$default_widgets.#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# formXXX
|
||||
- message: '#Access to an undefined property \$this\(form[a-zA-Z0-9\\_]+\)::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# 2.25+
|
||||
|
||||
# WidgetsStack object and auto properties
|
||||
- message: '#Access to an undefined property Dotclear\\Plugin\\widgets\\WidgetsStack::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# WidgetsElement object and auto properties
|
||||
- message: '#Access to an undefined property Dotclear\\Plugin\\widgets\\WidgetsElement::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# dcModuleDefine auto properties
|
||||
- message: '#Access to an undefined property dcModuleDefine::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# 2.26+
|
||||
|
||||
# Intensive use of magic __set/__get/__call/__invoke causes theses wrong warnings
|
||||
- message: '#Call to an undefined method Dotclear\\Helper\\Html\\Form\\[a-zA-Z0-9\\_]+::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
||||
# Intensive use of magic __set/__get/__call/__invoke causes theses wrong warnings
|
||||
- message: '#Access to an undefined property Dotclear\\Helper\\Html\\Form\\[a-zA-Z0-9\\_]+::#'
|
||||
path: %currentWorkingDirectory%
|
||||
|
|
179
src/module/phpstan/phpstan.rules.full.conf
Normal file
179
src/module/phpstan/phpstan.rules.full.conf
Normal file
|
@ -0,0 +1,179 @@
|
|||
parameters:
|
||||
level: %LEVEL%
|
||||
|
||||
paths:
|
||||
- %MODULE_ROOT%
|
||||
|
||||
scanFiles:
|
||||
- %DC_ROOT%/index.php
|
||||
|
||||
scanDirectories:
|
||||
- %DC_ROOT%
|
||||
|
||||
excludePaths:
|
||||
- %MODULE_ROOT%/*/libs/*
|
||||
|
||||
bootstrapFiles:
|
||||
- %BOOTSTRAP_ROOT%/phpstan.bootstrap.php
|
||||
|
||||
fileExtensions:
|
||||
- php
|
||||
- in
|
||||
|
||||
dynamicConstantNames:
|
||||
- DC_ADBLOCKER_CHECK
|
||||
- DC_ADMIN_SSL
|
||||
- DC_ADMIN_URL
|
||||
- DC_AKISMET_SUPER
|
||||
- DC_ALLOW_MULTI_MODULES
|
||||
- DC_ALLOW_REPOSITORIES
|
||||
- DC_ANTISPAM_CONF_SUPER
|
||||
- DC_BACKUP_PATH
|
||||
- DC_CRYPT_ALGO
|
||||
- DC_CSP_LOGFILE
|
||||
- DC_DBDRIVER
|
||||
- DC_DBHOST
|
||||
- DC_DBNAME
|
||||
- DC_DBPASSWORD
|
||||
- DC_DBPREFIX
|
||||
- DC_DBUSER
|
||||
- DC_DEBUG
|
||||
- DC_DEFAULT_JQUERY
|
||||
- DC_DEFAULT_THEME
|
||||
- DC_DEFAULT_TPLSET
|
||||
- DC_DEV
|
||||
- DC_DIGESTS
|
||||
- DC_DISTRIB_PLUGINS
|
||||
- DC_DISTRIB_THEMES
|
||||
- DC_DNSBL_SUPER
|
||||
- DC_ERRORFILE
|
||||
- DC_FAIRTRACKBACKS_FORCE
|
||||
- DC_FORCE_SCHEME_443
|
||||
- DC_L10N_ROOT
|
||||
- DC_L10N_UPDATE_URL
|
||||
- DC_MASTER_KEY
|
||||
- DC_MAX_UPLOAD_SIZE
|
||||
- DC_NEXT_REQUIRED_PHP
|
||||
- DC_NOT_UPDATE
|
||||
- DC_PLUGINS_ROOT
|
||||
- DC_QUERY_TIMEOUT
|
||||
- DC_RC_PATH
|
||||
- DC_REVERSE_PROXY
|
||||
- DC_ROOT
|
||||
- DC_SESSION_NAME
|
||||
- DC_SESSION_TTL
|
||||
- DC_STORE_NOT_UPDATE
|
||||
- DC_TPL_CACHE
|
||||
- DC_UPDATE_URL
|
||||
- DC_UPDATE_VERSION
|
||||
- DC_VAR
|
||||
- DC_VENDOR_NAME
|
||||
- DC_VERSION
|
||||
- DC_XMLRPC_URL
|
||||
|
||||
checkMissingIterableValueType: false
|
||||
checkGenericClassInNonGenericObjectType: false
|
||||
reportUnmatchedIgnoredErrors: false
|
||||
|
||||
ignoreErrors:
|
||||
|
||||
# $this variable may not be defined (plugins/themes)
|
||||
- message: '#Variable \$this might not be defined#'
|
||||
path: */*/_define.php
|
||||
|
||||
# dcAdmin object and auto properties
|
||||
- message: '#Access to an undefined property dcAdmin::#'
|
||||
|
||||
# dcNamespace object and auto properties
|
||||
- message: '#Access to an undefined property dcNamespace::#'
|
||||
|
||||
# context object and auto properties
|
||||
- message: '#Access to an undefined property context::#'
|
||||
|
||||
# record object and auto properties
|
||||
- message: '#Access to an undefined property record::#'
|
||||
|
||||
# dcWidgets object and auto properties
|
||||
- message: '#Access to an undefined property dcWidgets::#'
|
||||
|
||||
# dcWidgets object methods
|
||||
- message: '#Call to an undefined method dcWidgets::#'
|
||||
|
||||
# dcWidget object and auto properties
|
||||
- message: '#Access to an undefined property dcWidget::#'
|
||||
|
||||
# dcWidget object methods
|
||||
- message: '#Call to an undefined method dcWidget::#'
|
||||
|
||||
# xmlTag object and auto properties
|
||||
- message : '#Access to an undefined property xmlTag::#'
|
||||
|
||||
# xmlTag object methods
|
||||
- message : '#Call to an undefined method xmlTag::#'
|
||||
|
||||
# dcSettings object and auto properties
|
||||
- message : '#Access to an undefined property dcSettings::#'
|
||||
|
||||
# dcPrefs object and auto properties
|
||||
- message : '#Access to an undefined property dcPrefs::#'
|
||||
|
||||
# dbStruct object and auto properties
|
||||
- message : '#Access to an undefined property dbStruct::#'
|
||||
|
||||
# fileItem object and auto properties
|
||||
- message : '#Access to an undefined property fileItem::#'
|
||||
|
||||
# cursor object and auto properties
|
||||
- message : '#Access to an undefined property cursor::#'
|
||||
|
||||
# dcRecord object and auto properties
|
||||
- message: '#Access to an undefined property dcRecord::#'
|
||||
|
||||
# dcRecord object methods
|
||||
- message: '#Call to an undefined method dcRecord::#'
|
||||
|
||||
# Intensive use of magic __set/__get/__call/__invoke causes theses wrong warnings
|
||||
- message: '#Call to an undefined method form[a-zA-Z0-9\\_]+::#'
|
||||
|
||||
# Intensive use of magic __set/__get/__call/__invoke causes theses wrong warnings
|
||||
- message: '#Access to an undefined property form[a-zA-Z0-9\\_]+::#'
|
||||
|
||||
# form<*>filters
|
||||
- message: '#Access to an undefined property admin[a-zA-Z0-9\\_]+Filter::\$[a-zA-Z0-9\\_]+.#'
|
||||
|
||||
# dcAdminfilters
|
||||
- message: '#Access to an undefined property dcAdminFilter::\$[a-zA-Z0-9\\_]+.#'
|
||||
|
||||
# adminMediaPage
|
||||
- message: '#Access to an undefined property adminMediaPage::\$[a-zA-Z0-9\\_]+.#'
|
||||
|
||||
# arrayObject/type
|
||||
- message: '#ArrayObject\<\*NEVER\*, \*NEVER\*\> does not accept#'
|
||||
|
||||
# dcAdmin::$widgets user-defined properties
|
||||
- message: '#Access to an undefined property dcCore::\$widgets.#'
|
||||
|
||||
# dcAdmin::$default_widgets user-defined properties
|
||||
- message: '#Access to an undefined property dcCore::\$default_widgets.#'
|
||||
|
||||
# formXXX
|
||||
- message: '#Access to an undefined property \$this\(form[a-zA-Z0-9\\_]+\)::#'
|
||||
|
||||
# 2.25+
|
||||
|
||||
# WidgetsStack object and auto properties
|
||||
- message: '#Access to an undefined property Dotclear\\Plugin\\widgets\\WidgetsStack::#'
|
||||
|
||||
# WidgetsElement object and auto properties
|
||||
- message: '#Access to an undefined property Dotclear\\Plugin\\widgets\\WidgetsElement::#'
|
||||
|
||||
# dcModuleDefine auto properties
|
||||
- message: '#Access to an undefined property dcModuleDefine::#'
|
||||
|
||||
# 2.26+
|
||||
|
||||
# Intensive use of magic __set/__get/__call/__invoke causes theses wrong warnings
|
||||
- message: '#Call to an undefined method Dotclear\\Helper\\Html\\Form\\[a-zA-Z0-9\\_]+::#'
|
||||
|
||||
# Intensive use of magic __set/__get/__call/__invoke causes theses wrong warnings
|
||||
- message: '#Access to an undefined property Dotclear\\Helper\\Html\\Form\\[a-zA-Z0-9\\_]+::#'
|
Loading…
Reference in a new issue