Skip to content

Commit d9a7fd9

Browse files
committed
Transpile to PHP 7.3
1 parent d3ed999 commit d9a7fd9

24 files changed

+421
-246
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.3"
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

+15-18
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,28 @@
1212
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD | Attribute::TARGET_CLASS)]
1313
final class IsEnabled implements ControllerAttribute
1414
{
15+
/**
16+
* @var string
17+
*/
18+
public $featureName;
19+
/**
20+
* @var int
21+
*/
22+
public $errorCode = Response::HTTP_NOT_FOUND;
1523
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-
) {
24+
string $featureName,
25+
#[\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])]
26+
int $errorCode = Response::HTTP_NOT_FOUND
27+
)
28+
{
29+
$this->featureName = $featureName;
30+
$this->errorCode = $errorCode;
2631
}
27-
2832
public function getFeatureName(): string
2933
{
3034
return $this->featureName;
3135
}
3236

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-
])]
4037
public function getErrorCode(): int
4138
{
4239
return $this->errorCode;

src/Attribute/IsNotEnabled.php

+15-18
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,28 @@
1212
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_METHOD | Attribute::TARGET_CLASS)]
1313
final class IsNotEnabled implements ControllerAttribute
1414
{
15+
/**
16+
* @var string
17+
*/
18+
public $featureName;
19+
/**
20+
* @var int
21+
*/
22+
public $errorCode = Response::HTTP_NOT_FOUND;
1523
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-
) {
24+
string $featureName,
25+
#[\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])]
26+
int $errorCode = Response::HTTP_NOT_FOUND
27+
)
28+
{
29+
$this->featureName = $featureName;
30+
$this->errorCode = $errorCode;
2631
}
27-
2832
public function getFeatureName(): string
2933
{
3034
return $this->featureName;
3135
}
3236

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-
])]
4037
public function getErrorCode(): int
4138
{
4239
return $this->errorCode;

src/Command/TestFlagCommand.php

+62-47
Original file line numberDiff line numberDiff line change
@@ -16,70 +16,85 @@
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+
* @var \Unleash\Client\Unleash
22+
*/
23+
private $unleash;
24+
/**
25+
* @readonly
26+
* @var \Psr\SimpleCache\CacheInterface
27+
*/
28+
private $cache;
29+
public function __construct(string $name, Unleash $unleash, CacheInterface $cache)
30+
{
31+
$this->unleash = $unleash;
32+
$this->cache = $cache;
2433
parent::__construct($name);
2534
}
26-
2735
protected function configure(): void
2836
{
2937
$this
3038
->setDescription('Check the status of an Unleash feature')
3139
->addArgument(
32-
name: 'flag',
33-
mode: InputArgument::REQUIRED,
34-
description: 'The name of the feature flag to check the result for',
40+
'flag',
41+
InputArgument::REQUIRED,
42+
'The name of the feature flag to check the result for',
3543
)
3644
->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',
45+
'force',
46+
'f',
47+
InputOption::VALUE_NONE,
48+
'When this flag is present, fresh results without cache will be forced',
4149
)
4250
->addOption(
43-
name: 'user-id',
44-
mode: InputOption::VALUE_REQUIRED,
45-
description: "[Context] Provide the current user's ID",
46-
default: null,
51+
'user-id',
52+
null,
53+
InputOption::VALUE_REQUIRED,
54+
"[Context] Provide the current user's ID",
55+
null,
4756
)
4857
->addOption(
49-
name: 'ip-address',
50-
mode: InputOption::VALUE_REQUIRED,
51-
description: '[Context] Provide the current IP address',
52-
default: null,
58+
'ip-address',
59+
null,
60+
InputOption::VALUE_REQUIRED,
61+
'[Context] Provide the current IP address',
62+
null,
5363
)
5464
->addOption(
55-
name: 'session-id',
56-
mode: InputOption::VALUE_REQUIRED,
57-
description: '[Context] Provide the current session ID',
58-
default: null,
65+
'session-id',
66+
null,
67+
InputOption::VALUE_REQUIRED,
68+
'[Context] Provide the current session ID',
69+
null,
5970
)
6071
->addOption(
61-
name: 'hostname',
62-
mode: InputOption::VALUE_REQUIRED,
63-
description: '[Context] Provide the current hostname',
64-
default: null,
72+
'hostname',
73+
null,
74+
InputOption::VALUE_REQUIRED,
75+
'[Context] Provide the current hostname',
76+
null,
6577
)
6678
->addOption(
67-
name: 'environment',
68-
mode: InputOption::VALUE_REQUIRED,
69-
description: '[Context] Provide the current environment',
70-
default: null,
79+
'environment',
80+
null,
81+
InputOption::VALUE_REQUIRED,
82+
'[Context] Provide the current environment',
83+
null,
7184
)
7285
->addOption(
73-
name: 'current-time',
74-
mode: InputOption::VALUE_REQUIRED,
75-
description: '[Context] Provide the current date and time',
76-
default: null,
86+
'current-time',
87+
null,
88+
InputOption::VALUE_REQUIRED,
89+
'[Context] Provide the current date and time',
90+
null,
7791
)
7892
->addOption(
7993
'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,
94+
null,
95+
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
96+
'[Context] Custom context values in the format [contextName]=[contextValue], for example: myCustomContextField=someValue',
97+
null,
8398
)
8499
->addOption( // must use positional arguments, because $suggestedValues is not a real argument
85100
'expected',
@@ -159,13 +174,13 @@ private function createContext(InputInterface $input): Context
159174
assert($currentTime === null || is_string($currentTime));
160175

161176
return new UnleashContext(
162-
currentUserId: $userId,
163-
ipAddress: $ipAddress,
164-
sessionId: $sessionId,
165-
customContext: $customContext,
166-
hostname: $hostname,
167-
environment: $environment,
168-
currentTime: $currentTime,
177+
$userId,
178+
$ipAddress,
179+
$sessionId,
180+
$customContext,
181+
$hostname,
182+
$environment,
183+
$currentTime,
169184
);
170185
}
171186
}

src/Context/SymfonyContextProvider.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
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+
* @var \Unleash\Client\Bundle\Context\SymfonyUnleashContext
13+
*/
14+
private $context;
15+
public function __construct(SymfonyUnleashContext $context)
16+
{
17+
$this->context = $context;
1318
}
1419

1520
public function getContext(): Context

0 commit comments

Comments
 (0)