@@ -44,6 +44,21 @@ public function __construct(array $userAttributes)
4444 $ this ->userAttributes = $ userAttributes ;
4545 }
4646
47+ /**
48+ * Sets null for missing keys in a leaf condition.
49+ *
50+ * @param array $leafCondition The leaf condition node of an audience.
51+ */
52+ protected function setNullForMissingKeys (array $ leafCondition )
53+ {
54+ $ keys = ['type ' , 'match ' , 'value ' ];
55+ foreach ($ keys as $ key ) {
56+ $ leafCondition [$ key ] = isset ($ leafCondition [$ key ]) ? $ leafCondition [$ key ]: null ;
57+ }
58+
59+ return $ leafCondition ;
60+ }
61+
4762 /**
4863 * Gets the supported match types for condition evaluation.
4964 *
@@ -103,8 +118,8 @@ protected function isValueValidForExactConditions($value)
103118 */
104119 protected function exactEvaluator ($ condition )
105120 {
106- $ conditionName = $ condition->{ 'name ' } ;
107- $ conditionValue = $ condition->{ 'value ' } ;
121+ $ conditionName = $ condition[ 'name ' ] ;
122+ $ conditionValue = $ condition[ 'value ' ] ;
108123 $ userValue = isset ($ this ->userAttributes [$ conditionName ]) ? $ this ->userAttributes [$ conditionName ]: null ;
109124
110125 if (!$ this ->isValueValidForExactConditions ($ userValue ) ||
@@ -128,7 +143,7 @@ protected function exactEvaluator($condition)
128143 */
129144 protected function existsEvaluator ($ condition )
130145 {
131- $ conditionName = $ condition->{ 'name ' } ;
146+ $ conditionName = $ condition[ 'name ' ] ;
132147 return isset ($ this ->userAttributes [$ conditionName ]);
133148 }
134149
@@ -144,8 +159,8 @@ protected function existsEvaluator($condition)
144159 */
145160 protected function greaterThanEvaluator ($ condition )
146161 {
147- $ conditionName = $ condition->{ 'name ' } ;
148- $ conditionValue = $ condition->{ 'value ' } ;
162+ $ conditionName = $ condition[ 'name ' ] ;
163+ $ conditionValue = $ condition[ 'value ' ] ;
149164 $ userValue = isset ($ this ->userAttributes [$ conditionName ]) ? $ this ->userAttributes [$ conditionName ]: null ;
150165
151166 if (!Validator::isFiniteNumber ($ userValue ) || !Validator::isFiniteNumber ($ conditionValue )) {
@@ -167,8 +182,8 @@ protected function greaterThanEvaluator($condition)
167182 */
168183 protected function lessThanEvaluator ($ condition )
169184 {
170- $ conditionName = $ condition->{ 'name ' } ;
171- $ conditionValue = $ condition->{ 'value ' } ;
185+ $ conditionName = $ condition[ 'name ' ] ;
186+ $ conditionValue = $ condition[ 'value ' ] ;
172187 $ userValue = isset ($ this ->userAttributes [$ conditionName ]) ? $ this ->userAttributes [$ conditionName ]: null ;
173188
174189 if (!Validator::isFiniteNumber ($ userValue ) || !Validator::isFiniteNumber ($ conditionValue )) {
@@ -190,8 +205,8 @@ protected function lessThanEvaluator($condition)
190205 */
191206 protected function substringEvaluator ($ condition )
192207 {
193- $ conditionName = $ condition->{ 'name ' } ;
194- $ conditionValue = $ condition->{ 'value ' } ;
208+ $ conditionName = $ condition[ 'name ' ] ;
209+ $ conditionValue = $ condition[ 'value ' ] ;
195210 $ userValue = isset ($ this ->userAttributes [$ conditionName ]) ? $ this ->userAttributes [$ conditionName ]: null ;
196211
197212 if (!is_string ($ userValue ) || !is_string ($ conditionValue )) {
@@ -211,14 +226,16 @@ protected function substringEvaluator($condition)
211226 */
212227 public function evaluate ($ leafCondition )
213228 {
214- if ($ leafCondition ->{'type ' } !== self ::CUSTOM_ATTRIBUTE_CONDITION_TYPE ) {
229+ $ leafCondition = $ this ->setNullForMissingKeys ($ leafCondition );
230+
231+ if ($ leafCondition ['type ' ] !== self ::CUSTOM_ATTRIBUTE_CONDITION_TYPE ) {
215232 return null ;
216233 }
217234
218- if (! isset ($ leafCondition->{ 'match ' }) ) {
235+ if (($ leafCondition[ 'match ' ]) === null ) {
219236 $ conditionMatch = self ::EXACT_MATCH_TYPE ;
220237 } else {
221- $ conditionMatch = $ leafCondition->{ 'match ' } ;
238+ $ conditionMatch = $ leafCondition[ 'match ' ] ;
222239 }
223240
224241 if (!in_array ($ conditionMatch , $ this ->getMatchTypes ())) {
0 commit comments