1212 */
1313class Clause
1414{
15- /** @var string */
15+ /** @var string|null */
1616 private $ _attribute = null ;
17- /** @var string */
17+ /** @var string|null */
1818 private $ _op = null ;
1919 /** @var array */
2020 private $ _values = array ();
2121 /** @var bool */
2222 private $ _negate = false ;
2323
24- private function __construct ($ attribute , $ op , array $ values , $ negate )
24+ private function __construct (? string $ attribute , ? string $ op , array $ values , bool $ negate )
2525 {
2626 $ this ->_attribute = $ attribute ;
2727 $ this ->_op = $ op ;
2828 $ this ->_values = $ values ;
2929 $ this ->_negate = $ negate ;
3030 }
3131
32- public static function getDecoder ()
32+ /**
33+ * @psalm-return \Closure(mixed):self
34+ */
35+ public static function getDecoder (): \Closure
3336 {
3437 return function ($ v ) {
3538 return new Clause ($ v ['attribute ' ], $ v ['op ' ], $ v ['values ' ], $ v ['negate ' ]);
3639 };
3740 }
3841
39- /**
40- * @param $user LDUser
41- * @return bool
42- */
43- public function matchesUser ($ user , $ featureRequester )
42+ public function matchesUser (LDUser $ user , ?FeatureRequester $ featureRequester ): bool
4443 {
4544 if ($ this ->_op === 'segmentMatch ' ) {
4645 foreach ($ this ->_values as $ value ) {
47- $ segment = $ featureRequester ->getSegment ($ value );
46+ $ segment = $ featureRequester ? $ featureRequester ->getSegment ($ value ) : null ;
4847 if ($ segment ) {
4948 if ($ segment ->matchesUser ($ user )) {
5049 return $ this ->_maybeNegate (true );
@@ -57,11 +56,7 @@ public function matchesUser($user, $featureRequester)
5756 }
5857 }
5958
60- /**
61- * @param $user LDUser
62- * @return bool
63- */
64- public function matchesUserNoSegments ($ user )
59+ public function matchesUserNoSegments (LDUser $ user ): bool
6560 {
6661 $ userValue = $ user ->getValueForEvaluation ($ this ->_attribute );
6762 if ($ userValue === null ) {
@@ -79,44 +74,32 @@ public function matchesUserNoSegments($user)
7974 }
8075 }
8176
82-
83- /**
84- * @return string
85- */
86- public function getAttribute ()
77+ public function getAttribute (): ?string
8778 {
8879 return $ this ->_attribute ;
8980 }
9081
91- /**
92- * @return string
93- */
94- public function getOp ()
82+ public function getOp (): ?string
9583 {
9684 return $ this ->_op ;
9785 }
9886
99- /**
100- * @return array
101- */
102- public function getValues ()
87+ public function getValues (): array
10388 {
10489 return $ this ->_values ;
10590 }
10691
107- /**
108- * @return boolean
109- */
110- public function isNegate ()
92+ public function isNegate (): bool
11193 {
11294 return $ this ->_negate ;
11395 }
11496
11597 /**
116- * @param $userValue
98+ * @param mixed|null $userValue
99+ *
117100 * @return bool
118101 */
119- private function matchAny ($ userValue )
102+ private function matchAny ($ userValue ): bool
120103 {
121104 foreach ($ this ->_values as $ v ) {
122105 $ result = Operators::apply ($ this ->_op , $ userValue , $ v );
@@ -127,7 +110,7 @@ private function matchAny($userValue)
127110 return false ;
128111 }
129112
130- private function _maybeNegate ($ b )
113+ private function _maybeNegate (bool $ b ): bool
131114 {
132115 if ($ this ->_negate ) {
133116 return !$ b ;
0 commit comments