Skip to content

Commit

Permalink
Use newer phpstan and rector, use php 8.1 features (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage committed Dec 10, 2021
1 parent df4cd11 commit 5762565
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
"guzzlehttp/guzzle": "^7.0",
"cache/filesystem-adapter": "^1.1",
"friendsofphp/php-cs-fixer": "^3.0",
"phpstan/phpstan": "^0.12.90",
"phpstan/phpstan": "^1.2",
"jetbrains/phpstorm-attributes": "^1.0",
"rector/rector": "^0.11.46",
"rector/rector": "^0.12.7",
"phpunit/phpunit": "^9.5",
"symfony/http-client": "^5.0",
"nyholm/psr7": "^1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Client/DefaultRegistrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private function hasValidCacheRegistration(): bool
return false;
}

return $cache->get(CacheKey::REGISTRATION) ?? false;
return (bool) $cache->get(CacheKey::REGISTRATION);
}

private function storeCache(bool $result): void
Expand Down
3 changes: 1 addition & 2 deletions src/Configuration/UnleashConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public function __construct(
private array $headers = [],
private bool $autoRegistrationEnabled = true,
?Context $defaultContext = null,
private ?UnleashContextProvider $contextProvider = null,
private ?UnleashContextProvider $contextProvider = new DefaultUnleashContextProvider(),
) {
$this->contextProvider ??= new DefaultUnleashContextProvider();
if ($defaultContext !== null) {
$this->setDefaultContext($defaultContext);
}
Expand Down
3 changes: 2 additions & 1 deletion src/DTO/DefaultVariant.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getPayload(): ?VariantPayload
}

/**
* @phpstan-return array<string|bool|array>
* @phpstan-return array<string|bool|array<string>>
*/
#[ArrayShape(['name' => 'string', 'enabled' => 'bool', 'payload' => 'mixed'])]
public function jsonSerialize(): array
Expand All @@ -47,6 +47,7 @@ public function jsonSerialize(): array
];
if ($this->payload !== null) {
$result['payload'] = $this->payload->jsonSerialize();
assert(is_array($result['payload']));
}

return $result;
Expand Down
2 changes: 1 addition & 1 deletion src/DTO/DefaultVariantPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function fromJson(): array
);
}

return json_decode($this->value, true, 512, JSON_THROW_ON_ERROR);
return (array) json_decode($this->value, true, 512, JSON_THROW_ON_ERROR);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Helper/DefaultImplementationLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class DefaultImplementationLocator
];

/**
* @var array<string,array<string,array>>
* @var array<string,array<string,array<mixed>>>
*/
private array $defaultImplementations = [
'cache' => [
Expand Down
3 changes: 3 additions & 0 deletions src/Helper/StringStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ public function isReadable(): bool
return true;
}

/**
* @param int<0, max> $length
*/
public function read($length): string
{
if ($this->stream === null) {
Expand Down
1 change: 1 addition & 0 deletions src/Metrics/DefaultMetricsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ private function getOrCreateBucket(): MetricsBucket
$bucket = null;
if ($cache->has(CacheKey::METRICS_BUCKET)) {
$bucket = $cache->get(CacheKey::METRICS_BUCKET);
assert($bucket instanceof MetricsBucket || $bucket === null);
}

$bucket ??= new MetricsBucket(new DateTimeImmutable());
Expand Down
6 changes: 5 additions & 1 deletion src/Repository/DefaultUnleashRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ private function getCachedFeatures(): ?array
return null;
}

return $cache->get(CacheKey::FEATURES, []);
$result = $cache->get(CacheKey::FEATURES, []);
assert(is_array($result));

return $result;
}

/**
Expand All @@ -109,6 +112,7 @@ private function parseFeatures(string $rawBody): array
{
$features = [];
$body = json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR);
assert(is_array($body));
foreach ($body['features'] as $feature) {
$strategies = [];
$variants = [];
Expand Down

0 comments on commit 5762565

Please sign in to comment.