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;
    }