Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cb5035f

Browse files
committedAug 8, 2024·
fix linter issue
Signed-off-by: Thomas Poignant <[email protected]>
1 parent aaa2577 commit cb5035f

File tree

4 files changed

+51
-25
lines changed

4 files changed

+51
-25
lines changed
 

‎providers/GoFeatureFlag/composer.json

+16-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,22 @@
2424
"require-dev": {
2525
"phpunit/phpunit": "^9",
2626
"mockery/mockery": "^1.6",
27-
"spatie/phpunit-snapshot-assertions": "^4.2"
27+
"spatie/phpunit-snapshot-assertions": "^4.2",
28+
"phan/phan": "^5.4",
29+
"php-parallel-lint/php-console-highlighter": "^1.0",
30+
"php-parallel-lint/php-parallel-lint": "^1.3",
31+
"phpstan/extension-installer": "^1.1",
32+
"phpstan/phpstan": "~1.10.0",
33+
"phpstan/phpstan-mockery": "^1.0",
34+
"phpstan/phpstan-phpunit": "^1.1",
35+
"psalm/plugin-mockery": "^0.11.0",
36+
"psalm/plugin-phpunit": "^0.18.0",
37+
"ramsey/coding-standard": "^2.0.3",
38+
"ramsey/composer-repl": "^1.4",
39+
"ramsey/conventional-commits": "^1.3",
40+
"roave/security-advisories": "dev-latest",
41+
"spatie/phpunit-snapshot-assertions": "^4.2",
42+
"vimeo/psalm": "~4.30.0"
2843
},
2944
"minimum-stability": "dev",
3045
"prefer-stable": true,

‎providers/GoFeatureFlag/src/GoFeatureFlagProvider.php

+11-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use OpenFeature\interfaces\provider\Provider;
1414
use OpenFeature\interfaces\provider\Reason;
1515
use OpenFeature\interfaces\provider\ResolutionDetails;
16+
use OpenFeature\Providers\GoFeatureFlag\config\Config;
1617
use OpenFeature\Providers\GoFeatureFlag\controller\OfrepApi;
1718
use OpenFeature\Providers\GoFeatureFlag\exception\BaseOfrepException;
1819
use OpenFeature\Providers\GoFeatureFlag\exception\InvalidConfigException;
@@ -26,7 +27,7 @@ class GoFeatureFlagProvider extends AbstractProvider implements Provider
2627
/**
2728
* @throws InvalidConfigException
2829
*/
29-
public function __construct($config = null)
30+
public function __construct(Config $config)
3031
{
3132
Validator::validateConfig($config);
3233
if (is_array($config->getCustomHeaders()) && !array_key_exists("Content-Type", $config->getCustomHeaders())) {
@@ -45,15 +46,22 @@ public function resolveBooleanValue(string $flagKey, bool $defaultValue, ?Evalua
4546
return $this->evaluate($flagKey, $defaultValue, ['boolean'], $context);
4647
}
4748

48-
private function evaluate(string $flagKey, mixed $defaultValue, array $allowedClasses, ?EvaluationContext $evaluationContext = null): ResolutionDetails
49+
/**
50+
* @param array<string> $allowedClasses
51+
*/
52+
private function evaluate(string $flagKey, mixed $defaultValue, array $allowedClasses, EvaluationContext $evaluationContext = null): ResolutionDetails
4953
{
5054
try {
5155
Validator::validateEvaluationContext($evaluationContext);
5256
Validator::validateFlagKey($flagKey);
57+
5358
$apiResp = $this->ofrepApi->evaluate($flagKey, $evaluationContext);
5459

5560
if ($apiResp->isError()) {
56-
$err = new ResolutionError($apiResp->getErrorCode(), $apiResp->getErrorDetails());
61+
$err = new ResolutionError(
62+
$apiResp->getErrorCode() ?? ErrorCode::GENERAL(),
63+
$apiResp->getErrorDetails()
64+
);
5765
return (new ResolutionDetailsBuilder())
5866
->withValue($defaultValue)
5967
->withError($err)

‎providers/GoFeatureFlag/src/util/Validator.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ class Validator
1818
* @return void
1919
* @throws InvalidConfigException - if the config is invalid we return an error
2020
*/
21-
public static function validateConfig(Config $config): void
21+
public static function validateConfig(?Config $config): void
2222
{
23+
if ($config === null) {
24+
throw new InvalidConfigException('Config is null');
25+
}
2326
self::validateEndpoint($config->getEndpoint());
2427
}
2528

‎providers/GoFeatureFlag/tests/unit/GoFeatureFlagProviderTest.php

+20-20
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class GoFeatureFlagProviderTest extends TestCase
2222
{
2323
private EvaluationContext $defaultEvaluationContext;
2424

25-
public function test_should_throw_if_invalid_endpoint()
25+
public function test_should_throw_if_invalid_endpoint(): void
2626
{
2727
$this->expectException(InvalidConfigException::class);
2828
new GoFeatureFlagProvider(
@@ -32,15 +32,15 @@ public function test_should_throw_if_invalid_endpoint()
3232

3333
// Configuration validation tests
3434

35-
public function test_should_not_throw_if_valid_endpoint()
35+
public function test_should_not_throw_if_valid_endpoint(): void
3636
{
3737
$provider = new GoFeatureFlagProvider(
3838
new Config('https://gofeatureflag.org')
3939
);
4040
$this->assertInstanceOf(GoFeatureFlagProvider::class, $provider);
4141
}
4242

43-
public function test_should_raise_if_endpoint_is_not_http()
43+
public function test_should_raise_if_endpoint_is_not_http(): void
4444
{
4545
$this->expectException(InvalidConfigException::class);
4646
$provider = new GoFeatureFlagProvider(
@@ -49,15 +49,15 @@ public function test_should_raise_if_endpoint_is_not_http()
4949
$this->assertInstanceOf(GoFeatureFlagProvider::class, $provider);
5050
}
5151

52-
public function test_empty_endpoint_should_throw()
52+
public function test_empty_endpoint_should_throw(): void
5353
{
5454
$this->expectException(InvalidConfigException::class);
5555
new GoFeatureFlagProvider(
5656
new Config('')
5757
);
5858
}
5959

60-
public function test_metadata_name_is_defined()
60+
public function test_metadata_name_is_defined(): void
6161
{
6262
$config = new Config('http://localhost:1031');
6363
$provider = new GoFeatureFlagProvider($config);
@@ -68,7 +68,7 @@ public function test_metadata_name_is_defined()
6868

6969
// Metadata tests
7070

71-
public function test_should_return_the_value_of_the_flag_as_int()
71+
public function test_should_return_the_value_of_the_flag_as_int(): void
7272
{
7373
$mockClient = $this->createMock(Client::class);
7474
$mockResponse = new Response(200, [], json_encode([
@@ -98,7 +98,7 @@ public function test_should_return_the_value_of_the_flag_as_int()
9898
assertEquals('integer_key', $got->getFlagKey());
9999
}
100100

101-
private function mockHttpClient($provider, $mockClient)
101+
private function mockHttpClient($provider, $mockClient): void
102102
{
103103
$providerReflection = new \ReflectionClass($provider);
104104
$ofrepApiProperty = $providerReflection->getProperty('ofrepApi');
@@ -111,7 +111,7 @@ private function mockHttpClient($provider, $mockClient)
111111
$clientProperty->setValue($ofrepApi, $mockClient);
112112
}
113113

114-
public function test_should_return_the_value_of_the_flag_as_float()
114+
public function test_should_return_the_value_of_the_flag_as_float(): void
115115
{
116116
$mockClient = $this->createMock(Client::class);
117117
$mockResponse = new Response(200, [], json_encode([
@@ -141,7 +141,7 @@ public function test_should_return_the_value_of_the_flag_as_float()
141141
assertEquals('flag-key', $got->getFlagKey());
142142
}
143143

144-
public function test_should_return_the_value_of_the_flag_as_string()
144+
public function test_should_return_the_value_of_the_flag_as_string(): void
145145
{
146146
$mockClient = $this->createMock(Client::class);
147147
$mockResponse = new Response(200, [], json_encode([
@@ -171,7 +171,7 @@ public function test_should_return_the_value_of_the_flag_as_string()
171171
assertEquals('flag-key', $got->getFlagKey());
172172
}
173173

174-
public function test_should_return_the_value_of_the_flag_as_bool()
174+
public function test_should_return_the_value_of_the_flag_as_bool(): void
175175
{
176176
$mockClient = $this->createMock(Client::class);
177177
$mockResponse = new Response(200, [], json_encode([
@@ -201,7 +201,7 @@ public function test_should_return_the_value_of_the_flag_as_bool()
201201
assertEquals('flag-key', $got->getFlagKey());
202202
}
203203

204-
public function test_should_return_the_value_of_the_flag_as_object()
204+
public function test_should_return_the_value_of_the_flag_as_object(): void
205205
{
206206
$mockClient = $this->createMock(Client::class);
207207
$mockResponse = new Response(200, [], json_encode([
@@ -231,7 +231,7 @@ public function test_should_return_the_value_of_the_flag_as_object()
231231
assertEquals('flag-key', $got->getFlagKey());
232232
}
233233

234-
public function test_should_return_the_default_value_if_flag_is_not_the_right_type()
234+
public function test_should_return_the_default_value_if_flag_is_not_the_right_type(): void
235235
{
236236
$mockClient = $this->createMock(Client::class);
237237
$mockResponse = new Response(200, [], json_encode([
@@ -262,7 +262,7 @@ public function test_should_return_the_default_value_if_flag_is_not_the_right_ty
262262
assertEquals('integer_key', $got->getFlagKey());
263263
}
264264

265-
public function test_should_return_the_default_value_of_the_flag_if_error_send_by_the_API_http_code_403()
265+
public function test_should_return_the_default_value_of_the_flag_if_error_send_by_the_API_http_code_403(): void
266266
{
267267
$mockClient = $this->createMock(Client::class);
268268
$mockResponse = new Response(403, [], json_encode([]));
@@ -288,7 +288,7 @@ public function test_should_return_the_default_value_of_the_flag_if_error_send_b
288288
assertEquals('boolean_key', $got->getFlagKey());
289289
}
290290

291-
public function test_should_return_the_default_value_of_the_flag_if_error_send_by_the_API__http_code_400__()
291+
public function test_should_return_the_default_value_of_the_flag_if_error_send_by_the_API__http_code_400(): void
292292
{
293293
$mockClient = $this->createMock(Client::class);
294294
$mockResponse = new Response(400, [], json_encode([
@@ -319,7 +319,7 @@ public function test_should_return_the_default_value_of_the_flag_if_error_send_b
319319
assertEquals('boolean_key', $got->getFlagKey());
320320
}
321321

322-
public function test_should_return_default_value_if_no_evaluation_context()
322+
public function test_should_return_default_value_if_no_evaluation_context(): void
323323
{
324324
$mockClient = $this->createMock(Client::class);
325325
$mockResponse = new Response(200, [], json_encode([
@@ -349,7 +349,7 @@ public function test_should_return_default_value_if_no_evaluation_context()
349349
assertEquals('boolean_key', $got->getFlagKey());
350350
}
351351

352-
public function test_should_return_default_value_if_evaluation_context_has_empty_string_targetingKey()
352+
public function test_should_return_default_value_if_evaluation_context_has_empty_string_targetingKey(): void
353353
{
354354
$mockClient = $this->createMock(Client::class);
355355
$mockResponse = new Response(200, [], json_encode([
@@ -379,7 +379,7 @@ public function test_should_return_default_value_if_evaluation_context_has_empty
379379
assertEquals('boolean_key', $got->getFlagKey());
380380
}
381381

382-
public function test_should_return_default_value_if_evaluation_context_has_null_targetingKey()
382+
public function test_should_return_default_value_if_evaluation_context_has_null_targetingKey(): void
383383
{
384384
$mockClient = $this->createMock(Client::class);
385385
$mockResponse = new Response(200, [], json_encode([
@@ -409,7 +409,7 @@ public function test_should_return_default_value_if_evaluation_context_has_null_
409409
assertEquals('boolean_key', $got->getFlagKey());
410410
}
411411

412-
public function test_should_return_default_value_if_flag_key_empty_string()
412+
public function test_should_return_default_value_if_flag_key_empty_string(): void
413413
{
414414
$mockClient = $this->createMock(Client::class);
415415
$mockResponse = new Response(200, [], json_encode([
@@ -439,7 +439,7 @@ public function test_should_return_default_value_if_flag_key_empty_string()
439439
assertEquals('', $got->getFlagKey());
440440
}
441441

442-
public function test_return_an_error_API_response_if_500()
442+
public function test_return_an_error_API_response_if_500(): void
443443
{
444444
$mockClient = $this->createMock(Client::class);
445445
$mockResponse = new Response(500, [], json_encode([]));
@@ -472,7 +472,7 @@ protected function setUp(): void
472472
$this->defaultEvaluationContext = new MutableEvaluationContext("214b796a-807b-4697-b3a3-42de0ec10a37", new Attributes(["email" => "contact@gofeatureflag.org"]));
473473
}
474474

475-
private function mockClient($provider, $mockClient)
475+
private function mockClient($provider, $mockClient): void
476476
{
477477
$providerReflection = new \ReflectionClass($provider);
478478
$ofrepApiProperty = $providerReflection->getProperty('ofrepApi');

0 commit comments

Comments
 (0)
Please sign in to comment.