enhance phpstan configuration
parent
6daddd17e3
commit
3b8651b1cb
|
@ -0,0 +1,7 @@
|
|||
/*global CodeMirror, dotclear */
|
||||
'use strict';
|
||||
|
||||
window.CodeMirror.defineMode('dotclear', function (config) {
|
||||
config.readOnly = true;
|
||||
return CodeMirror.getMode(config, 'text/x-yaml');
|
||||
});
|
|
@ -12,6 +12,12 @@
|
|||
*/
|
||||
class ImproveActionPhpstan extends ImproveAction
|
||||
{
|
||||
/** @var boolean User pref to use colored synthax */
|
||||
protected static $user_ui_colorsyntax = false;
|
||||
|
||||
/** @var string User pref for colored synthax theme */
|
||||
protected static $user_ui_colorsyntax_theme = 'default';
|
||||
|
||||
protected function init(): bool
|
||||
{
|
||||
$this->setProperties([
|
||||
|
@ -23,6 +29,10 @@ class ImproveActionPhpstan extends ImproveAction
|
|||
'types' => ['plugin']
|
||||
]);
|
||||
|
||||
$this->core->auth->user_prefs->addWorkspace('interface');
|
||||
self::$user_ui_colorsyntax = $this->core->auth->user_prefs->interface->colorsyntax;
|
||||
self::$user_ui_colorsyntax_theme = $this->core->auth->user_prefs->interface->colorsyntax_theme;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -31,19 +41,30 @@ class ImproveActionPhpstan extends ImproveAction
|
|||
return true;
|
||||
}
|
||||
|
||||
public function header(): ?string
|
||||
{
|
||||
if (self::$user_ui_colorsyntax) {
|
||||
return dcPage::jsLoadCodeMirror(self::$user_ui_colorsyntax_theme);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function configure($url): ?string
|
||||
{
|
||||
if (!empty($_POST['save'])) {
|
||||
$this->setSettings([
|
||||
'phpexe_path' => (!empty($_POST['phpexe_path']) ? $_POST['phpexe_path'] : ''),
|
||||
'run_level' => (integer) $_POST['run_level'],
|
||||
'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'])
|
||||
]);
|
||||
$this->redirect($url);
|
||||
}
|
||||
$content = (string) file_get_contents(dirname(__FILE__) . '/libs/dc.phpstan.rules.conf');
|
||||
|
||||
return
|
||||
'<p class="info">' . __('You must enable improve details to view analyse results !') . '</p>' .
|
||||
'<p><label class="classic" for="phpexe_path">' .
|
||||
__('Root directory of PHP executable:') . '<br />' .
|
||||
form::field('phpexe_path', 160, 255, $this->getSetting('phpexe_path')) . '</label>' .
|
||||
|
@ -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</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>' .
|
||||
form::number('run_level', ['min' => 0, 'max' => 9, 'default' => (int) $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.'),
|
||||
__('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><label class="classic" for="split_report">' .
|
||||
form::checkbox('split_report', 1, $this->getSetting('split_report')) .
|
||||
__('Split report by file rather than all in the end.') . '</label></p>' .
|
||||
'<p class="form-note">' . __('Enable this can cause timeout.') . '</p>' .
|
||||
'<p class="info">' . __('You must enable improve details to view analyse results !') . '</p>';
|
||||
|
||||
'<p><label for="file_content">' . __('PHPStan configuration file:') . '</strong></label></p>' .
|
||||
'<p>' . form::textarea('file_content', 120, 14, [
|
||||
'default' => html::escapeHTML($content),
|
||||
'class' => 'maximal',
|
||||
'extra_html' => 'readonly="true"'
|
||||
]) . '</p>' .
|
||||
(
|
||||
!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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue