From f4ee508f31edcf051f098e3a8a3ef9072d5274a3 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Tue, 2 Nov 2021 18:17:35 -0500 Subject: [PATCH] Run phpstan locally with `lnms dev:check lint` (#13458) * Run phpstan locally with `lnms dev:check lint` Separate result cache for deprecated functions so we don't break the cache every time. * Skip phpstan flag Skip all lints on ci except php lint (so we can check on multiple php versions) * forgot default value * fix up test cases * Update LibreNMS/Util/CiHelper.php Co-authored-by: Jellyfrog Co-authored-by: Jellyfrog --- LibreNMS/Util/CiHelper.php | 10 +++++++++- app/Console/Commands/DevCheckCommand.php | 9 ++++++++- phpstan-deprecated.neon | 1 + tests/Unit/CiHelperTest.php | 11 +++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/LibreNMS/Util/CiHelper.php b/LibreNMS/Util/CiHelper.php index 0ce72b9931..103414cdd8 100644 --- a/LibreNMS/Util/CiHelper.php +++ b/LibreNMS/Util/CiHelper.php @@ -59,6 +59,7 @@ class CiHelper 'unit_skip' => false, 'web_skip' => false, 'lint_skip_php' => false, + 'lint_skip_phpstan' => false, 'lint_skip_python' => false, 'lint_skip_bash' => false, 'unit_os' => false, @@ -273,6 +274,12 @@ class CiHelper $php_lint_cmd = array_merge($php_lint_cmd, $files); $return += $this->execute('PHP lint', $php_lint_cmd); + + if (! $this->flags['lint_skip_phpstan']) { + $phpstan_cmd = [$this->checkPhpExec('phpstan'), 'analyze', '--no-interaction', '--memory-limit=2G']; + $return += $this->execute('PHPStan Deprecated', $phpstan_cmd + ['--configuration=phpstan-deprecated.neon']); + $return += $this->execute('PHPStan', $phpstan_cmd); + } } if (! $this->flags['lint_skip_python']) { @@ -425,6 +432,7 @@ class CiHelper $this->setFlags([ 'lint_skip_php' => empty($this->changed['php']), + 'lint_skip_phpstan' => empty($this->changed['php']), 'lint_skip_python' => empty($this->changed['python']), 'lint_skip_bash' => empty($this->changed['bash']), 'unit_os' => $this->getFlag('unit_os') || (! empty($this->changed['os']) && empty(array_diff($this->changed['php'], $this->changed['os-files']))), @@ -435,7 +443,7 @@ class CiHelper $this->setFlags([ 'unit_skip' => empty($this->changed['php']) && ! array_sum(Arr::only($this->getFlags(), ['unit_os', 'unit_docs', 'unit_svg', 'unit_modules', 'docs_changed'])), - 'lint_skip' => array_sum(Arr::only($this->getFlags(), ['lint_skip_php', 'lint_skip_python', 'lint_skip_bash'])) === 3, + 'lint_skip' => array_sum(Arr::only($this->getFlags(), ['lint_skip_php', 'lint_skip_phpstan', 'lint_skip_python', 'lint_skip_bash'])) === 4, 'style_skip' => ! $this->flags['ci'] && empty($this->changed['php']), 'web_skip' => empty($this->changed['php']) && empty($this->changed['resources']), ]); diff --git a/app/Console/Commands/DevCheckCommand.php b/app/Console/Commands/DevCheckCommand.php index 24d07c04ca..57e1c9a928 100644 --- a/app/Console/Commands/DevCheckCommand.php +++ b/app/Console/Commands/DevCheckCommand.php @@ -100,7 +100,14 @@ class DevCheckCommand extends LnmsCommand } if ($check == 'ci') { - $this->helper->setFlags(['ci' => true, 'fail-fast' => true]); + $this->helper->setFlags([ + 'ci' => true, + 'fail-fast' => true, + // checked in lint workflow + 'lint_skip_phpstan' => true, + 'lint_skip_python' => true, + 'lint_skip_bash' => true, + ]); $this->helper->duskHeadless(); $this->helper->enableSnmpsim(); $this->helper->enableDb(); diff --git a/phpstan-deprecated.neon b/phpstan-deprecated.neon index 6bc7461e8b..d733ffe229 100644 --- a/phpstan-deprecated.neon +++ b/phpstan-deprecated.neon @@ -6,6 +6,7 @@ parameters: customRulesetUsed: true reportUnmatchedIgnoredErrors: false + resultCachePath: %tmpDir%/resultCache-deprecated.php paths: - LibreNMS diff --git a/tests/Unit/CiHelperTest.php b/tests/Unit/CiHelperTest.php index ac8e255429..db52f629ef 100644 --- a/tests/Unit/CiHelperTest.php +++ b/tests/Unit/CiHelperTest.php @@ -72,6 +72,7 @@ class CiHelperTest extends TestCase 'unit_skip' => true, 'web_skip' => true, 'lint_skip_php' => true, + 'lint_skip_phpstan' => true, 'lint_skip_python' => true, 'lint_skip_bash' => true, ]); @@ -95,6 +96,7 @@ class CiHelperTest extends TestCase 'web_skip' => true, 'unit_os' => true, 'lint_skip_php' => true, + 'lint_skip_phpstan' => true, 'lint_skip_python' => true, 'lint_skip_bash' => true, ]); @@ -108,6 +110,7 @@ class CiHelperTest extends TestCase 'web_skip' => true, 'unit_os' => true, 'lint_skip_php' => true, + 'lint_skip_phpstan' => true, 'lint_skip_python' => true, 'lint_skip_bash' => true, ]); @@ -131,6 +134,7 @@ class CiHelperTest extends TestCase 'web_skip' => true, 'unit_modules' => true, 'lint_skip_php' => true, + 'lint_skip_phpstan' => true, 'lint_skip_python' => true, 'lint_skip_bash' => true, ]); @@ -147,6 +151,7 @@ class CiHelperTest extends TestCase 'unit_os' => true, 'unit_modules' => true, 'lint_skip_php' => true, + 'lint_skip_phpstan' => true, 'lint_skip_python' => true, 'lint_skip_bash' => true, ]); @@ -160,6 +165,7 @@ class CiHelperTest extends TestCase 'web_skip' => true, 'unit_os' => true, 'lint_skip_php' => true, + 'lint_skip_phpstan' => true, 'lint_skip_python' => true, 'lint_skip_bash' => true, ]); @@ -173,6 +179,7 @@ class CiHelperTest extends TestCase 'web_skip' => true, 'unit_os' => true, 'lint_skip_php' => true, + 'lint_skip_phpstan' => true, 'lint_skip_python' => true, 'lint_skip_bash' => true, ]); @@ -204,6 +211,7 @@ class CiHelperTest extends TestCase 'unit_skip' => true, 'web_skip' => true, 'lint_skip_php' => true, + 'lint_skip_phpstan' => true, ]); putenv('FILES=includes/polling/sensors/ios.inc.php'); @@ -223,6 +231,7 @@ class CiHelperTest extends TestCase 'style_skip' => true, 'web_skip' => true, 'lint_skip_php' => true, + 'lint_skip_phpstan' => true, 'lint_skip_python' => true, 'lint_skip_bash' => true, 'unit_svg' => true, @@ -236,6 +245,7 @@ class CiHelperTest extends TestCase 'style_skip' => true, 'web_skip' => true, 'lint_skip_php' => true, + 'lint_skip_phpstan' => true, 'lint_skip_python' => true, 'lint_skip_bash' => true, 'unit_svg' => true, @@ -272,6 +282,7 @@ class CiHelperTest extends TestCase 'unit_skip' => false, 'web_skip' => false, 'lint_skip_php' => false, + 'lint_skip_phpstan' => false, 'lint_skip_python' => false, 'lint_skip_bash' => false, 'unit_os' => false,