config = $config; $this->user = $user; $this->experimentName = $experimentName; $this->name = $name ?? ''; } /** * @inheritDoc */ public function getName(): string { return $this->name; } /** * Returns true if the user is logged-in and false otherwise. * * @inheritDoc */ public function isMet(): bool { // Get the experiment configuration from the config object. $experiment = $this->config->get( 'VectorWebABTestEnrollment' ); // Use the local user ID directly $id = $this->user->getId(); // Check if the experiment is not enabled or does not match the specified name. if ( !$experiment['enabled'] || $experiment['name'] !== $this->experimentName ) { // If the experiment is not enabled or does not match the specified name, // return true, indicating that the metric is "met" return true; } else { // If the experiment is enabled and matches the specified name, // calculate the user's variant based on their user ID $variant = $id % 2; // Cast the variant value to a boolean and return it, indicating whether // the user is in the "control" or "test" group. return (bool)$variant; } } }