Skip to content

Commit 012d55a

Browse files
Apply suggestions from code review
Co-authored-by: Matthew M. Keeler <keelerm84@gmail.com>
1 parent a2f63d7 commit 012d55a

File tree

2 files changed

+10
-24
lines changed

2 files changed

+10
-24
lines changed

src/LaunchDarkly/Integrations/TestData.php

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace LaunchDarkly\Integrations;
44

5-
use \LaunchDarkly\FeatureRequester;
6-
use \LaunchDarkly\Impl\Model\FeatureFlag;
7-
use \LaunchDarkly\Impl\Model\Segment;
5+
use LaunchDarkly\FeatureRequester;
6+
use LaunchDarkly\Impl\Model\FeatureFlag;
7+
use LaunchDarkly\Impl\Model\Segment;
88

99
define('TRUE_VARIATION_INDEX', 0);
1010
define('FALSE_VARIATION_INDEX', 1);
@@ -23,7 +23,6 @@ public function __construct()
2323
$this->_currentFlags = [];
2424
}
2525

26-
2726
/**
2827
* Gets the configuration for a specific feature flag.
2928
*
@@ -32,10 +31,7 @@ public function __construct()
3231
*/
3332
public function getFeature(string $key): ?FeatureFlag
3433
{
35-
if (array_key_exists($key, $this->_currentFlags)) {
36-
return $this->_currentFlags[$key];
37-
}
38-
return null;
34+
return $this->_currentFlags[$key] ?? null;
3935
}
4036

4137
/**
@@ -116,11 +112,9 @@ public function update(FlagBuilder $flagBuilder): TestData
116112
$key = $flagBuilder->getKey();
117113
$oldVersion = 0;
118114

119-
if (array_key_exists($key, $this->_currentFlags)) {
120-
$oldFlag = $this->_currentFlags[$key];
121-
if ($oldFlag) {
122-
$oldVersion = $oldFlag['version'];
123-
}
115+
$oldFlag = $this->_currentFlags[$key] ?? null;
116+
if ($oldFlag) {
117+
$oldVersion = $oldFlag['version'];
124118
}
125119

126120
$newFlag = $flagBuilder->build($oldVersion + 1);
@@ -167,7 +161,6 @@ public function __construct(string $key)
167161
$this->_rules = [];
168162
}
169163

170-
171164
/**
172165
* Returns the key of the Flag Builder
173166
*
@@ -365,10 +358,7 @@ public function variationForUser(string $userKey, $variation)
365358
$variationKeys = array_keys($this->_variations);
366359
foreach ($variationKeys as $idx) {
367360
if ($idx == $variationIndex) {
368-
$targetForVariation = [];
369-
if (array_key_exists($idx, $targets)) {
370-
$targetForVariation = $targets[$idx];
371-
}
361+
$targetForVariation = $targets[$idx] ?? [];
372362

373363
if (!in_array($userKey, $targetForVariation)) {
374364
array_push($targetForVariation, $userKey);
@@ -382,9 +372,7 @@ public function variationForUser(string $userKey, $variation)
382372
// Needs a strict check to ensure it doesn't eval to true
383373
// when index === 0
384374
if ($userKeyIdx !== false) {
385-
unset($targetForVariation[$userKeyIdx]);
386-
$targetForVariation = array_values($targetForVariation);
387-
$this->_targets[$idx] = $targetForVariation;
375+
$this->_targets[$idx] = array_splice($targetForVariation, $userKeyIdx, 1);
388376
}
389377
}
390378
}
@@ -551,7 +539,7 @@ public function build(int $version): array
551539
$baseFlagObject['rules'] = [];
552540

553541
foreach ($this->_rules as $idx => $rule) {
554-
array_push($baseFlagObject['rules'], $rule->build($idx));
542+
$baseFlagObject['rules'][] = $rule->build($idx);
555543
}
556544

557545
$baseFlagObject['deleted'] = false;

tests/Integrations/TestDataTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ public function testFlagConfigStringVariations()
133133
$this->assertEquals(['variation' => 2], $stringVariationFlag['fallthrough']);
134134
}
135135

136-
137-
138136
public function testUserTargets()
139137
{
140138
$td = new TestData();

0 commit comments

Comments
 (0)