Skip to content

Commit a239522

Browse files
authored
Minor cleanup and consistency changes (#79)
1 parent d537537 commit a239522

File tree

6 files changed

+18
-32
lines changed

6 files changed

+18
-32
lines changed

src/LaunchDarkly/FeatureFlagsState.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class FeatureFlagsState implements \JsonSerializable
2727
/**
2828
* @ignore
2929
*/
30-
public function __construct(bool $valid, array $flagValues = array(), array $flagMetadata = array())
30+
public function __construct(bool $valid)
3131
{
3232
$this->_valid = $valid;
3333
$this->_flagValues = array();

src/LaunchDarkly/Impl/Events/EventProcessor.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,12 @@ class EventProcessor
2424
/** @var int */
2525
private $_capacity;
2626

27-
/** @var int */
28-
private $_timeout;
29-
3027
public function __construct(string $sdkKey, array $options = array())
3128
{
3229
$this->_eventPublisher = $this->getEventPublisher($sdkKey, $options);
3330
$this->_eventSerializer = new EventSerializer($options);
3431

3532
$this->_capacity = $options['capacity'];
36-
$this->_timeout = $options['timeout'];
3733
}
3834

3935
public function __destruct()
@@ -55,7 +51,7 @@ public function enqueue(array $event): bool
5551
return false;
5652
}
5753

58-
array_push($this->_queue, $event);
54+
$this->_queue[] = $event;
5955

6056
return true;
6157
}

src/LaunchDarkly/Impl/Events/EventSerializer.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function serializeEvents(array $events): string
2727
{
2828
$filtered = array();
2929
foreach ($events as $e) {
30-
array_push($filtered, $this->filterEvent($e));
30+
$filtered[] = $this->filterEvent($e);
3131
}
3232
$ret = json_encode($filtered);
3333
if ($ret === false) {
@@ -54,9 +54,9 @@ private function filterAttrs(array $attrs, array &$json, ?array $userPrivateAttr
5454
foreach ($attrs as $key => $value) {
5555
if ($value != null) {
5656
if ($this->_allAttrsPrivate ||
57-
(!is_null($userPrivateAttrs) && array_search($key, $userPrivateAttrs) !== false) ||
58-
array_search($key, $this->_privateAttrNames) !== false) {
59-
$allPrivateAttrs[$key] = true;
57+
(!is_null($userPrivateAttrs) && in_array($key, $userPrivateAttrs)) ||
58+
in_array($key, $this->_privateAttrNames)) {
59+
$allPrivateAttrs[] = $key;
6060
} else {
6161
$json[$key] = $stringify ? strval($value) : $value;
6262
}
@@ -93,9 +93,8 @@ private function serializeUser(LDUser $user): array
9393
}
9494
}
9595
if (count($allPrivateAttrs)) {
96-
$pa = array_keys($allPrivateAttrs);
97-
sort($pa);
98-
$json['privateAttrs'] = $pa;
96+
sort($allPrivateAttrs);
97+
$json['privateAttrs'] = $allPrivateAttrs;
9998
}
10099
return $json;
101100
}

src/LaunchDarkly/Impl/Model/FeatureFlag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ private function checkPrerequisites(LDUser $user, FeatureRequester $featureReque
188188
if (!$prereqFeatureFlag->isOn() || $prereqEvalResult->getVariationIndex() !== $variation) {
189189
$prereqOk = false;
190190
}
191-
array_push($events, $eventFactory->newEvalEvent($prereqFeatureFlag, $user, $prereqEvalResult, null, $this));
191+
$events[] = $eventFactory->newEvalEvent($prereqFeatureFlag, $user, $prereqEvalResult, null, $this);
192192
}
193193
} catch (\Exception $e) {
194194
$prereqOk = false;

src/LaunchDarkly/LDUserBuilder.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function secondary(?string $secondary): LDUserBuilder
7575
*/
7676
public function privateSecondary(?string $secondary): LDUserBuilder
7777
{
78-
array_push($this->_privateAttributeNames, 'secondary');
78+
$this->_privateAttributeNames[] = 'secondary';
7979
return $this->secondary($secondary);
8080
}
8181

@@ -97,7 +97,7 @@ public function ip(?string $ip): LDUserBuilder
9797
*/
9898
public function privateIp(?string $ip): LDUserBuilder
9999
{
100-
array_push($this->_privateAttributeNames, 'ip');
100+
$this->_privateAttributeNames[] = 'ip';
101101
return $this->ip($ip);
102102
}
103103

@@ -123,7 +123,7 @@ public function country(?string $country): LDUserBuilder
123123
*/
124124
public function privateCountry(?string $country): LDUserBuilder
125125
{
126-
array_push($this->_privateAttributeNames, 'country');
126+
$this->_privateAttributeNames[] = 'country';
127127
return $this->country($country);
128128
}
129129

@@ -145,7 +145,7 @@ public function email(?string $email): LDUserBuilder
145145
*/
146146
public function privateEmail(?string $email): LDUserBuilder
147147
{
148-
array_push($this->_privateAttributeNames, 'email');
148+
$this->_privateAttributeNames[] = 'email';
149149
return $this->email($email);
150150
}
151151

@@ -167,7 +167,7 @@ public function name(?string $name): LDUserBuilder
167167
*/
168168
public function privateName(?string $name): LDUserBuilder
169169
{
170-
array_push($this->_privateAttributeNames, 'name');
170+
$this->_privateAttributeNames[] = 'name';
171171
return $this->name($name);
172172
}
173173

@@ -189,7 +189,7 @@ public function avatar(?string $avatar)
189189
*/
190190
public function privateAvatar(?string $avatar): LDUserBuilder
191191
{
192-
array_push($this->_privateAttributeNames, 'avatar');
192+
$this->_privateAttributeNames[] = 'avatar';
193193
return $this->avatar($avatar);
194194
}
195195

@@ -211,7 +211,7 @@ public function firstName(?string $firstName): LDUserBuilder
211211
*/
212212
public function privateFirstName(?string $firstName): LDUserBuilder
213213
{
214-
array_push($this->_privateAttributeNames, 'firstName');
214+
$this->_privateAttributeNames[] = 'firstName';
215215
return $this->firstName($firstName);
216216
}
217217

@@ -233,7 +233,7 @@ public function lastName(?string $lastName): LDUserBuilder
233233
*/
234234
public function privateLastName(?string $lastName): LDUserBuilder
235235
{
236-
array_push($this->_privateAttributeNames, 'lastName');
236+
$this->_privateAttributeNames[] = 'lastName';
237237
return $this->lastName($lastName);
238238
}
239239

@@ -284,7 +284,7 @@ public function customAttribute(string $customKey, $customValue): LDUserBuilder
284284
*/
285285
public function privateCustomAttribute(string $customKey, $customValue): LDUserBuilder
286286
{
287-
array_push($this->_privateAttributeNames, $customKey);
287+
$this->_privateAttributeNames[] = $customKey;
288288
return $this->customAttribute($customKey, $customValue);
289289
}
290290

tests/LDClientTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -675,13 +675,4 @@ public function testLoggerInterfaceWarn()
675675

676676
$client->variation('MyFeature', $user);
677677
}
678-
679-
private function getPrivateField(&$object, $fieldName)
680-
{
681-
$reflection = new \ReflectionClass(get_class($object));
682-
$field = $reflection->getProperty($fieldName);
683-
$field->setAccessible(true);
684-
685-
return $field->getValue($object);
686-
}
687678
}

0 commit comments

Comments
 (0)