22
33namespace 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
99define ('TRUE_VARIATION_INDEX ' , 0 );
1010define ('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 ;
0 commit comments