public function bucket(ProjectConfig $config, Experiment $experiment, $bucketingId, $userId)
    {
        if (is_null($experiment->getKey())) {
            return null;
        }

        // Determine if experiment is in a mutually exclusive group.
        if ($experiment->isInMutexGroup()) {
            $group = $config->getGroup($experiment->getGroupId());

            if (is_null($group->getId())) {
                return null;
            }

            $userExperimentId = $this->findBucket($bucketingId, $userId, $group->getId(), $group->getTrafficAllocation());
            if (empty($userExperimentId)) {
                $this->_logger->log(Logger::INFO, sprintf('User "%s" is in no experiment.', $userId));
                return null;
            }

            if ($userExperimentId != $experiment->getId()) {
                $this->_logger->log(
                    Logger::INFO,
                    sprintf(
                        'User "%s" is not in experiment %s of group %s.',
                        $userId,
                        $experiment->getKey(),
                        $experiment->getGroupId()
                    )
                );
                return null;
            }

            $this->_logger->log(
                Logger::INFO,
                sprintf(
                    'User "%s" is in experiment %s of group %s.',
                    $userId,
                    $experiment->getKey(),
                    $experiment->getGroupId()
                )
            );
        }

        // Bucket user if not in whitelist and in group (if any).
        $variationId = $this->findBucket($bucketingId, $userId, $experiment->getId(), $experiment->getTrafficAllocation());
        if (!empty($variationId)) {
            $variation = $config->getVariationFromId($experiment->getKey(), $variationId);

            $this->_logger->log(
                Logger::INFO,
                sprintf(
                    'User "%s" is in variation %s of experiment %s.',
                    $userId,
                    $variation->getKey(),
                    $experiment->getKey()
                )
            );
            return $variation;
        }
        
        $this->_logger->log(Logger::INFO, sprintf('User "%s" is in no variation.', $userId));
        return null;
    }
public function bucket(ProjectConfig $config, Experiment $experiment, $bucketingId, $userId)
    {
        if (is_null($experiment->getKey())) {
            return null;
        }

        // Determine if experiment is in a mutually exclusive group.
        if ($experiment->isInMutexGroup()) {
            $group = $config->getGroup($experiment->getGroupId());

            if (is_null($group->getId())) {
                return null;
            }

            $userExperimentId = $this->findBucket($bucketingId, $userId, $group->getId(), $group->getTrafficAllocation());
            if (empty($userExperimentId)) {
                $this->_logger->log(Logger::INFO, sprintf('User "%s" is in no experiment.', $userId));
                return null;
            }

            if ($userExperimentId != $experiment->getId()) {
                $this->_logger->log(
                    Logger::INFO,
                    sprintf(
                        'User "%s" is not in experiment %s of group %s.',
                        $userId,
                        $experiment->getKey(),
                        $experiment->getGroupId()
                    )
                );
                return null;
            }

            $this->_logger->log(
                Logger::INFO,
                sprintf(
                    'User "%s" is in experiment %s of group %s.',
                    $userId,
                    $experiment->getKey(),
                    $experiment->getGroupId()
                )
            );
        }

        // Bucket user if not in whitelist and in group (if any).
        $variationId = $this->findBucket($bucketingId, $userId, $experiment->getId(), $experiment->getTrafficAllocation());
        if (!empty($variationId)) {
            $variation = $config->getVariationFromId($experiment->getKey(), $variationId);

            $this->_logger->log(
                Logger::INFO,
                sprintf(
                    'User "%s" is in variation %s of experiment %s.',
                    $userId,
                    $variation->getKey(),
                    $experiment->getKey()
                )
            );
            return $variation;
        }
        
        $this->_logger->log(Logger::INFO, sprintf('User "%s" is in no variation.', $userId));
        return null;
    }
public function bucket ( ProjectConfig $ config , Experiment $ experiment , $ bucketingId , $ userId ) { if ( is_null ( $ experiment -> getKey ( ) ) ) { return null ; } // Determine if experiment is in a mutually exclusive group. if ( $ experiment -> isInMutexGroup ( ) ) { $ group = $ config -> getGroup ( $ experiment -> getGroupId ( ) ) ; if ( is_null ( $ group -> getId ( ) ) ) { return null ; } $ userExperimentId = $ this -> findBucket ( $ bucketingId , $ userId , $ group -> getId ( ) , $ group -> getTrafficAllocation ( ) ) ; if ( empty ( $ userExperimentId ) ) { $ this -> _logger -> log ( Logger :: INFO , sprintf ( 'User "%s" is in no experiment.' , $ userId ) ) ; return null ; } if ( $ userExperimentId != $ experiment -> getId ( ) ) { $ this -> _logger -> log ( Logger :: INFO , sprintf ( 'User "%s" is not in experiment %s of group %s.' , $ userId , $ experiment -> getKey ( ) , $ experiment -> getGroupId ( ) ) ) ; return null ; } $ this -> _logger -> log ( Logger :: INFO , sprintf ( 'User "%s" is in experiment %s of group %s.' , $ userId , $ experiment -> getKey ( ) , $ experiment -> getGroupId ( ) ) ) ; } // Bucket user if not in whitelist and in group (if any). $ variationId = $ this -> findBucket ( $ bucketingId , $ userId , $ experiment -> getId ( ) , $ experiment -> getTrafficAllocation ( ) ) ; if ( ! empty ( $ variationId ) ) { $ variation = $ config -> getVariationFromId ( $ experiment -> getKey ( ) , $ variationId ) ; $ this -> _logger -> log ( Logger :: INFO , sprintf ( 'User "%s" is in variation %s of experiment %s.' , $ userId , $ variation -> getKey ( ) , $ experiment -> getKey ( ) ) ) ; return $ variation ; } $ this -> _logger -> log ( Logger :: INFO , sprintf ( 'User "%s" is in no variation.' , $ userId ) ) ; return null ; }
Determine variation the user should be put in.

@param $config ProjectConfig Configuration for the project.
@param $experiment Experiment Experiment in which user is to be bucketed.
@param $bucketingId string A customer-assigned value used to create the key for the murmur hash.
@param $userId string User identifier.

@return Variation Variation which will be shown to the user.
Determine variation the user should be put in .