Skip to content

Commit 2123274

Browse files
authored
fix: Use late static binding in AbstractProvider (#123)
## This PR Switches from self::$NAME to static::$NAME in the getMetadata method of the AbstractProvider class. This change is to ensure the name of the extending provider is used in the metadata. Previously, when extending from AbstractProvider, the metadata name was always AbstractProvider. ### How to test Create a class that extends AbstractProvider, give it a different name, then call "getMetadata" and see that the name is now the name of the extended class and not "AbstractProvider" Signed-off-by: Andrew Menino-Barlow <[email protected]>
1 parent 3ff3a59 commit 2123274

File tree

3 files changed

+4
-14
lines changed

3 files changed

+4
-14
lines changed

src/implementation/provider/AbstractProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ abstract class AbstractProvider implements Provider
2323

2424
public function getMetadata(): MetadataInterface
2525
{
26-
return new Metadata(self::$NAME);
26+
return new Metadata(static::$NAME);
2727
}
2828

2929
abstract public function resolveBooleanValue(string $flagKey, bool $defaultValue, ?EvaluationContext $context = null): ResolutionDetailsInterface;

tests/TestProvider.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,19 @@
44

55
namespace OpenFeature\Test;
66

7-
use OpenFeature\implementation\common\Metadata;
7+
use OpenFeature\implementation\provider\AbstractProvider;
88
use OpenFeature\implementation\provider\ResolutionDetailsFactory;
9-
use OpenFeature\interfaces\common\Metadata as MetadataInterface;
109
use OpenFeature\interfaces\flags\EvaluationContext;
1110
use OpenFeature\interfaces\hooks\HooksAwareTrait;
12-
use OpenFeature\interfaces\provider\Provider;
1311
use OpenFeature\interfaces\provider\ResolutionDetails;
1412
use Psr\Log\LoggerAwareTrait;
1513

16-
class TestProvider implements Provider
14+
class TestProvider extends AbstractProvider
1715
{
1816
use HooksAwareTrait;
1917
use LoggerAwareTrait;
2018

21-
public const NAME = 'TestProvider';
22-
23-
public function getMetadata(): MetadataInterface
24-
{
25-
return new Metadata(self::NAME);
26-
}
19+
protected static string $NAME = 'TestProvider';
2720

2821
/**
2922
* Resolves the flag value for the provided flag key as a boolean

tests/unit/HooksTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ public function testEvaluationContextIsImmutableInAfterHooks(): void
143143
[$mutationHook],
144144
new HookHints(),
145145
);
146-
// @phpstan-ignore-next-line
147146
$this->assertNull($additionalEvaluationContext);
148147
}
149148

@@ -175,7 +174,6 @@ public function testEvaluationContextIsImmutableInErrorHooks(): void
175174
new HookHints(),
176175
);
177176

178-
//@phpstan-ignore-next-line
179177
$this->assertNull($additionalEvaluationContext);
180178
}
181179

@@ -206,7 +204,6 @@ public function testEvaluationContextIsImmutableInFinallyHooks(): void
206204
new HookHints(),
207205
);
208206

209-
// @phpstan-ignore-next-line
210207
$this->assertNull($additionalEvaluationContext);
211208
}
212209

0 commit comments

Comments
 (0)