enhance phpstan configuration
This commit is contained in:
parent
6daddd17e3
commit
3b8651b1cb
3 changed files with 88 additions and 27 deletions
7
inc/lib.improve.action.phpstan.js
Normal file
7
inc/lib.improve.action.phpstan.js
Normal file
|
@ -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
|
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
|
protected function init(): bool
|
||||||
{
|
{
|
||||||
$this->setProperties([
|
$this->setProperties([
|
||||||
|
@ -23,6 +29,10 @@ class ImproveActionPhpstan extends ImproveAction
|
||||||
'types' => ['plugin']
|
'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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,19 +41,30 @@ class ImproveActionPhpstan extends ImproveAction
|
||||||
return true;
|
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
|
public function configure($url): ?string
|
||||||
{
|
{
|
||||||
if (!empty($_POST['save'])) {
|
if (!empty($_POST['save'])) {
|
||||||
$this->setSettings([
|
$this->setSettings([
|
||||||
'phpexe_path' => (!empty($_POST['phpexe_path']) ? $_POST['phpexe_path'] : ''),
|
'phpexe_path' => (!empty($_POST['phpexe_path']) ? $_POST['phpexe_path'] : ''),
|
||||||
'run_level' => (integer) $_POST['run_level'],
|
'run_level' => (int) $_POST['run_level'],
|
||||||
'ignored_vars' => (!empty($_POST['ignored_vars']) ? $_POST['ignored_vars'] : ''),
|
'ignored_vars' => (!empty($_POST['ignored_vars']) ? $_POST['ignored_vars'] : ''),
|
||||||
'split_report' => !empty($_POST['split_report'])
|
'split_report' => !empty($_POST['split_report'])
|
||||||
]);
|
]);
|
||||||
$this->redirect($url);
|
$this->redirect($url);
|
||||||
}
|
}
|
||||||
|
$content = (string) file_get_contents(dirname(__FILE__) . '/libs/dc.phpstan.rules.conf');
|
||||||
|
|
||||||
return
|
return
|
||||||
|
'<p class="info">' . __('You must enable improve details to view analyse results !') . '</p>' .
|
||||||
'<p><label class="classic" for="phpexe_path">' .
|
'<p><label class="classic" for="phpexe_path">' .
|
||||||
__('Root directory of PHP executable:') . '<br />' .
|
__('Root directory of PHP executable:') . '<br />' .
|
||||||
form::field('phpexe_path', 160, 255, $this->getSetting('phpexe_path')) . '</label>' .
|
form::field('phpexe_path', 160, 255, $this->getSetting('phpexe_path')) . '</label>' .
|
||||||
|
@ -52,7 +73,7 @@ class ImproveActionPhpstan extends ImproveAction
|
||||||
__('If this module does not work you can try to put here directory to php executable (without executable file name).') .
|
__('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>' .
|
' C:\path_to\php</p>' .
|
||||||
'<p><label class="classic" for="run_level">' . __('Level:') . ' </label>' .
|
'<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">' .
|
'<p><label class="classic" for="ignored_vars">' .
|
||||||
__('List of ignored variables:') . '<br />' .
|
__('List of ignored variables:') . '<br />' .
|
||||||
form::field('ignored_vars', 160, 255, $this->getSetting('ignored_vars')) . '</label>' .
|
form::field('ignored_vars', 160, 255, $this->getSetting('ignored_vars')) . '</label>' .
|
||||||
|
@ -65,7 +86,18 @@ class ImproveActionPhpstan extends ImproveAction
|
||||||
form::checkbox('split_report', 1, $this->getSetting('split_report')) .
|
form::checkbox('split_report', 1, $this->getSetting('split_report')) .
|
||||||
__('Split report by file rather than all in the end.') . '</label></p>' .
|
__('Split report by file rather than all in the end.') . '</label></p>' .
|
||||||
'<p class="form-note">' . __('Enable this can cause timeout.') . '</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
|
public function openModule(): bool
|
||||||
|
@ -151,22 +183,21 @@ class ImproveActionPhpstan extends ImproveAction
|
||||||
|
|
||||||
private function writeConf(): bool
|
private function writeConf(): bool
|
||||||
{
|
{
|
||||||
$content =
|
$content = str_replace(
|
||||||
"parameters:\n" .
|
[
|
||||||
" level: " . (integer) $this->getSetting('run_level') . "\n\n" .
|
'%LEVEL%',
|
||||||
" paths: \n" .
|
'%MODULE_ROOT%',
|
||||||
" - " . $this->module['sroot'] . "\n\n" .
|
'%DC_ROOT%',
|
||||||
" scanFiles:\n" .
|
'%BOOTSTRAP_ROOT%'
|
||||||
" - " . DC_ROOT . "/index.php\n" .
|
],
|
||||||
" scanDirectories:\n" .
|
[
|
||||||
" - " . DC_ROOT . "\n" .
|
(int) $this->getSetting('run_level'),
|
||||||
" excludePaths:\n" .
|
$this->module['sroot'],
|
||||||
" - " . $this->module['sroot'] . "/*/libs/*\n\n" .
|
DC_ROOT,
|
||||||
" bootstrapFiles:\n" .
|
dirname(__FILE__) . '/libs/'
|
||||||
" - " . dirname(__FILE__) . "/libs/dc.phpstan.bootstrap.php\n\n";
|
],
|
||||||
|
(string) file_get_contents(dirname(__FILE__) . '/libs/dc.phpstan.rules.conf')
|
||||||
// common
|
);
|
||||||
$content .= file_get_contents(dirname(__FILE__) . "/libs/dc.phpstan.neon.conf");
|
|
||||||
|
|
||||||
$ignored = explode(';', $this->getSetting('ignored_vars'));
|
$ignored = explode(';', $this->getSetting('ignored_vars'));
|
||||||
foreach ($ignored as $var) {
|
foreach ($ignored as $var) {
|
||||||
|
@ -175,12 +206,11 @@ class ImproveActionPhpstan extends ImproveAction
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$content .=
|
$content .= ' # $' . $var . ' variable may not be defined (globally)' . "\n" .
|
||||||
' # $' . $var .' variable may not be defined (globally)' . "\n" .
|
|
||||||
' - message: \'#Variable \$' . $var . ' might not be defined#\'' . "\n" .
|
' - message: \'#Variable \$' . $var . ' might not be defined#\'' . "\n" .
|
||||||
' path: *' . "\n\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:
|
fileExtensions:
|
||||||
- php
|
- php
|
||||||
- in
|
- in
|
||||||
|
@ -35,6 +53,12 @@
|
||||||
- */_install.php
|
- */_install.php
|
||||||
- */_uninstall.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)
|
# $_menu variable may not be defined (plugins/themes)
|
||||||
- message: '#Variable \$_menu might not be defined#'
|
- message: '#Variable \$_menu might not be defined#'
|
||||||
path: */_admin.php
|
path: */_admin.php
|
Loading…
Reference in a new issue