diff --git a/src/LaunchDarkly/Clause.php b/src/LaunchDarkly/Clause.php index adf01615e..c0330b009 100644 --- a/src/LaunchDarkly/Clause.php +++ b/src/LaunchDarkly/Clause.php @@ -2,7 +2,8 @@ namespace LaunchDarkly; -class Clause { +class Clause +{ /** @var string */ private $_attribute = null; /** @var string */ @@ -12,14 +13,16 @@ class Clause { /** @var bool */ private $_negate = false; - private function __construct($attribute, $op, array $values, $negate) { + private function __construct($attribute, $op, array $values, $negate) + { $this->_attribute = $attribute; $this->_op = $op; $this->_values = $values; $this->_negate = $negate; } - public static function getDecoder() { + public static function getDecoder() + { return function ($v) { return new Clause($v['attribute'], $v['op'], $v['values'], $v['negate']); }; @@ -29,7 +32,8 @@ public static function getDecoder() { * @param $user LDUser * @return bool */ - public function matchesUser($user) { + public function matchesUser($user) + { $userValue = $user->getValueForEvaluation($this->_attribute); if ($userValue === null) { return false; @@ -50,28 +54,32 @@ public function matchesUser($user) { /** * @return string */ - public function getAttribute() { + public function getAttribute() + { return $this->_attribute; } /** * @return string */ - public function getOp() { + public function getOp() + { return $this->_op; } /** * @return array */ - public function getValues() { + public function getValues() + { return $this->_values; } /** * @return boolean */ - public function isNegate() { + public function isNegate() + { return $this->_negate; } @@ -79,7 +87,8 @@ public function isNegate() { * @param $userValue * @return bool */ - private function matchAny($userValue) { + private function matchAny($userValue) + { foreach ($this->_values as $v) { $result = Operators::apply($this->_op, $userValue, $v); if ($result === true) { @@ -89,11 +98,12 @@ private function matchAny($userValue) { return false; } - private function _maybeNegate($b) { + private function _maybeNegate($b) + { if ($this->_negate) { return !$b; } else { return $b; } } -} \ No newline at end of file +} diff --git a/src/LaunchDarkly/Rule.php b/src/LaunchDarkly/Rule.php index c2ac20d43..0da0a8b2c 100644 --- a/src/LaunchDarkly/Rule.php +++ b/src/LaunchDarkly/Rule.php @@ -2,16 +2,19 @@ namespace LaunchDarkly; -class Rule extends VariationOrRollout { +class Rule extends VariationOrRollout +{ /** @var Clause[] */ private $_clauses = array(); - protected function __construct($variation, $rollout, array $clauses) { + protected function __construct($variation, $rollout, array $clauses) + { parent::__construct($variation, $rollout); $this->_clauses = $clauses; } - public static function getDecoder() { + public static function getDecoder() + { return function ($v) { return new Rule( isset($v['variation']) ? $v['variation'] : null, @@ -24,7 +27,8 @@ public static function getDecoder() { * @param $user LDUser * @return bool */ - public function matchesUser($user) { + public function matchesUser($user) + { foreach ($this->_clauses as $clause) { if (!$clause->matchesUser($user)) { return false; @@ -36,7 +40,8 @@ public function matchesUser($user) { /** * @return Clause[] */ - public function getClauses() { + public function getClauses() + { return $this->_clauses; } -} \ No newline at end of file +} diff --git a/src/LaunchDarkly/VariationOrRollout.php b/src/LaunchDarkly/VariationOrRollout.php index e1ff63b60..ca95f23d5 100644 --- a/src/LaunchDarkly/VariationOrRollout.php +++ b/src/LaunchDarkly/VariationOrRollout.php @@ -2,8 +2,8 @@ namespace LaunchDarkly; - -class VariationOrRollout { +class VariationOrRollout +{ private static $LONG_SCALE = 0xFFFFFFFFFFFFFFF; /** @var int | null */ @@ -11,12 +11,14 @@ class VariationOrRollout { /** @var Rollout | null */ private $_rollout = null; - protected function __construct($variation, $rollout) { + protected function __construct($variation, $rollout) + { $this->_variation = $variation; $this->_rollout = $rollout; } - public static function getDecoder() { + public static function getDecoder() + { return function ($v) { return new VariationOrRollout( isset($v['variation']) ? $v['variation'] : null, @@ -27,14 +29,16 @@ public static function getDecoder() { /** * @return int | null */ - public function getVariation() { + public function getVariation() + { return $this->_variation; } /** * @return Rollout | null */ - public function getRollout() { + public function getRollout() + { return $this->_rollout; } @@ -44,10 +48,11 @@ public function getRollout() { * @param $_salt string * @return int|null */ - public function variationIndexForUser($user, $_key, $_salt) { + public function variationIndexForUser($user, $_key, $_salt) + { if ($this->_variation !== null) { return $this->_variation; - } else if ($this->_rollout !== null) { + } elseif ($this->_rollout !== null) { $bucketBy = $this->_rollout->getBucketBy() === null ? "key" : $this->_rollout->getBucketBy(); $bucket = $this->bucketUser($user, $_key, $bucketBy, $_salt); $sum = 0.0; @@ -68,7 +73,8 @@ public function variationIndexForUser($user, $_key, $_salt) { * @param $_salt string * @return float */ - private function bucketUser($user, $_key, $attr, $_salt) { + private function bucketUser($user, $_key, $attr, $_salt) + { $userValue = $user->getValueForEvaluation($attr); $idHash = null; if ($userValue != null) { @@ -86,4 +92,4 @@ private function bucketUser($user, $_key, $attr, $_salt) { } return 0.0; } -} \ No newline at end of file +}