From 0721a7b8788dfaf537ff018e605f001ef9847a3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Ku=C5=BAnik?= Date: Wed, 27 Aug 2025 23:27:08 +0200 Subject: [PATCH 1/3] chore: Upgrade static analysis level --- phpstan.neon | 3 ++- src/CompareVersions.php | 4 ---- src/Featurevisor.php | 14 ++++++-------- src/Logger.php | 2 +- tests/ChildTest.php | 2 -- 5 files changed, 9 insertions(+), 16 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 7ee3062..92d54c4 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,6 @@ parameters: - level: 3 + level: 4 + treatPhpDocTypesAsCertain: false paths: - src - tests diff --git a/src/CompareVersions.php b/src/CompareVersions.php index a362eca..b185dd0 100644 --- a/src/CompareVersions.php +++ b/src/CompareVersions.php @@ -32,10 +32,6 @@ public static function compare(string $v1, string $v2): int private static function validateAndParse(string $version): array { - if (!is_string($version)) { - throw new \TypeError('Invalid argument expected string'); - } - if (!preg_match(self::$semver, $version, $match)) { throw new \Exception("Invalid argument not valid semver ('$version' received)"); } diff --git a/src/Featurevisor.php b/src/Featurevisor.php index d58ae9e..b645c8e 100644 --- a/src/Featurevisor.php +++ b/src/Featurevisor.php @@ -560,20 +560,18 @@ public function getAllEvaluations(array $context = [], array $featureKeys = [], 'flagEvaluation' => $flagEvaluation, ]); // variation - if (method_exists($this->datafileReader, 'hasVariations') && $this->datafileReader->hasVariations($featureKey)) { + if ($this->datafileReader->hasVariations($featureKey)) { $variation = $this->getVariation($featureKey, $context, $opts); if ($variation !== null) { $evaluatedFeature['variation'] = $variation; } } // variables - if (method_exists($this->datafileReader, 'getVariableKeys')) { - $variableKeys = $this->datafileReader->getVariableKeys($featureKey); - if (!empty($variableKeys)) { - $evaluatedFeature['variables'] = []; - foreach ($variableKeys as $variableKey) { - $evaluatedFeature['variables'][$variableKey] = $this->getVariable($featureKey, $variableKey, $context, $opts); - } + $variableKeys = $this->datafileReader->getVariableKeys($featureKey); + if (!empty($variableKeys)) { + $evaluatedFeature['variables'] = []; + foreach ($variableKeys as $variableKey) { + $evaluatedFeature['variables'][$variableKey] = $this->getVariable($featureKey, $variableKey, $context, $opts); } } $evaluations[$featureKey] = $evaluatedFeature; diff --git a/src/Logger.php b/src/Logger.php index 92e12b4..2dc9364 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -72,7 +72,7 @@ public function log($level, $message, array $context = []): void private static function defaultLogHandler($level, $message, ?array $details = null): void { - if (STDOUT === false) { + if (STDOUT == false) { return; } diff --git a/tests/ChildTest.php b/tests/ChildTest.php index 1d75715..9b7153f 100644 --- a/tests/ChildTest.php +++ b/tests/ChildTest.php @@ -147,14 +147,12 @@ public function testCreateChildInstanceAndAllBehaviors() { 'context' => [ 'appVersion' => '1.0.0' ], ]); - self::assertNotNull($f); self::assertEquals(['appVersion' => '1.0.0'], $f->getContext()); $childF = $f->spawn([ 'userId' => '123', 'country' => 'nl', ]); - self::assertNotNull($childF); self::assertEquals([ 'appVersion' => '1.0.0', 'userId' => '123', From 43b8f3a58510b749d0e23e503c150d4a9a481036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Ku=C5=BAnik?= Date: Wed, 27 Aug 2025 23:31:20 +0200 Subject: [PATCH 2/3] chore: Ignore errors hard to fix without declared array types --- phpstan.neon | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/phpstan.neon b/phpstan.neon index 92d54c4..ff1d56c 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,3 +4,27 @@ parameters: paths: - src - tests + ignoreErrors: + - + message: '#^Call to function is_array\(\) with mixed will always evaluate to false\.$#' + identifier: function.impossibleType + count: 1 + path: src/Bucketer.php + + - + message: '#^Offset ''or'' on \*NEVER\* in isset\(\) always exists and is not nullable\.$#' + identifier: isset.offset + count: 1 + path: src/Bucketer.php + + - + message: '#^Strict comparison using \!\=\= between mixed and null will always evaluate to true\.$#' + identifier: notIdentical.alwaysTrue + count: 1 + path: src/EvaluateSticky.php + + - + message: '#^Call to function method_exists\(\) with Featurevisor\\Featurevisor and ''getVariation'' will always evaluate to true\.$#' + identifier: function.alreadyNarrowedType + count: 1 + path: tests/FeaturevisorTest.php From d4ec13e20a5cb1f8f48bde0e5020242e74eaf6df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Ku=C5=BAnik?= Date: Wed, 27 Aug 2025 23:33:31 +0200 Subject: [PATCH 3/3] chore: Upgrade static analysis to level 5 --- phpstan.neon | 2 +- src/Featurevisor.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index ff1d56c..69bdbb4 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 4 + level: 5 treatPhpDocTypesAsCertain: false paths: - src diff --git a/src/Featurevisor.php b/src/Featurevisor.php index b645c8e..151e869 100644 --- a/src/Featurevisor.php +++ b/src/Featurevisor.php @@ -23,10 +23,10 @@ class Featurevisor * sticky?: array, * hooks?: array * } $options * @return self