Skip to content

Commit

Permalink
fix: Use late static binding in AbstractProvider (#123)
Browse files Browse the repository at this point in the history
## 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]>
  • Loading branch information
schodemeiss authored May 7, 2024
1 parent 3ff3a59 commit 2123274
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/implementation/provider/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract class AbstractProvider implements Provider

public function getMetadata(): MetadataInterface
{
return new Metadata(self::$NAME);
return new Metadata(static::$NAME);
}

abstract public function resolveBooleanValue(string $flagKey, bool $defaultValue, ?EvaluationContext $context = null): ResolutionDetailsInterface;
Expand Down
13 changes: 3 additions & 10 deletions tests/TestProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,19 @@

namespace OpenFeature\Test;

use OpenFeature\implementation\common\Metadata;
use OpenFeature\implementation\provider\AbstractProvider;
use OpenFeature\implementation\provider\ResolutionDetailsFactory;
use OpenFeature\interfaces\common\Metadata as MetadataInterface;
use OpenFeature\interfaces\flags\EvaluationContext;
use OpenFeature\interfaces\hooks\HooksAwareTrait;
use OpenFeature\interfaces\provider\Provider;
use OpenFeature\interfaces\provider\ResolutionDetails;
use Psr\Log\LoggerAwareTrait;

class TestProvider implements Provider
class TestProvider extends AbstractProvider
{
use HooksAwareTrait;
use LoggerAwareTrait;

public const NAME = 'TestProvider';

public function getMetadata(): MetadataInterface
{
return new Metadata(self::NAME);
}
protected static string $NAME = 'TestProvider';

/**
* Resolves the flag value for the provided flag key as a boolean
Expand Down
3 changes: 0 additions & 3 deletions tests/unit/HooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ public function testEvaluationContextIsImmutableInAfterHooks(): void
[$mutationHook],
new HookHints(),
);
// @phpstan-ignore-next-line
$this->assertNull($additionalEvaluationContext);
}

Expand Down Expand Up @@ -175,7 +174,6 @@ public function testEvaluationContextIsImmutableInErrorHooks(): void
new HookHints(),
);

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

Expand Down Expand Up @@ -206,7 +204,6 @@ public function testEvaluationContextIsImmutableInFinallyHooks(): void
new HookHints(),
);

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

Expand Down

0 comments on commit 2123274

Please sign in to comment.