Skip to content

Commit e1e9c59

Browse files
authored
chore: Static analysis tool rule level upgrade (#11)
1 parent c8e325d commit e1e9c59

File tree

5 files changed

+37
-20
lines changed

5 files changed

+37
-20
lines changed

phpstan.neon

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
parameters:
2-
level: 3
2+
level: 5
3+
treatPhpDocTypesAsCertain: false
34
paths:
45
- src
56
- tests
7+
ignoreErrors:
8+
-
9+
message: '#^Call to function is_array\(\) with mixed will always evaluate to false\.$#'
10+
identifier: function.impossibleType
11+
count: 1
12+
path: src/Bucketer.php
13+
14+
-
15+
message: '#^Offset ''or'' on \*NEVER\* in isset\(\) always exists and is not nullable\.$#'
16+
identifier: isset.offset
17+
count: 1
18+
path: src/Bucketer.php
19+
20+
-
21+
message: '#^Strict comparison using \!\=\= between mixed and null will always evaluate to true\.$#'
22+
identifier: notIdentical.alwaysTrue
23+
count: 1
24+
path: src/EvaluateSticky.php
25+
26+
-
27+
message: '#^Call to function method_exists\(\) with Featurevisor\\Featurevisor and ''getVariation'' will always evaluate to true\.$#'
28+
identifier: function.alreadyNarrowedType
29+
count: 1
30+
path: tests/FeaturevisorTest.php

src/CompareVersions.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ public static function compare(string $v1, string $v2): int
3232

3333
private static function validateAndParse(string $version): array
3434
{
35-
if (!is_string($version)) {
36-
throw new \TypeError('Invalid argument expected string');
37-
}
38-
3935
if (!preg_match(self::$semver, $version, $match)) {
4036
throw new \Exception("Invalid argument not valid semver ('$version' received)");
4137
}

src/Featurevisor.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ class Featurevisor
2323
* sticky?: array<string, mixed>,
2424
* hooks?: array<array{
2525
* name: string,
26-
* before: Closure,
27-
* after: Closure,
28-
* bucketKey: Closure,
29-
* bucketValue: Closure
26+
* before?: Closure,
27+
* after?: Closure,
28+
* bucketKey?: Closure,
29+
* bucketValue?: Closure
3030
* }>
3131
* } $options
3232
* @return self
@@ -560,20 +560,18 @@ public function getAllEvaluations(array $context = [], array $featureKeys = [],
560560
'flagEvaluation' => $flagEvaluation,
561561
]);
562562
// variation
563-
if (method_exists($this->datafileReader, 'hasVariations') && $this->datafileReader->hasVariations($featureKey)) {
563+
if ($this->datafileReader->hasVariations($featureKey)) {
564564
$variation = $this->getVariation($featureKey, $context, $opts);
565565
if ($variation !== null) {
566566
$evaluatedFeature['variation'] = $variation;
567567
}
568568
}
569569
// variables
570-
if (method_exists($this->datafileReader, 'getVariableKeys')) {
571-
$variableKeys = $this->datafileReader->getVariableKeys($featureKey);
572-
if (!empty($variableKeys)) {
573-
$evaluatedFeature['variables'] = [];
574-
foreach ($variableKeys as $variableKey) {
575-
$evaluatedFeature['variables'][$variableKey] = $this->getVariable($featureKey, $variableKey, $context, $opts);
576-
}
570+
$variableKeys = $this->datafileReader->getVariableKeys($featureKey);
571+
if (!empty($variableKeys)) {
572+
$evaluatedFeature['variables'] = [];
573+
foreach ($variableKeys as $variableKey) {
574+
$evaluatedFeature['variables'][$variableKey] = $this->getVariable($featureKey, $variableKey, $context, $opts);
577575
}
578576
}
579577
$evaluations[$featureKey] = $evaluatedFeature;

src/Logger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function log($level, $message, array $context = []): void
7272

7373
private static function defaultLogHandler($level, $message, ?array $details = null): void
7474
{
75-
if (STDOUT === false) {
75+
if (STDOUT == false) {
7676
return;
7777
}
7878

tests/ChildTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,12 @@ public function testCreateChildInstanceAndAllBehaviors() {
147147
'context' => [ 'appVersion' => '1.0.0' ],
148148
]);
149149

150-
self::assertNotNull($f);
151150
self::assertEquals(['appVersion' => '1.0.0'], $f->getContext());
152151

153152
$childF = $f->spawn([
154153
'userId' => '123',
155154
'country' => 'nl',
156155
]);
157-
self::assertNotNull($childF);
158156
self::assertEquals([
159157
'appVersion' => '1.0.0',
160158
'userId' => '123',

0 commit comments

Comments
 (0)