Skip to content

Commit

Permalink
Chore: Remove deprecations (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage authored Nov 3, 2023
1 parent d60019b commit 76747af
Show file tree
Hide file tree
Showing 57 changed files with 204 additions and 578 deletions.
11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"psr/simple-cache-implementation": "^1.0 | ^2.0 | ^3.0",
"lastguest/murmurhash": "^2.1",
"psr/http-message": "^1.0 | ^2.0",
"php-http/discovery": "^1.14"
"php-http/discovery": "^1.14",
"symfony/event-dispatcher": "^5.0 | ^6.0"
},
"autoload": {
"psr-4": {
Expand All @@ -36,8 +37,7 @@
"phpunit/phpunit": "^9.5",
"symfony/http-client": "^5.0 | ^6.0",
"nyholm/psr7": "^1.0",
"symfony/cache": "^5.0 | ^6.0",
"symfony/event-dispatcher": "^5.0 | ^6.0"
"symfony/cache": "^5.0 | ^6.0"
},
"autoload-dev": {
"psr-4": {
Expand All @@ -55,5 +55,10 @@
"fixer": "php-cs-fixer fix --verbose --allow-risky=yes",
"phpstan": "phpstan analyse --level=max src",
"phpunit": "phpunit"
},
"config": {
"allow-plugins": {
"php-http/discovery": true
}
}
}
4 changes: 2 additions & 2 deletions src/Bootstrap/CompoundBootstrapProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
use Traversable;
use Unleash\Client\Exception\CompoundException;

final class CompoundBootstrapProvider implements BootstrapProvider
final readonly class CompoundBootstrapProvider implements BootstrapProvider
{
/**
* @var BootstrapProvider[]
*/
private readonly array $bootstrapProviders;
private array $bootstrapProviders;

public function __construct(
BootstrapProvider ...$bootstrapProviders
Expand Down
2 changes: 1 addition & 1 deletion src/Bootstrap/DefaultBootstrapHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use JsonException;
use Traversable;

final class DefaultBootstrapHandler implements BootstrapHandler
final readonly class DefaultBootstrapHandler implements BootstrapHandler
{
/**
* @throws JsonException
Expand Down
2 changes: 1 addition & 1 deletion src/Bootstrap/EmptyBootstrapProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use JsonSerializable;
use Traversable;

final class EmptyBootstrapProvider implements BootstrapProvider
final readonly class EmptyBootstrapProvider implements BootstrapProvider
{
public function getBootstrap(): array|JsonSerializable|Traversable|null
{
Expand Down
4 changes: 2 additions & 2 deletions src/Bootstrap/FileBootstrapProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
use Throwable;
use Unleash\Client\Exception\InvalidValueException;

final class FileBootstrapProvider implements BootstrapProvider
final readonly class FileBootstrapProvider implements BootstrapProvider
{
public function __construct(
private readonly string|SplFileInfo $file,
private string|SplFileInfo $file,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Bootstrap/JsonBootstrapProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
use JsonException;
use Unleash\Client\Exception\InvalidValueException;

final class JsonBootstrapProvider implements BootstrapProvider
final readonly class JsonBootstrapProvider implements BootstrapProvider
{
public function __construct(
private readonly string $json,
private string $json,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Bootstrap/JsonSerializableBootstrapProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
use JsonSerializable;
use Traversable;

final class JsonSerializableBootstrapProvider implements BootstrapProvider
final readonly class JsonSerializableBootstrapProvider implements BootstrapProvider
{
/**
* @param JsonSerializable|array<mixed>|Traversable<mixed> $data
*/
public function __construct(
private readonly JsonSerializable|array|Traversable $data,
private JsonSerializable|array|Traversable $data,
) {
}

Expand Down
28 changes: 17 additions & 11 deletions src/Configuration/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@

use DateTimeInterface;

/**
* @todo move to required methods in next major
*
* @method string|null getHostname()
* @method string|null getEnvironment()
* @method DateTimeInterface getCurrentTime()
* @method Context setHostname(string|null $hostname)
* @method Context setEnvironment(string|null $environment)
* @method Context setCurrentTime(DateTimeInterface|null $time)
* @method array<string, string> getCustomProperties()
*/
interface Context
{
public function getCurrentUserId(): ?string;
Expand Down Expand Up @@ -46,4 +35,21 @@ public function setSessionId(?string $sessionId): self;
public function hasMatchingFieldValue(string $fieldName, array $values): bool;

public function findContextValue(string $fieldName): ?string;

public function getHostname(): ?string;

public function setHostname(?string $hostname): self;

public function getEnvironment(): ?string;

public function setEnvironment(?string $environment): self;

public function getCurrentTime(): DateTimeInterface;

public function setCurrentTime(?DateTimeInterface $time): self;

/**
* @return array<string, string>
*/
public function getCustomProperties(): array;
}
62 changes: 9 additions & 53 deletions src/Configuration/UnleashConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@

namespace Unleash\Client\Configuration;

use JetBrains\PhpStorm\Deprecated;
use JetBrains\PhpStorm\Pure;
use LogicException;
use Psr\SimpleCache\CacheInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Unleash\Client\Bootstrap\BootstrapHandler;
use Unleash\Client\Bootstrap\BootstrapProvider;
use Unleash\Client\Bootstrap\DefaultBootstrapHandler;
use Unleash\Client\Bootstrap\EmptyBootstrapProvider;
use Unleash\Client\ContextProvider\DefaultUnleashContextProvider;
use Unleash\Client\ContextProvider\SettableUnleashContextProvider;
use Unleash\Client\ContextProvider\UnleashContextProvider;
use Unleash\Client\Helper\EventDispatcher;

final class UnleashConfiguration
{
Expand All @@ -31,25 +29,16 @@ public function __construct(
private bool $metricsEnabled = true,
private array $headers = [],
private bool $autoRegistrationEnabled = true,
// todo remove in next major version
?Context $defaultContext = null,
// todo remove nullability in next major version
private ?UnleashContextProvider $contextProvider = null,
// todo remove nullability in next major version
private ?BootstrapHandler $bootstrapHandler = null,
// todo remove nullability in next major version
private ?BootstrapProvider $bootstrapProvider = null,
private UnleashContextProvider $contextProvider = new DefaultUnleashContextProvider(),
private BootstrapHandler $bootstrapHandler = new DefaultBootstrapHandler(),
private BootstrapProvider $bootstrapProvider = new EmptyBootstrapProvider(),
private bool $fetchingEnabled = true,
// todo remove nullability in next major version
private ?EventDispatcherInterface $eventDispatcher = null,
private EventDispatcherInterface $eventDispatcher = new EventDispatcher(),
private int $staleTtl = 30 * 60,
private ?CacheInterface $staleCache = null,
private ?string $proxyKey = null,
) {
$this->contextProvider ??= new DefaultUnleashContextProvider();
if ($defaultContext !== null) {
$this->setDefaultContext($defaultContext);
}
}

public function getCache(): CacheInterface
Expand Down Expand Up @@ -204,25 +193,8 @@ public function getDefaultContext(): Context
return $this->getContextProvider()->getContext();
}

/**
* @todo remove on next major version
*/
#[Deprecated(reason: 'Support for context provider was added, default context logic should be handled in a provider')]
public function setDefaultContext(?Context $defaultContext): self
{
if ($this->getContextProvider() instanceof SettableUnleashContextProvider) {
$this->getContextProvider()->setDefaultContext($defaultContext ?? new UnleashContext());
} else {
throw new LogicException("Default context cannot be set via configuration for a context provider that doesn't implement SettableUnleashContextProvider");
}

return $this;
}

public function getContextProvider(): UnleashContextProvider
{
assert($this->contextProvider !== null);

return $this->contextProvider;
}

Expand All @@ -236,7 +208,7 @@ public function setContextProvider(UnleashContextProvider $contextProvider): sel
#[Pure]
public function getBootstrapHandler(): BootstrapHandler
{
return $this->bootstrapHandler ?? new DefaultBootstrapHandler();
return $this->bootstrapHandler;
}

public function setBootstrapHandler(BootstrapHandler $bootstrapHandler): self
Expand All @@ -249,7 +221,7 @@ public function setBootstrapHandler(BootstrapHandler $bootstrapHandler): self
#[Pure]
public function getBootstrapProvider(): BootstrapProvider
{
return $this->bootstrapProvider ?? new EmptyBootstrapProvider();
return $this->bootstrapProvider;
}

public function setBootstrapProvider(BootstrapProvider $bootstrapProvider): self
Expand All @@ -271,28 +243,12 @@ public function setFetchingEnabled(bool $fetchingEnabled): self
return $this;
}

#[Deprecated('This method has been deprecated and will be removed in next major version')]
public function getEventDispatcher(): EventDispatcher
{
if ($this->eventDispatcher === null) {
return new EventDispatcher(null);
}
if ($this->eventDispatcher instanceof EventDispatcher) {
return $this->eventDispatcher;
}

return new EventDispatcher($this->eventDispatcher);
}

/**
* @internal
*/
public function getEventDispatcherOrNull(): ?EventDispatcherInterface
public function getEventDispatcher(): EventDispatcherInterface
{
return $this->eventDispatcher;
}

public function setEventDispatcher(?EventDispatcherInterface $eventDispatcher): self
public function setEventDispatcher(EventDispatcherInterface $eventDispatcher): self
{
$this->eventDispatcher = $eventDispatcher;

Expand Down
20 changes: 2 additions & 18 deletions src/ContextProvider/DefaultUnleashContextProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,11 @@
use Unleash\Client\Configuration\Context;
use Unleash\Client\Configuration\UnleashContext;

final class DefaultUnleashContextProvider implements UnleashContextProvider, SettableUnleashContextProvider
final readonly class DefaultUnleashContextProvider implements UnleashContextProvider
{
public function __construct(private ?Context $defaultContext = null)
{
}

#[Pure]
public function getContext(): Context
{
return $this->defaultContext ? clone $this->defaultContext : new UnleashContext();
}

/**
* @todo remove in next major version
*
* @internal
*/
public function setDefaultContext(Context $context): self
{
$this->defaultContext = $context;

return $this;
return new UnleashContext();
}
}
15 changes: 0 additions & 15 deletions src/ContextProvider/SettableUnleashContextProvider.php

This file was deleted.

13 changes: 6 additions & 7 deletions src/DTO/Constraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
use JetBrains\PhpStorm\ExpectedValues;
use Unleash\Client\Enum\ConstraintOperator;

/**
* @todo move to required methods in next major
*
* @method string|null getSingleValue()
* @method bool isInverted()
* @method bool isCaseInsensitive()
*/
interface Constraint
{
public function getContextName(): string;
Expand All @@ -23,4 +16,10 @@ public function getOperator(): string;
* @return array<string>|null
*/
public function getValues(): ?array;

public function getSingleValue(): ?string;

public function isInverted(): bool;

public function isCaseInsensitive(): bool;
}
14 changes: 7 additions & 7 deletions src/DTO/DefaultConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
use JetBrains\PhpStorm\ExpectedValues;
use Unleash\Client\Enum\ConstraintOperator;

final class DefaultConstraint implements Constraint
final readonly class DefaultConstraint implements Constraint
{
/**
* @param array<string> $values
*/
public function __construct(
private readonly string $contextName,
private string $contextName,
#[ExpectedValues(valuesFromClass: ConstraintOperator::class)]
private readonly string $operator,
private readonly ?array $values = null,
private readonly ?string $singleValue = null,
private readonly bool $inverted = false,
private readonly bool $caseInsensitive = false,
private string $operator,
private ?array $values = null,
private ?string $singleValue = null,
private bool $inverted = false,
private bool $caseInsensitive = false,
) {
}

Expand Down
12 changes: 6 additions & 6 deletions src/DTO/DefaultFeature.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace Unleash\Client\DTO;

final class DefaultFeature implements Feature
final readonly class DefaultFeature implements Feature
{
/**
* @param iterable<Strategy> $strategies
* @param array<Variant> $variants
*/
public function __construct(
private readonly string $name,
private readonly bool $enabled,
private readonly iterable $strategies,
private readonly array $variants = [],
private readonly bool $impressionData = false,
private string $name,
private bool $enabled,
private iterable $strategies,
private array $variants = [],
private bool $impressionData = false,
) {
}

Expand Down
Loading

0 comments on commit 76747af

Please sign in to comment.