Skip to content

Commit 7747f4a

Browse files
committed
Transpile to PHP 7.4
1 parent a1bbd01 commit 7747f4a

23 files changed

+321
-228
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"symfony/cache": "^5.0 | ^6.0 | ^7.0",
1010
"nyholm/psr7": "^1.0",
1111
"unleash/client": "^2.4",
12-
"php": "^8.2"
12+
"php": "^7.4"
1313
},
1414
"autoload": {
1515
"psr-4": {

src/Attribute/ControllerAttribute.php

-7
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,5 @@ interface ControllerAttribute
1212
{
1313
public function getFeatureName(): string;
1414

15-
#[ExpectedValues([
16-
Response::HTTP_NOT_FOUND,
17-
Response::HTTP_FORBIDDEN,
18-
Response::HTTP_BAD_REQUEST,
19-
Response::HTTP_UNAUTHORIZED,
20-
Response::HTTP_SERVICE_UNAVAILABLE,
21-
])]
2215
public function getErrorCode(): int;
2316
}

src/Attribute/IsEnabled.php

+9-18
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,22 @@
1212
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD | Attribute::TARGET_CLASS)]
1313
final class IsEnabled implements ControllerAttribute
1414
{
15+
public string $featureName;
16+
public int $errorCode = Response::HTTP_NOT_FOUND;
1517
public function __construct(
16-
public string $featureName,
17-
#[ExpectedValues([
18-
Response::HTTP_NOT_FOUND,
19-
Response::HTTP_FORBIDDEN,
20-
Response::HTTP_BAD_REQUEST,
21-
Response::HTTP_UNAUTHORIZED,
22-
Response::HTTP_SERVICE_UNAVAILABLE,
23-
])]
24-
public int $errorCode = Response::HTTP_NOT_FOUND,
25-
) {
18+
string $featureName,
19+
#[\JetBrains\PhpStorm\ExpectedValues([\Symfony\Component\HttpFoundation\Response::HTTP_NOT_FOUND, \Symfony\Component\HttpFoundation\Response::HTTP_FORBIDDEN, \Symfony\Component\HttpFoundation\Response::HTTP_BAD_REQUEST, \Symfony\Component\HttpFoundation\Response::HTTP_UNAUTHORIZED, \Symfony\Component\HttpFoundation\Response::HTTP_SERVICE_UNAVAILABLE])]
20+
int $errorCode = Response::HTTP_NOT_FOUND
21+
)
22+
{
23+
$this->featureName = $featureName;
24+
$this->errorCode = $errorCode;
2625
}
27-
2826
public function getFeatureName(): string
2927
{
3028
return $this->featureName;
3129
}
3230

33-
#[ExpectedValues([
34-
Response::HTTP_NOT_FOUND,
35-
Response::HTTP_FORBIDDEN,
36-
Response::HTTP_BAD_REQUEST,
37-
Response::HTTP_UNAUTHORIZED,
38-
Response::HTTP_SERVICE_UNAVAILABLE,
39-
])]
4031
public function getErrorCode(): int
4132
{
4233
return $this->errorCode;

src/Attribute/IsNotEnabled.php

+9-18
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,22 @@
1212
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD | Attribute::TARGET_CLASS)]
1313
final class IsNotEnabled implements ControllerAttribute
1414
{
15+
public string $featureName;
16+
public int $errorCode = Response::HTTP_NOT_FOUND;
1517
public function __construct(
16-
public string $featureName,
17-
#[ExpectedValues([
18-
Response::HTTP_NOT_FOUND,
19-
Response::HTTP_FORBIDDEN,
20-
Response::HTTP_BAD_REQUEST,
21-
Response::HTTP_UNAUTHORIZED,
22-
Response::HTTP_SERVICE_UNAVAILABLE,
23-
])]
24-
public int $errorCode = Response::HTTP_NOT_FOUND,
25-
) {
18+
string $featureName,
19+
#[\JetBrains\PhpStorm\ExpectedValues([\Symfony\Component\HttpFoundation\Response::HTTP_NOT_FOUND, \Symfony\Component\HttpFoundation\Response::HTTP_FORBIDDEN, \Symfony\Component\HttpFoundation\Response::HTTP_BAD_REQUEST, \Symfony\Component\HttpFoundation\Response::HTTP_UNAUTHORIZED, \Symfony\Component\HttpFoundation\Response::HTTP_SERVICE_UNAVAILABLE])]
20+
int $errorCode = Response::HTTP_NOT_FOUND
21+
)
22+
{
23+
$this->featureName = $featureName;
24+
$this->errorCode = $errorCode;
2625
}
27-
2826
public function getFeatureName(): string
2927
{
3028
return $this->featureName;
3129
}
3230

33-
#[ExpectedValues([
34-
Response::HTTP_NOT_FOUND,
35-
Response::HTTP_FORBIDDEN,
36-
Response::HTTP_BAD_REQUEST,
37-
Response::HTTP_UNAUTHORIZED,
38-
Response::HTTP_SERVICE_UNAVAILABLE,
39-
])]
4031
public function getErrorCode(): int
4132
{
4233
return $this->errorCode;

src/Command/TestFlagCommand.php

+60-47
Original file line numberDiff line numberDiff line change
@@ -16,70 +16,83 @@
1616

1717
final class TestFlagCommand extends Command
1818
{
19-
public function __construct(
20-
string $name,
21-
private readonly Unleash $unleash,
22-
private readonly CacheInterface $cache,
23-
) {
19+
/**
20+
* @readonly
21+
*/
22+
private Unleash $unleash;
23+
/**
24+
* @readonly
25+
*/
26+
private CacheInterface $cache;
27+
public function __construct(string $name, Unleash $unleash, CacheInterface $cache)
28+
{
29+
$this->unleash = $unleash;
30+
$this->cache = $cache;
2431
parent::__construct($name);
2532
}
26-
2733
protected function configure(): void
2834
{
2935
$this
3036
->setDescription('Check the status of an Unleash feature')
3137
->addArgument(
32-
name: 'flag',
33-
mode: InputArgument::REQUIRED,
34-
description: 'The name of the feature flag to check the result for',
38+
'flag',
39+
InputArgument::REQUIRED,
40+
'The name of the feature flag to check the result for',
3541
)
3642
->addOption(
37-
name: 'force',
38-
shortcut: 'f',
39-
mode: InputOption::VALUE_NONE,
40-
description: 'When this flag is present, fresh results without cache will be forced',
43+
'force',
44+
'f',
45+
InputOption::VALUE_NONE,
46+
'When this flag is present, fresh results without cache will be forced',
4147
)
4248
->addOption(
43-
name: 'user-id',
44-
mode: InputOption::VALUE_REQUIRED,
45-
description: "[Context] Provide the current user's ID",
46-
default: null,
49+
'user-id',
50+
null,
51+
InputOption::VALUE_REQUIRED,
52+
"[Context] Provide the current user's ID",
53+
null,
4754
)
4855
->addOption(
49-
name: 'ip-address',
50-
mode: InputOption::VALUE_REQUIRED,
51-
description: '[Context] Provide the current IP address',
52-
default: null,
56+
'ip-address',
57+
null,
58+
InputOption::VALUE_REQUIRED,
59+
'[Context] Provide the current IP address',
60+
null,
5361
)
5462
->addOption(
55-
name: 'session-id',
56-
mode: InputOption::VALUE_REQUIRED,
57-
description: '[Context] Provide the current session ID',
58-
default: null,
63+
'session-id',
64+
null,
65+
InputOption::VALUE_REQUIRED,
66+
'[Context] Provide the current session ID',
67+
null,
5968
)
6069
->addOption(
61-
name: 'hostname',
62-
mode: InputOption::VALUE_REQUIRED,
63-
description: '[Context] Provide the current hostname',
64-
default: null,
70+
'hostname',
71+
null,
72+
InputOption::VALUE_REQUIRED,
73+
'[Context] Provide the current hostname',
74+
null,
6575
)
6676
->addOption(
67-
name: 'environment',
68-
mode: InputOption::VALUE_REQUIRED,
69-
description: '[Context] Provide the current environment',
70-
default: null,
77+
'environment',
78+
null,
79+
InputOption::VALUE_REQUIRED,
80+
'[Context] Provide the current environment',
81+
null,
7182
)
7283
->addOption(
73-
name: 'current-time',
74-
mode: InputOption::VALUE_REQUIRED,
75-
description: '[Context] Provide the current date and time',
76-
default: null,
84+
'current-time',
85+
null,
86+
InputOption::VALUE_REQUIRED,
87+
'[Context] Provide the current date and time',
88+
null,
7789
)
7890
->addOption(
7991
'custom-context',
80-
mode: InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
81-
description: '[Context] Custom context values in the format [contextName]=[contextValue], for example: myCustomContextField=someValue',
82-
default: null,
92+
null,
93+
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
94+
'[Context] Custom context values in the format [contextName]=[contextValue], for example: myCustomContextField=someValue',
95+
null,
8396
)
8497
->addOption( // must use positional arguments, because $suggestedValues is not a real argument
8598
'expected',
@@ -159,13 +172,13 @@ private function createContext(InputInterface $input): Context
159172
assert($currentTime === null || is_string($currentTime));
160173

161174
return new UnleashContext(
162-
currentUserId: $userId,
163-
ipAddress: $ipAddress,
164-
sessionId: $sessionId,
165-
customContext: $customContext,
166-
hostname: $hostname,
167-
environment: $environment,
168-
currentTime: $currentTime,
175+
$userId,
176+
$ipAddress,
177+
$sessionId,
178+
$customContext,
179+
$hostname,
180+
$environment,
181+
$currentTime,
169182
);
170183
}
171184
}

src/Context/SymfonyContextProvider.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
use Unleash\Client\Configuration\Context;
66
use Unleash\Client\ContextProvider\UnleashContextProvider;
77

8-
final readonly class SymfonyContextProvider implements UnleashContextProvider
8+
final class SymfonyContextProvider implements UnleashContextProvider
99
{
10-
public function __construct(
11-
private SymfonyUnleashContext $context
12-
) {
10+
/**
11+
* @readonly
12+
*/
13+
private SymfonyUnleashContext $context;
14+
public function __construct(SymfonyUnleashContext $context)
15+
{
16+
$this->context = $context;
1317
}
1418

1519
public function getContext(): Context

0 commit comments

Comments
 (0)