@@ -470,6 +470,14 @@ public function getVariation($experimentKey, $userId, $attributes = null)
470470 */
471471 public function setForcedVariation ($ experimentKey , $ userId , $ variationKey )
472472 {
473+ if (!$ this ->validateInputs (
474+ [
475+ self ::EXPERIMENT_KEY =>$ experimentKey ,
476+ self ::USER_ID => $ userId
477+ ]
478+ )) {
479+ return false ;
480+ }
473481 return $ this ->_config ->setForcedVariation ($ experimentKey , $ userId , $ variationKey );
474482 }
475483
@@ -483,6 +491,15 @@ public function setForcedVariation($experimentKey, $userId, $variationKey)
483491 */
484492 public function getForcedVariation ($ experimentKey , $ userId )
485493 {
494+ if (!$ this ->validateInputs (
495+ [
496+ self ::EXPERIMENT_KEY =>$ experimentKey ,
497+ self ::USER_ID => $ userId
498+ ]
499+ )) {
500+ return null ;
501+ }
502+
486503 $ forcedVariation = $ this ->_config ->getForcedVariation ($ experimentKey , $ userId );
487504 if (isset ($ forcedVariation )) {
488505 return $ forcedVariation ->getKey ();
@@ -798,6 +815,15 @@ public function isValid()
798815 protected function validateInputs (array $ values , $ logLevel = Logger::ERROR )
799816 {
800817 $ isValid = true ;
818+ if (array_key_exists (self ::USER_ID , $ values )) {
819+ // Empty str is a valid user ID
820+ if (!is_string ($ values [self ::USER_ID ])) {
821+ $ this ->_logger ->log (Logger::ERROR , sprintf (Errors::INVALID_FORMAT , self ::USER_ID ));
822+ $ isValid = false ;
823+ }
824+ unset($ values [self ::USER_ID ]);
825+ }
826+
801827 foreach ($ values as $ key => $ value ) {
802828 if (!Validator::validateNonEmptyString ($ value )) {
803829 $ isValid = false ;
0 commit comments