Skip to content

Commit 4de6e1f

Browse files
authored
(U2C #4) use PHP 8 type declarations and strict mode (#105)
1 parent 116a6c6 commit 4de6e1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+401
-537
lines changed

src/LaunchDarkly/EvaluationDetail.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace LaunchDarkly;
46

57
/**
@@ -9,22 +11,17 @@
911
*/
1012
class EvaluationDetail
1113
{
12-
/** @var int|null */
13-
private $_variationIndex = null;
14-
15-
/** @var mixed|null */
16-
private $_value = null;
17-
18-
/** @var EvaluationReason */
19-
private $_reason;
14+
private ?int $_variationIndex = null;
15+
private mixed $_value = null;
16+
private EvaluationReason $_reason;
2017

2118
/**
2219
* EvaluationDetail constructor.
23-
* @param mixed|null $value the value of the flag variation
20+
* @param mixed $value the value of the flag variation
2421
* @param int|null $variationIndex the index of the flag variation, or null if it was the default value
2522
* @param EvaluationReason $reason evaluation reason properties
2623
*/
27-
public function __construct($value, ?int $variationIndex, EvaluationReason $reason)
24+
public function __construct(mixed $value, ?int $variationIndex, EvaluationReason $reason)
2825
{
2926
$this->_value = $value;
3027
$this->_variationIndex = $variationIndex;
@@ -36,7 +33,7 @@ public function __construct($value, ?int $variationIndex, EvaluationReason $reas
3633
*
3734
* @return mixed
3835
*/
39-
public function getValue()
36+
public function getValue(): mixed
4037
{
4138
return $this->_value;
4239
}

src/LaunchDarkly/EvaluationReason.php

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace LaunchDarkly;
46

57
/**
@@ -81,23 +83,12 @@ class EvaluationReason implements \JsonSerializable
8183
*/
8284
const EXCEPTION_ERROR = 'EXCEPTION';
8385

84-
/** @var string */
85-
private $_kind;
86-
87-
/** @var string|null */
88-
private $_errorKind;
89-
90-
/** @var int|null */
91-
private $_ruleIndex;
92-
93-
/** @var string|null */
94-
private $_ruleId;
95-
96-
/** @var string|null */
97-
private $_prerequisiteKey;
98-
99-
/** @var bool */
100-
private $_inExperiment;
86+
private string $_kind;
87+
private ?string $_errorKind;
88+
private ?int $_ruleIndex;
89+
private ?string $_ruleId;
90+
private ?string $_prerequisiteKey;
91+
private bool $_inExperiment;
10192

10293
/**
10394
* Creates a new instance of the OFF reason.
@@ -228,7 +219,7 @@ public function getPrerequisiteKey(): ?string
228219
/**
229220
* Returns true if the evaluation resulted in an experiment rollout *and* served
230221
* one of the variations in the experiment. Otherwise it returns false.
231-
* @return boolean
222+
* @return bool
232223
*/
233224
public function isInExperiment(): bool
234225
{

src/LaunchDarkly/EventPublisher.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace LaunchDarkly;
46

57
/**

src/LaunchDarkly/FeatureFlagsState.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace LaunchDarkly;
46

57
use LaunchDarkly\Impl\Model\FeatureFlag;
@@ -15,14 +17,9 @@
1517
*/
1618
class FeatureFlagsState implements \JsonSerializable
1719
{
18-
/** @var bool */
19-
protected $_valid = false;
20-
21-
/** @var array */
22-
protected $_flagValues;
23-
24-
/** @var array<string, array{debugEventsUntilDate?: int|null, reason?: EvaluationReason, trackEvents?: true, variation?: int|null, version?: int}> **/
25-
protected $_flagMetadata;
20+
protected bool $_valid = false;
21+
protected array $_flagValues;
22+
protected array $_flagMetadata;
2623

2724
/**
2825
* @ignore
@@ -100,7 +97,7 @@ public function isValid(): bool
10097
* @param string $key the feature flag key
10198
* @return mixed the flag's value; null if the flag returned the default value, or if there was no such flag
10299
*/
103-
public function getFlagValue(string $key)
100+
public function getFlagValue(string $key): mixed
104101
{
105102
return isset($this->_flagValues[$key]) ? $this->_flagValues[$key] : null;
106103
}

src/LaunchDarkly/FeatureRequester.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace LaunchDarkly;
46

57
use LaunchDarkly\Impl\Model\FeatureFlag;

src/LaunchDarkly/Impl/EvalResult.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace LaunchDarkly\Impl;
46

57
use LaunchDarkly\EvaluationDetail;
@@ -12,10 +14,8 @@
1214
*/
1315
class EvalResult
1416
{
15-
/** @var EvaluationDetail */
16-
private $_detail;
17-
/** @var array */
18-
private $_prerequisiteEvents = [];
17+
private EvaluationDetail $_detail;
18+
private array $_prerequisiteEvents = [];
1919

2020
public function __construct(EvaluationDetail $detail, array $prerequisiteEvents)
2121
{

src/LaunchDarkly/Impl/Events/EventFactory.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace LaunchDarkly\Impl\Events;
46

57
use LaunchDarkly\EvaluationDetail;
@@ -13,8 +15,7 @@
1315
*/
1416
class EventFactory
1517
{
16-
/** @var boolean */
17-
private $_withReasons;
18+
private bool $_withReasons;
1819

1920
public function __construct(bool $withReasons)
2021
{
@@ -25,16 +26,16 @@ public function __construct(bool $withReasons)
2526
* @param FeatureFlag $flag
2627
* @param LDUser $user
2728
* @param EvaluationDetail $detail
28-
* @param mixed|null $default
29+
* @param mixed $default
2930
* @param FeatureFlag|null $prereqOfFlag
30-
* @return (mixed|null)[]
31+
* @return mixed[]
3132
*/
3233
public function newEvalEvent(
3334
FeatureFlag $flag,
3435
LDUser $user,
3536
EvaluationDetail $detail,
36-
$default,
37-
$prereqOfFlag = null
37+
mixed $default,
38+
?FeatureFlag $prereqOfFlag = null
3839
): array {
3940
$addExperimentData = $flag->isExperiment($detail->getReason());
4041
$e = [
@@ -67,7 +68,7 @@ public function newEvalEvent(
6768
}
6869

6970
/**
70-
* @return (mixed|null)[]
71+
* @return mixed[]
7172
*/
7273
public function newDefaultEvent(FeatureFlag $flag, LDUser $user, EvaluationDetail $detail): array
7374
{
@@ -97,7 +98,7 @@ public function newDefaultEvent(FeatureFlag $flag, LDUser $user, EvaluationDetai
9798
}
9899

99100
/**
100-
* @return (mixed|null)[]
101+
* @return mixed[]
101102
*/
102103
public function newUnknownFlagEvent(string $key, LDUser $user, EvaluationDetail $detail): array
103104
{
@@ -120,7 +121,7 @@ public function newUnknownFlagEvent(string $key, LDUser $user, EvaluationDetail
120121
}
121122

122123
/**
123-
* @return (mixed|null)[]
124+
* @return mixed[]
124125
*/
125126
public function newIdentifyEvent(LDUser $user): array
126127
{
@@ -135,12 +136,12 @@ public function newIdentifyEvent(LDUser $user): array
135136
/**
136137
* @param string $eventName
137138
* @param LDUser $user
138-
* @param mixed|null $data
139-
* @param null|numeric $metricValue
139+
* @param mixed $data
140+
* @param int|float|null $metricValue
140141
*
141-
* @return (mixed|null)[]
142+
* @return mixed[]
142143
*/
143-
public function newCustomEvent(string $eventName, LDUser $user, $data, $metricValue): array
144+
public function newCustomEvent(string $eventName, LDUser $user, mixed $data, int|float|null $metricValue): array
144145
{
145146
$e = [
146147
'kind' => 'custom',

src/LaunchDarkly/Impl/Events/EventProcessor.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace LaunchDarkly\Impl\Events;
46

57
use LaunchDarkly\EventPublisher;
@@ -13,17 +15,10 @@
1315
*/
1416
class EventProcessor
1517
{
16-
/** @var EventPublisher */
17-
private $_eventPublisher;
18-
19-
/** @var EventSerializer */
20-
private $_eventSerializer;
21-
22-
/** @var array */
23-
private $_queue = [];
24-
25-
/** @var int */
26-
private $_capacity;
18+
private EventPublisher $_eventPublisher;
19+
private EventSerializer $_eventSerializer;
20+
private array $_queue = [];
21+
private int $_capacity;
2722

2823
/**
2924
* @psalm-param array{capacity: int} $options
@@ -47,7 +42,7 @@ public function sendEvent(array $event): bool
4742
}
4843

4944
/**
50-
* @param (int|mixed|string|true)[] $event
45+
* @param mixed[] $event
5146
*/
5247
public function enqueue(array $event): bool
5348
{

src/LaunchDarkly/Impl/Events/EventSerializer.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace LaunchDarkly\Impl\Events;
46

57
use LaunchDarkly\LDUser;
@@ -12,11 +14,8 @@
1214
*/
1315
class EventSerializer
1416
{
15-
/** @var bool */
16-
private $_allAttrsPrivate;
17-
18-
/** @var array */
19-
private $_privateAttrNames;
17+
private bool $_allAttrsPrivate;
18+
private array $_privateAttrNames;
2019

2120
public function __construct(array $options)
2221
{

src/LaunchDarkly/Impl/Events/NullEventProcessor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace LaunchDarkly\Impl\Events;
46

57
/**
@@ -8,7 +10,7 @@
810
*/
911
class NullEventProcessor extends EventProcessor
1012
{
11-
public function enqueue($event): bool
13+
public function enqueue(array $event): bool
1214
{
1315
return true;
1416
}

0 commit comments

Comments
 (0)