Skip to content

Commit

Permalink
Chore: Add Override attribute to all overriding methods
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage committed May 20, 2024
1 parent 477bb2f commit 8758393
Show file tree
Hide file tree
Showing 68 changed files with 252 additions and 2 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,6 @@
'phpdoc_order' => true,
'phpdoc_scalar' => true,
'phpdoc_separation' => true,
'global_namespace_import' => true,
])
->setFinder($finder);
2 changes: 2 additions & 0 deletions src/Bootstrap/CompoundBootstrapProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Exception;
use JsonSerializable;
use Override;
use Traversable;
use Unleash\Client\Exception\CompoundException;

Expand All @@ -23,6 +24,7 @@ public function __construct(
/**
* @return array<mixed>|JsonSerializable|Traversable<mixed>|null
*/
#[Override]
public function getBootstrap(): array|JsonSerializable|Traversable|null
{
$exceptions = [];
Expand Down
2 changes: 2 additions & 0 deletions src/Bootstrap/DefaultBootstrapHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
namespace Unleash\Client\Bootstrap;

use JsonException;
use Override;
use Traversable;

final readonly class DefaultBootstrapHandler implements BootstrapHandler
{
/**
* @throws JsonException
*/
#[Override]
public function getBootstrapContents(BootstrapProvider $provider): ?string
{
$bootstrap = $provider->getBootstrap();
Expand Down
2 changes: 2 additions & 0 deletions src/Bootstrap/EmptyBootstrapProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
namespace Unleash\Client\Bootstrap;

use JsonSerializable;
use Override;
use Traversable;

final readonly class EmptyBootstrapProvider implements BootstrapProvider
{
#[Override]
public function getBootstrap(): array|JsonSerializable|Traversable|null
{
return null;
Expand Down
2 changes: 2 additions & 0 deletions src/Bootstrap/FileBootstrapProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use InvalidArgumentException;
use JsonException;
use Override;
use RuntimeException;
use SplFileInfo;
use Throwable;
Expand All @@ -22,6 +23,7 @@ public function __construct(
*
* @return array<mixed>
*/
#[Override]
public function getBootstrap(): array
{
$filePath = $this->getFilePath($this->file);
Expand Down
2 changes: 2 additions & 0 deletions src/Bootstrap/JsonBootstrapProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Unleash\Client\Bootstrap;

use JsonException;
use Override;
use Unleash\Client\Exception\InvalidValueException;

final readonly class JsonBootstrapProvider implements BootstrapProvider
Expand All @@ -17,6 +18,7 @@ public function __construct(
*
* @return array<mixed>
*/
#[Override]
public function getBootstrap(): array
{
$result = @json_decode($this->json, true);
Expand Down
2 changes: 2 additions & 0 deletions src/Bootstrap/JsonSerializableBootstrapProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Unleash\Client\Bootstrap;

use JsonSerializable;
use Override;
use Traversable;

final readonly class JsonSerializableBootstrapProvider implements BootstrapProvider
Expand All @@ -18,6 +19,7 @@ public function __construct(
/**
* @return array<mixed>|JsonSerializable|Traversable<mixed>
*/
#[Override]
public function getBootstrap(): array|JsonSerializable|Traversable
{
return $this->data;
Expand Down
2 changes: 2 additions & 0 deletions src/Client/DefaultRegistrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use DateTimeImmutable;
use Exception;
use JsonException;
use Override;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
Expand Down Expand Up @@ -33,6 +34,7 @@ public function __construct(
* @throws JsonException
* @throws ClientExceptionInterface
*/
#[Override]
public function register(iterable $strategyHandlers): bool
{
if (!$this->configuration->isFetchingEnabled()) {
Expand Down
20 changes: 20 additions & 0 deletions src/Configuration/UnleashContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use DateTimeImmutable;
use DateTimeInterface;
use Override;
use Unleash\Client\Enum\ContextField;
use Unleash\Client\Enum\Stickiness;
use Unleash\Client\Exception\InvalidValueException;
Expand All @@ -26,26 +27,31 @@ public function __construct(
$this->setCurrentTime($currentTime);
}

#[Override]
public function getCurrentUserId(): ?string
{
return $this->currentUserId;
}

#[Override]
public function getEnvironment(): ?string
{
return $this->environment;
}

#[Override]
public function getIpAddress(): ?string
{
return $this->ipAddress ?? $_SERVER['REMOTE_ADDR'] ?? null;
}

#[Override]
public function getSessionId(): ?string
{
return $this->sessionId ?? (session_id() ?: null);
}

#[Override]
public function getCustomProperty(string $name): string
{
if (!array_key_exists($name, $this->customContext)) {
Expand All @@ -55,18 +61,21 @@ public function getCustomProperty(string $name): string
return $this->customContext[$name];
}

#[Override]
public function setCustomProperty(string $name, ?string $value): self
{
$this->customContext[$name] = $value ?? '';

return $this;
}

#[Override]
public function hasCustomProperty(string $name): bool
{
return array_key_exists($name, $this->customContext);
}

#[Override]
public function removeCustomProperty(string $name, bool $silent = true): self
{
if (!$this->hasCustomProperty($name) && !$silent) {
Expand All @@ -78,39 +87,45 @@ public function removeCustomProperty(string $name, bool $silent = true): self
return $this;
}

#[Override]
public function setCurrentUserId(?string $currentUserId): self
{
$this->currentUserId = $currentUserId;

return $this;
}

#[Override]
public function setIpAddress(?string $ipAddress): self
{
$this->ipAddress = $ipAddress;

return $this;
}

#[Override]
public function setSessionId(?string $sessionId): self
{
$this->sessionId = $sessionId;

return $this;
}

#[Override]
public function setEnvironment(?string $environment): self
{
$this->environment = $environment;

return $this;
}

#[Override]
public function getHostname(): ?string
{
return $this->findContextValue(ContextField::HOSTNAME) ?? (gethostname() ?: null);
}

#[Override]
public function setHostname(?string $hostname): self
{
if ($hostname === null) {
Expand All @@ -125,6 +140,7 @@ public function setHostname(?string $hostname): self
/**
* @param array<string> $values
*/
#[Override]
public function hasMatchingFieldValue(string $fieldName, array $values): bool
{
$fieldValue = $this->findContextValue($fieldName);
Expand All @@ -135,6 +151,7 @@ public function hasMatchingFieldValue(string $fieldName, array $values): bool
return in_array($fieldValue, $values, true);
}

#[Override]
public function findContextValue(string $fieldName): ?string
{
return match ($fieldName) {
Expand All @@ -147,6 +164,7 @@ public function findContextValue(string $fieldName): ?string
};
}

#[Override]
public function getCurrentTime(): DateTimeInterface
{
if (!$this->hasCustomProperty('currentTime')) {
Expand All @@ -156,6 +174,7 @@ public function getCurrentTime(): DateTimeInterface
return new DateTimeImmutable($this->getCustomProperty('currentTime'));
}

#[Override]
public function setCurrentTime(DateTimeInterface|string|null $time): self
{
if ($time === null) {
Expand All @@ -171,6 +190,7 @@ public function setCurrentTime(DateTimeInterface|string|null $time): self
/**
* @return array<string, string>
*/
#[Override]
public function getCustomProperties(): array
{
return $this->customContext;
Expand Down
2 changes: 2 additions & 0 deletions src/ConstraintValidator/DefaultConstraintValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Unleash\Client\ConstraintValidator;

use Override;
use Unleash\Client\Configuration\Context;
use Unleash\Client\ConstraintValidator\Operator\Date\DateAfterOperatorValidator;
use Unleash\Client\ConstraintValidator\Operator\Date\DateBeforeOperatorValidator;
Expand All @@ -24,6 +25,7 @@

final class DefaultConstraintValidator implements ConstraintValidator
{
#[Override]
public function validateConstraint(Constraint $constraint, Context $context): bool
{
$field = $constraint->getContextName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Unleash\Client\ConstraintValidator\Operator;

use Override;
use Unleash\Client\Exception\OperatorValidatorException;

/**
Expand All @@ -12,6 +13,7 @@ abstract class AbstractOperatorValidator implements OperatorValidator
/**
* @param array<mixed>|string|null $allowedValues
*/
#[Override]
public function __invoke(string $currentValue, array|string|null $allowedValues): bool
{
if ($allowedValues === null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
use DateTimeImmutable;
use DateTimeInterface;
use Exception;
use Override;
use Unleash\Client\ConstraintValidator\Operator\AbstractOperatorValidator;

/**
* @internal
*/
abstract class AbstractDateOperatorValidator extends AbstractOperatorValidator
{
#[Override]
protected function acceptsValues(array|string $values): bool
{
if (!is_string($values)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Unleash\Client\ConstraintValidator\Operator\Date;

use Override;

/**
* @internal
*/
final class DateAfterOperatorValidator extends AbstractDateOperatorValidator
{
#[Override]
protected function validate(string $currentValue, array|string $searchInValue): bool
{
assert(is_string($searchInValue));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Unleash\Client\ConstraintValidator\Operator\Date;

use Override;

/**
* @internal
*/
final class DateBeforeOperatorValidator extends AbstractDateOperatorValidator
{
#[Override]
protected function validate(string $currentValue, array|string $searchInValue): bool
{
assert(is_string($searchInValue));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

namespace Unleash\Client\ConstraintValidator\Operator\Lists;

use Override;
use Unleash\Client\ConstraintValidator\Operator\AbstractOperatorValidator;

/**
* @internal
*/
abstract class AbstractListOperatorValidator extends AbstractOperatorValidator
{
#[Override]
protected function acceptsValues(array|string $values): bool
{
return is_array($values) && array_is_list($values);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Unleash\Client\ConstraintValidator\Operator\Lists;

use Override;

/**
* @internal
*/
final class InListOperatorValidator extends AbstractListOperatorValidator
{
#[Override]
protected function validate(string $currentValue, array|string $searchInValue): bool
{
assert(is_array($searchInValue));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Unleash\Client\ConstraintValidator\Operator\Lists;

use Override;

/**
* @internal
*/
final class NotInListOperatorValidator extends AbstractListOperatorValidator
{
#[Override]
protected function validate(string $currentValue, array|string $searchInValue): bool
{
assert(is_array($searchInValue));
Expand Down
Loading

0 comments on commit 8758393

Please sign in to comment.