@@ -253,7 +253,15 @@ private static function _contextMatchesCondition(
253253 $ condition ,
254254 $ segmentKey ,
255255 ): bool {
256- $ contextValue = self ::_getContextValue ($ context , $ condition ->property );
256+ // NOTE: Currently, the only supported condition with a blank property is percentage split. In this
257+ // case, we use the identity key as context value. This is mainly to support legacy segments created
258+ // before we introduced JSONPath support.
259+ if ($ condition ->operator === SegmentConditionOperator::PERCENTAGE_SPLIT && empty ($ condition ->property )) {
260+ $ contextValue = $ context ->identity ?->key;
261+ } else {
262+ $ contextValue = self ::_getContextValue ($ context , $ condition ->property );
263+ }
264+
257265 $ cast = self ::_getCaster ($ contextValue );
258266
259267 switch ($ condition ->operator ) {
@@ -282,22 +290,16 @@ private static function _contextMatchesCondition(
282290 return in_array ($ contextValue , $ inValues , strict: true );
283291
284292 case SegmentConditionOperator::PERCENTAGE_SPLIT :
285- if (! is_numeric ( $ condition -> value ) ) {
293+ if ($ contextValue === null ) {
286294 return false ;
287295 }
288-
289- /** @var array<string> $objectIds */
290- if ($ contextValue !== null ) {
291- $ objectIds = [$ segmentKey , $ contextValue ];
292- } elseif ($ context ->identity !== null ) {
293- $ objectIds = [$ segmentKey , $ context ->identity ->key ];
294- } else {
296+ if (!is_numeric ($ condition ->value )) {
295297 return false ;
296298 }
297299
298300 $ hashing = new Hashing ();
299301 $ threshold = $ hashing ->getHashedPercentageForObjectIds (
300- $ objectIds ,
302+ [ $ segmentKey , $ contextValue ] ,
301303 );
302304 return $ threshold <= ((float ) $ condition ->value );
303305
0 commit comments