From 3b8651b1cbf8a4ab2014a53d1feaeff991ce96d8 Mon Sep 17 00:00:00 2001
From: Jean-Christian Denis ' . __('You must enable improve details to view analyse results !') . ' ' .
@@ -52,20 +73,31 @@ class ImproveActionPhpstan extends ImproveAction
__('If this module does not work you can try to put here directory to php executable (without executable file name).') .
' 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.'),
+ __('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.') . '
' . __('Enable this can cause timeout.') . '
' . - '' . __('You must enable improve details to view analyse results !') . '
'; + + '' . + '' . form::textarea('file_content', 120, 14, [ + 'default' => html::escapeHTML($content), + 'class' => 'maximal', + 'extra_html' => 'readonly="true"' + ]) . '
' . + ( + !self::$user_ui_colorsyntax ? '' : + dcPage::jsLoad(dcPage::getPF('improve/inc/lib.improve.action.phpstan.js')) . + dcPage::jsRunCodeMirror('editor', 'file_content', 'dotclear', self::$user_ui_colorsyntax_theme) + ); } public function openModule(): bool @@ -81,7 +113,7 @@ class ImproveActionPhpstan extends ImproveAction public function closeFile(): ?bool { - if (!$this->getSetting('split_report') + if (!$this->getSetting('split_report') || !in_array($this->path_extension, ['php', 'in']) ) { return null; @@ -151,36 +183,34 @@ class ImproveActionPhpstan extends ImproveAction private function writeConf(): bool { - $content = - "parameters:\n" . - " level: " . (integer) $this->getSetting('run_level') . "\n\n" . - " paths: \n" . - " - " . $this->module['sroot'] . "\n\n" . - " scanFiles:\n" . - " - " . DC_ROOT . "/index.php\n" . - " scanDirectories:\n" . - " - " . DC_ROOT . "\n" . - " excludePaths:\n" . - " - " . $this->module['sroot'] . "/*/libs/*\n\n" . - " bootstrapFiles:\n" . - " - " . dirname(__FILE__) . "/libs/dc.phpstan.bootstrap.php\n\n"; - - // common - $content .= file_get_contents(dirname(__FILE__) . "/libs/dc.phpstan.neon.conf"); + $content = str_replace( + [ + '%LEVEL%', + '%MODULE_ROOT%', + '%DC_ROOT%', + '%BOOTSTRAP_ROOT%' + ], + [ + (int) $this->getSetting('run_level'), + $this->module['sroot'], + DC_ROOT, + dirname(__FILE__) . '/libs/' + ], + (string) file_get_contents(dirname(__FILE__) . '/libs/dc.phpstan.rules.conf') + ); $ignored = explode(';', $this->getSetting('ignored_vars')); - foreach($ignored as $var) { + foreach ($ignored as $var) { $var = trim($var); if (empty($var)) { continue; } - $content .= - ' # $' . $var .' variable may not be defined (globally)' . "\n" . + $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); + return (bool) file_put_contents(DC_VAR . '/phpstan.neon', $content); } } diff --git a/inc/libs/dc.phpstan.neon.conf b/inc/libs/dc.phpstan.rules.conf similarity index 87% rename from inc/libs/dc.phpstan.neon.conf rename to inc/libs/dc.phpstan.rules.conf index 00b1ebc..75b95f3 100644 --- a/inc/libs/dc.phpstan.neon.conf +++ b/inc/libs/dc.phpstan.rules.conf @@ -1,3 +1,21 @@ +parameters: + level: %LEVEL% + + paths: + - %MODULE_ROOT% + + scanFiles: + - %DC_ROOT%/index.php + + scanDirectories: + - %DC_ROOT% + + excludePaths: + - %MODULE_ROOT%/*/libs/* + + bootstrapFiles: + - %BOOTSTRAP_ROOT%dc.phpstan.bootstrap.php + fileExtensions: - php - in @@ -35,6 +53,12 @@ - */_install.php - */_uninstall.php + # $list variable may not be defined (plugins/themes) + - message: '#Variable \$list might not be defined#' + paths: + - */_config.php + - */index.php + # $_menu variable may not be defined (plugins/themes) - message: '#Variable \$_menu might not be defined#' path: */_admin.php