Skip to content

Commit ec054e4

Browse files
authored
Merge pull request #87 from valerianpereira/feature/PSR2_Standards
PSR2 Sonar fixes
2 parents 42a6672 + e72722e commit ec054e4

File tree

3 files changed

+48
-27
lines changed

3 files changed

+48
-27
lines changed

src/LaunchDarkly/Clause.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace LaunchDarkly;
44

5-
class Clause {
5+
class Clause
6+
{
67
/** @var string */
78
private $_attribute = null;
89
/** @var string */
@@ -12,14 +13,16 @@ class Clause {
1213
/** @var bool */
1314
private $_negate = false;
1415

15-
private function __construct($attribute, $op, array $values, $negate) {
16+
private function __construct($attribute, $op, array $values, $negate)
17+
{
1618
$this->_attribute = $attribute;
1719
$this->_op = $op;
1820
$this->_values = $values;
1921
$this->_negate = $negate;
2022
}
2123

22-
public static function getDecoder() {
24+
public static function getDecoder()
25+
{
2326
return function ($v) {
2427
return new Clause($v['attribute'], $v['op'], $v['values'], $v['negate']);
2528
};
@@ -29,7 +32,8 @@ public static function getDecoder() {
2932
* @param $user LDUser
3033
* @return bool
3134
*/
32-
public function matchesUser($user) {
35+
public function matchesUser($user)
36+
{
3337
$userValue = $user->getValueForEvaluation($this->_attribute);
3438
if ($userValue === null) {
3539
return false;
@@ -50,36 +54,41 @@ public function matchesUser($user) {
5054
/**
5155
* @return string
5256
*/
53-
public function getAttribute() {
57+
public function getAttribute()
58+
{
5459
return $this->_attribute;
5560
}
5661

5762
/**
5863
* @return string
5964
*/
60-
public function getOp() {
65+
public function getOp()
66+
{
6167
return $this->_op;
6268
}
6369

6470
/**
6571
* @return array
6672
*/
67-
public function getValues() {
73+
public function getValues()
74+
{
6875
return $this->_values;
6976
}
7077

7178
/**
7279
* @return boolean
7380
*/
74-
public function isNegate() {
81+
public function isNegate()
82+
{
7583
return $this->_negate;
7684
}
7785

7886
/**
7987
* @param $userValue
8088
* @return bool
8189
*/
82-
private function matchAny($userValue) {
90+
private function matchAny($userValue)
91+
{
8392
foreach ($this->_values as $v) {
8493
$result = Operators::apply($this->_op, $userValue, $v);
8594
if ($result === true) {
@@ -89,11 +98,12 @@ private function matchAny($userValue) {
8998
return false;
9099
}
91100

92-
private function _maybeNegate($b) {
101+
private function _maybeNegate($b)
102+
{
93103
if ($this->_negate) {
94104
return !$b;
95105
} else {
96106
return $b;
97107
}
98108
}
99-
}
109+
}

src/LaunchDarkly/Rule.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22

33
namespace LaunchDarkly;
44

5-
class Rule extends VariationOrRollout {
5+
class Rule extends VariationOrRollout
6+
{
67
/** @var Clause[] */
78
private $_clauses = array();
89

9-
protected function __construct($variation, $rollout, array $clauses) {
10+
protected function __construct($variation, $rollout, array $clauses)
11+
{
1012
parent::__construct($variation, $rollout);
1113
$this->_clauses = $clauses;
1214
}
1315

14-
public static function getDecoder() {
16+
public static function getDecoder()
17+
{
1518
return function ($v) {
1619
return new Rule(
1720
isset($v['variation']) ? $v['variation'] : null,
@@ -24,7 +27,8 @@ public static function getDecoder() {
2427
* @param $user LDUser
2528
* @return bool
2629
*/
27-
public function matchesUser($user) {
30+
public function matchesUser($user)
31+
{
2832
foreach ($this->_clauses as $clause) {
2933
if (!$clause->matchesUser($user)) {
3034
return false;
@@ -36,7 +40,8 @@ public function matchesUser($user) {
3640
/**
3741
* @return Clause[]
3842
*/
39-
public function getClauses() {
43+
public function getClauses()
44+
{
4045
return $this->_clauses;
4146
}
42-
}
47+
}

src/LaunchDarkly/VariationOrRollout.php

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

33
namespace LaunchDarkly;
44

5-
6-
class VariationOrRollout {
5+
class VariationOrRollout
6+
{
77
private static $LONG_SCALE = 0xFFFFFFFFFFFFFFF;
88

99
/** @var int | null */
1010
private $_variation = null;
1111
/** @var Rollout | null */
1212
private $_rollout = null;
1313

14-
protected function __construct($variation, $rollout) {
14+
protected function __construct($variation, $rollout)
15+
{
1516
$this->_variation = $variation;
1617
$this->_rollout = $rollout;
1718
}
1819

19-
public static function getDecoder() {
20+
public static function getDecoder()
21+
{
2022
return function ($v) {
2123
return new VariationOrRollout(
2224
isset($v['variation']) ? $v['variation'] : null,
@@ -27,14 +29,16 @@ public static function getDecoder() {
2729
/**
2830
* @return int | null
2931
*/
30-
public function getVariation() {
32+
public function getVariation()
33+
{
3134
return $this->_variation;
3235
}
3336

3437
/**
3538
* @return Rollout | null
3639
*/
37-
public function getRollout() {
40+
public function getRollout()
41+
{
3842
return $this->_rollout;
3943
}
4044

@@ -44,10 +48,11 @@ public function getRollout() {
4448
* @param $_salt string
4549
* @return int|null
4650
*/
47-
public function variationIndexForUser($user, $_key, $_salt) {
51+
public function variationIndexForUser($user, $_key, $_salt)
52+
{
4853
if ($this->_variation !== null) {
4954
return $this->_variation;
50-
} else if ($this->_rollout !== null) {
55+
} elseif ($this->_rollout !== null) {
5156
$bucketBy = $this->_rollout->getBucketBy() === null ? "key" : $this->_rollout->getBucketBy();
5257
$bucket = $this->bucketUser($user, $_key, $bucketBy, $_salt);
5358
$sum = 0.0;
@@ -68,7 +73,8 @@ public function variationIndexForUser($user, $_key, $_salt) {
6873
* @param $_salt string
6974
* @return float
7075
*/
71-
private function bucketUser($user, $_key, $attr, $_salt) {
76+
private function bucketUser($user, $_key, $attr, $_salt)
77+
{
7278
$userValue = $user->getValueForEvaluation($attr);
7379
$idHash = null;
7480
if ($userValue != null) {
@@ -89,4 +95,4 @@ private function bucketUser($user, $_key, $attr, $_salt) {
8995
}
9096
return 0.0;
9197
}
92-
}
98+
}

0 commit comments

Comments
 (0)