Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

Commit 92fcc5e

Browse files
committed
phan fixes
1 parent 370a30f commit 92fcc5e

File tree

6 files changed

+15
-21
lines changed

6 files changed

+15
-21
lines changed

src/ServiceProvider.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
use Illuminate\Support\Facades\Blade;
66
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
7-
use MikeFrancis\LaravelUnleash\Unleash;
8-
use MikeFrancis\LaravelUnleash\Client;
97
use GuzzleHttp\ClientInterface;
108

119
class ServiceProvider extends IlluminateServiceProvider
@@ -42,6 +40,7 @@ public function boot()
4240
function (string $feature) {
4341
$client = app(Client::class);
4442
$unleash = app(Unleash::class, ['client' => $client]);
43+
assert($unleash instanceof Unleash);
4544

4645
return $unleash->isFeatureEnabled($feature);
4746
}
@@ -52,6 +51,7 @@ function (string $feature) {
5251
function (string $feature) {
5352
$client = app(Client::class);
5453
$unleash = app(Unleash::class, ['client' => $client]);
54+
assert($unleash instanceof Unleash);
5555

5656
return !$unleash->isFeatureEnabled($feature);
5757
}
@@ -60,8 +60,6 @@ function (string $feature) {
6060

6161
/**
6262
* Get the path to the config.
63-
*
64-
* @return string
6563
*/
6664
private function getConfigPath(): string
6765
{

src/Strategies/ApplicationHostnameStrategy.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Illuminate\Http\Request;
66
use Illuminate\Support\Arr;
7-
use Illuminate\Support\Str;
87
use MikeFrancis\LaravelUnleash\Strategies\Contracts\Strategy;
98

109
class ApplicationHostnameStrategy implements Strategy

src/Strategies/Contracts/DynamicStrategy.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ interface DynamicStrategy
99
/**
1010
* @param array $params Strategy Configuration from Unleash
1111
* @param Request $request Current Request
12-
* @param mixed $args An arbitrary number of arguments passed to isFeatureEnabled/Disabled
13-
* @return bool
12+
* @param mixed ...$args An arbitrary number of arguments passed to isFeatureEnabled/Disabled
1413
*/
1514
public function isEnabled(array $params, Request $request, ...$args): bool;
1615
}

src/Strategies/Contracts/Strategy.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ interface Strategy
99
/**
1010
* @param array $params Strategy Configuration from Unleash
1111
* @param Request $request Current Request
12-
* @return bool
1312
*/
1413
public function isEnabled(array $params, Request $request): bool;
1514
}

src/Strategies/DefaultStrategy.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
class DefaultStrategy implements Strategy
99
{
10+
/**
11+
* @unused-param $params
12+
* @unused-param $request
13+
*/
1014
public function isEnabled(array $params, Request $request): bool
1115
{
1216
return true;

src/Unleash.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@
22

33
namespace MikeFrancis\LaravelUnleash;
44

5-
use GuzzleHttp\ClientInterface;
6-
use GuzzleHttp\Exception\InvalidArgumentException;
5+
use GuzzleHttp\Client;
76
use GuzzleHttp\Exception\TransferException;
87
use Illuminate\Contracts\Cache\Repository as Cache;
98
use Illuminate\Contracts\Config\Repository as Config;
109
use Illuminate\Http\Request;
1110
use Illuminate\Support\Arr;
11+
use JsonException;
1212
use MikeFrancis\LaravelUnleash\Strategies\Contracts\DynamicStrategy;
1313
use MikeFrancis\LaravelUnleash\Strategies\Contracts\Strategy;
14-
use Symfony\Component\HttpFoundation\Exception\JsonException;
15-
16-
use function GuzzleHttp\json_decode;
1714

1815
class Unleash
1916
{
@@ -26,7 +23,7 @@ class Unleash
2623
protected $features;
2724
protected $expires;
2825

29-
public function __construct(ClientInterface $client, Cache $cache, Config $config, Request $request)
26+
public function __construct(Client $client, Cache $cache, Config $config, Request $request)
3027
{
3128
$this->client = $client;
3229
$this->cache = $cache;
@@ -109,7 +106,7 @@ public function isFeatureEnabled(string $name, ...$args): bool
109106

110107
$params = Arr::get($strategyData, 'parameters', []);
111108

112-
if ($strategy->isEnabled($params, $this->request, ...$args)) {
109+
if ($strategy->isEnabled($params, $this->request, ...$args)) { // @phan-suppress-current-line PhanParamTooManyUnpack
113110
return true;
114111
}
115112
}
@@ -124,7 +121,9 @@ public function isFeatureDisabled(string $name, ...$args): bool
124121

125122
public function refreshCache()
126123
{
127-
$this->fetchFeatures();
124+
if ($this->config->get('unleash.isEnabled') && $this->config->get('unleash.cache.isEnabled')) {
125+
$this->fetchFeatures();
126+
}
128127
}
129128

130129
protected function isFresh(): bool
@@ -156,11 +155,7 @@ protected function fetchFeatures(): array
156155
{
157156
$response = $this->client->get($this->config->get('unleash.featuresEndpoint'));
158157

159-
try {
160-
$data = json_decode((string)$response->getBody(), true, 512, \JSON_BIGINT_AS_STRING);
161-
} catch (InvalidArgumentException $e) {
162-
throw new JsonException('Could not decode unleash response body.', $e->getCode(), $e);
163-
}
158+
$data = (array) json_decode((string)$response->getBody(), true, 512, JSON_BIGINT_AS_STRING + JSON_THROW_ON_ERROR);
164159

165160
$data['expires'] = $this->setExpires();
166161

0 commit comments

Comments
 (0)