Skip to content

Commit fa02eff

Browse files
committed
Fix: Run 'composer cs'
1 parent 0b620b9 commit fa02eff

15 files changed

+320
-314
lines changed

integration-tests/LDDFeatureRequesterTest.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
use Predis\Client;
1010
use LaunchDarkly\ApcuLDDFeatureRequester;
1111

12-
class LDDFeatureRetrieverTest extends \PHPUnit_Framework_TestCase {
12+
class LDDFeatureRetrieverTest extends \PHPUnit_Framework_TestCase
13+
{
1314
const API_KEY = 'BOGUS_API_KEY';
1415

15-
public function testGet() {
16+
public function testGet()
17+
{
1618
$redis = new Client(array(
1719
"scheme" => "tcp",
1820
"host" => 'localhost',
@@ -27,7 +29,8 @@ public function testGet() {
2729
$this->assertEquals("bar", $client->variation('foo', $user, 'jim'));
2830
}
2931

30-
public function testGetApc() {
32+
public function testGetApc()
33+
{
3134
if (!extension_loaded('apc')) {
3235
self::markTestSkipped('Install `apc` extension to run this test.');
3336
}
@@ -53,7 +56,8 @@ public function testGetApc() {
5356
$this->assertEquals("baz", $client->variation('foo', $user, 'jim'));
5457
}
5558

56-
public function testGetApcu() {
59+
public function testGetApcu()
60+
{
5761
if (!extension_loaded('apcu')) {
5862
self::markTestSkipped('Install `apcu` extension to run this test.');
5963
}
@@ -121,7 +125,8 @@ public function testGetAll()
121125
$this->assertEquals($featureValue, $allFlags[$featureKey]);
122126
}
123127

124-
private function gen_feature($key, $val) {
128+
private function gen_feature($key, $val)
129+
{
125130
$data = [
126131
'name' => 'Feature ' . $key,
127132
'key' => $key,
@@ -171,6 +176,4 @@ private function gen_feature($key, $val) {
171176

172177
return \json_encode($data);
173178
}
174-
175179
}
176-

src/LaunchDarkly/EventProcessor.php

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ class EventProcessor
1212
private $_capacity;
1313
private $_timeout;
1414

15-
public function __construct($sdkKey, $options = array()) {
16-
$this->_eventPublisher = $this->getEventPublisher($sdkKey, $options);
17-
$this->_eventSerializer = new EventSerializer($options);
15+
public function __construct($sdkKey, $options = array())
16+
{
17+
$this->_eventPublisher = $this->getEventPublisher($sdkKey, $options);
18+
$this->_eventSerializer = new EventSerializer($options);
1819

19-
$this->_capacity = $options['capacity'];
20-
$this->_timeout = $options['timeout'];
20+
$this->_capacity = $options['capacity'];
21+
$this->_timeout = $options['timeout'];
2122

22-
$this->_queue = array();
23+
$this->_queue = array();
2324
}
2425

2526
public function __destruct()
@@ -43,44 +44,44 @@ public function enqueue($event)
4344
return true;
4445
}
4546

46-
/**
47-
* Publish events to LaunchDarkly
48-
* @return bool Whether the events were successfully published
49-
*/
50-
public function flush()
51-
{
52-
if (empty($this->_queue)) {
53-
return null;
54-
}
47+
/**
48+
* Publish events to LaunchDarkly
49+
* @return bool Whether the events were successfully published
50+
*/
51+
public function flush()
52+
{
53+
if (empty($this->_queue)) {
54+
return null;
55+
}
5556

56-
$payload = $this->_eventSerializer->serializeEvents($this->_queue);
57+
$payload = $this->_eventSerializer->serializeEvents($this->_queue);
5758

58-
// We don't expect flush to be called more than once per request cycle, but let's empty the queue just in case
59-
$this->_queue = array();
59+
// We don't expect flush to be called more than once per request cycle, but let's empty the queue just in case
60+
$this->_queue = array();
6061

61-
return $this->_eventPublisher->publish($payload);
62-
}
62+
return $this->_eventPublisher->publish($payload);
63+
}
6364

64-
/**
65-
* @param string $sdkKey
66-
* @param mixed[] $options
67-
* @return EventPublisher
68-
*/
69-
private function getEventPublisher($sdkKey, array $options)
70-
{
71-
if (isset($options['event_publisher']) && $options['event_publisher'] instanceof EventPublisher) {
72-
return $options['event_publisher'];
73-
}
65+
/**
66+
* @param string $sdkKey
67+
* @param mixed[] $options
68+
* @return EventPublisher
69+
*/
70+
private function getEventPublisher($sdkKey, array $options)
71+
{
72+
if (isset($options['event_publisher']) && $options['event_publisher'] instanceof EventPublisher) {
73+
return $options['event_publisher'];
74+
}
7475

75-
if (isset($options['event_publisher_class'])) {
76-
$eventPublisherClass = $options['event_publisher_class'];
77-
} else {
78-
$eventPublisherClass = CurlEventPublisher::class;
79-
}
76+
if (isset($options['event_publisher_class'])) {
77+
$eventPublisherClass = $options['event_publisher_class'];
78+
} else {
79+
$eventPublisherClass = CurlEventPublisher::class;
80+
}
8081

81-
if (!is_a($eventPublisherClass, EventPublisher::class, true)) {
82-
throw new \InvalidArgumentException;
83-
}
84-
return new $eventPublisherClass($sdkKey, $options);
85-
}
82+
if (!is_a($eventPublisherClass, EventPublisher::class, true)) {
83+
throw new \InvalidArgumentException;
84+
}
85+
return new $eventPublisherClass($sdkKey, $options);
86+
}
8687
}

src/LaunchDarkly/EventSerializer.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
class EventSerializer
88
{
9-
109
private $_allAttrsPrivate;
1110
private $_privateAttrNames;
1211

@@ -31,8 +30,7 @@ private function filterEvent($e)
3130
foreach ($e as $key => $value) {
3231
if ($key == 'user') {
3332
$ret[$key] = $this->serializeUser($value);
34-
}
35-
else {
33+
} else {
3634
$ret[$key] = $value;
3735
}
3836
}
@@ -44,11 +42,10 @@ private function filterAttrs($attrs, &$json, $userPrivateAttrs, &$allPrivateAttr
4442
foreach ($attrs as $key => $value) {
4543
if ($value != null) {
4644
if ($this->_allAttrsPrivate ||
47-
array_search($key, $userPrivateAttrs) !== FALSE ||
48-
array_search($key, $this->_privateAttrNames) !== FALSE) {
45+
array_search($key, $userPrivateAttrs) !== false ||
46+
array_search($key, $this->_privateAttrNames) !== false) {
4947
$allPrivateAttrs[$key] = true;
50-
}
51-
else {
48+
} else {
5249
$json[$key] = $value;
5350
}
5451
}

src/LaunchDarkly/GuzzleFeatureRequester.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ public function getAllFeatures()
113113
}
114114
}
115115

116-
private function handleUnexpectedStatus($code, $method) {
116+
private function handleUnexpectedStatus($code, $method)
117+
{
117118
$this->_logger->error("$method received an unexpected HTTP status code $code");
118119
if ($code == 401) {
119120
throw new InvalidSDKKeyException();

src/LaunchDarkly/LDClient.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ protected function _get_default($key, $default)
352352
}
353353
}
354354

355-
protected function handleInvalidSDKKey() {
355+
protected function handleInvalidSDKKey()
356+
{
356357
$this->_logger->error("Received 401 error, no further HTTP requests will be made during lifetime of LDClient since SDK key is invalid");
357358
$this->_offline = true;
358359
}

src/LaunchDarkly/LDUserBuilder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public function privateSecondary($secondary)
4747
/**
4848
* Sets the IP for a user.
4949
*/
50-
public function ip($ip){
50+
public function ip($ip)
51+
{
5152
$this->_ip = $ip;
5253
return $this;
5354
}

src/LaunchDarkly/Operators.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ public static function parseTime($in)
137137
* @param $in
138138
* @return null|string
139139
*/
140-
public static function parseSemVer($in) {
140+
public static function parseSemVer($in)
141+
{
141142
try {
142143
return SemanticVersion::parse($in, true);
143144
} catch (\InvalidArgumentException $e) {

src/LaunchDarkly/SemanticVersion.php

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
*/
1111
class SemanticVersion
1212
{
13-
private static $REGEX = '/^(?<major>0|[1-9]\d*)(\.(?<minor>0|[1-9]\d*))?(\.(?<patch>0|[1-9]\d*))?(\-(?<prerel>[0-9A-Za-z\-\.]+))?(\+(?<build>[0-9A-Za-z\-\.]+))?$/';
13+
private static $REGEX = '/^(?<major>0|[1-9]\d*)(\.(?<minor>0|[1-9]\d*))?(\.(?<patch>0|[1-9]\d*))?(\-(?<prerel>[0-9A-Za-z\-\.]+))?(\+(?<build>[0-9A-Za-z\-\.]+))?$/';
1414

15-
/** @var int */
15+
/** @var int */
1616
public $major;
1717
/** @var int */
1818
public $minor;
@@ -25,11 +25,11 @@ class SemanticVersion
2525

2626
public function __construct($major, $minor, $patch, $prerelease, $build)
2727
{
28-
$this->major = $major;
29-
$this->minor = $minor;
30-
$this->patch = $patch;
31-
$this->prerelease = $prerelease;
32-
$this->build = $build;
28+
$this->major = $major;
29+
$this->minor = $minor;
30+
$this->patch = $patch;
31+
$this->prerelease = $prerelease;
32+
$this->build = $build;
3333
}
3434

3535
/**
@@ -41,18 +41,18 @@ public function __construct($major, $minor, $patch, $prerelease, $build)
4141
*/
4242
public static function parse($input, $loose = false)
4343
{
44-
if (!preg_match(self::$REGEX, $input, $matches)) {
45-
throw new \InvalidArgumentException("not a valid semantic version");
46-
}
47-
$major = intval($matches['major']);
48-
if (!$loose && (!array_key_exists('minor', $matches) || !array_key_exists('patch', $matches))) {
49-
throw new \InvalidArgumentException("not a valid semantic version: minor and patch versions are required");
50-
}
51-
$minor = array_key_exists('minor', $matches) ? intval($matches['minor']) : 0;
52-
$patch = array_key_exists('patch', $matches) ? intval($matches['patch']) : 0;
53-
$prerelease = array_key_exists('prerel', $matches) ? $matches['prerel'] : '';
54-
$build = array_key_exists('build', $matches) ? $matches['build'] : '';
55-
return new SemanticVersion($major, $minor, $patch, $prerelease, $build);
44+
if (!preg_match(self::$REGEX, $input, $matches)) {
45+
throw new \InvalidArgumentException("not a valid semantic version");
46+
}
47+
$major = intval($matches['major']);
48+
if (!$loose && (!array_key_exists('minor', $matches) || !array_key_exists('patch', $matches))) {
49+
throw new \InvalidArgumentException("not a valid semantic version: minor and patch versions are required");
50+
}
51+
$minor = array_key_exists('minor', $matches) ? intval($matches['minor']) : 0;
52+
$patch = array_key_exists('patch', $matches) ? intval($matches['patch']) : 0;
53+
$prerelease = array_key_exists('prerel', $matches) ? $matches['prerel'] : '';
54+
$build = array_key_exists('build', $matches) ? $matches['build'] : '';
55+
return new SemanticVersion($major, $minor, $patch, $prerelease, $build);
5656
}
5757

5858
/**
@@ -63,59 +63,59 @@ public static function parse($input, $loose = false)
6363
*/
6464
public function comparePrecedence($other)
6565
{
66-
if ($this->major != $other->major) {
67-
return ($this->major < $other->major) ? -1 : 1;
68-
}
69-
if ($this->minor != $other->minor) {
70-
return ($this->minor < $other->minor) ? -1 : 1;
71-
}
72-
if ($this->patch != $other->patch) {
73-
return ($this->patch < $other->patch) ? -1 : 1;
74-
}
75-
if ($this->prerelease != $other->prerelease) {
76-
// *no* prerelease component always has a higher precedence than *any* prerelease component
77-
if ($this->prerelease == '') {
78-
return 1;
79-
}
80-
if ($other->prerelease == '') {
81-
return -1;
82-
}
83-
return self::compareIdentifiers(explode('.', $this->prerelease), explode('.', $other->prerelease));
84-
}
85-
// build metadata is always ignored in precedence comparison
86-
return 0;
66+
if ($this->major != $other->major) {
67+
return ($this->major < $other->major) ? -1 : 1;
68+
}
69+
if ($this->minor != $other->minor) {
70+
return ($this->minor < $other->minor) ? -1 : 1;
71+
}
72+
if ($this->patch != $other->patch) {
73+
return ($this->patch < $other->patch) ? -1 : 1;
74+
}
75+
if ($this->prerelease != $other->prerelease) {
76+
// *no* prerelease component always has a higher precedence than *any* prerelease component
77+
if ($this->prerelease == '') {
78+
return 1;
79+
}
80+
if ($other->prerelease == '') {
81+
return -1;
82+
}
83+
return self::compareIdentifiers(explode('.', $this->prerelease), explode('.', $other->prerelease));
84+
}
85+
// build metadata is always ignored in precedence comparison
86+
return 0;
8787
}
8888

8989
private static function compareIdentifiers($ids1, $ids2)
9090
{
91-
for ($i = 0; ; $i++) {
92-
if ($i >= count($ids1)) {
93-
// x.y is always less than x.y.z
94-
return ($i >= count($ids2)) ? 0 : -1;
95-
}
96-
if ($i >= count($ids2)) {
97-
return 1;
98-
}
99-
$v1 = $ids1[$i];
100-
$v2 = $ids2[$i];
101-
// each sub-identifier is compared numerically if both are numeric; if both are non-numeric,
102-
// they're compared as strings; otherwise, the numeric one is the lesser one
103-
$isNum1 = is_numeric($v1);
104-
$isNum2 = is_numeric($v2);
105-
if ($isNum1 && $isNum2) {
106-
$n1 = intval($v1);
107-
$n2 = intval($v2);
108-
$d = ($n1 == $n2) ? 0 : (($n1 < $n2) ? -1 : 1);
109-
} else {
110-
if ($isNum1 || $isNum2) {
111-
$d = $isNum1 ? -1 : 1;
112-
} else {
113-
$d = ($v1 == $v2) ? 0 : (($v1 < $v2) ? -1 : 1);
114-
}
115-
}
116-
if ($d != 0) {
117-
return $d;
118-
}
119-
}
91+
for ($i = 0; ; $i++) {
92+
if ($i >= count($ids1)) {
93+
// x.y is always less than x.y.z
94+
return ($i >= count($ids2)) ? 0 : -1;
95+
}
96+
if ($i >= count($ids2)) {
97+
return 1;
98+
}
99+
$v1 = $ids1[$i];
100+
$v2 = $ids2[$i];
101+
// each sub-identifier is compared numerically if both are numeric; if both are non-numeric,
102+
// they're compared as strings; otherwise, the numeric one is the lesser one
103+
$isNum1 = is_numeric($v1);
104+
$isNum2 = is_numeric($v2);
105+
if ($isNum1 && $isNum2) {
106+
$n1 = intval($v1);
107+
$n2 = intval($v2);
108+
$d = ($n1 == $n2) ? 0 : (($n1 < $n2) ? -1 : 1);
109+
} else {
110+
if ($isNum1 || $isNum2) {
111+
$d = $isNum1 ? -1 : 1;
112+
} else {
113+
$d = ($v1 == $v2) ? 0 : (($v1 < $v2) ? -1 : 1);
114+
}
115+
}
116+
if ($d != 0) {
117+
return $d;
118+
}
119+
}
120120
}
121121
}

0 commit comments

Comments
 (0)