Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Launchpad_Personalization_Experiment | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
| get_variation | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
| normalize | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Resolves the wpcom_launchpad_personalization_202607_v1 experiment variation server-side. |
| 4 | * |
| 5 | * @package automattic/jetpack-mu-wpcom |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Jetpack_Mu_Wpcom; |
| 9 | |
| 10 | use Automattic\Jetpack\ExPlat\Server_Assignment; |
| 11 | |
| 12 | /** |
| 13 | * Reads the launchpad-personalization variation for the current user. |
| 14 | * |
| 15 | * The experiment is registered on the `calypso` platform, and the read is |
| 16 | * non-assigning: rendering wp-admin must never create an assignment. |
| 17 | */ |
| 18 | class Launchpad_Personalization_Experiment { |
| 19 | |
| 20 | const EXPERIMENT_NAME = 'wpcom_launchpad_personalization_202607_v1'; |
| 21 | |
| 22 | /** |
| 23 | * The current user's variation: 'control', 'ai_launchpad', or 'no_guidance'. |
| 24 | * |
| 25 | * @return string |
| 26 | */ |
| 27 | public static function get_variation() { |
| 28 | /** |
| 29 | * Overrides the resolved variation (testing / manual QA). Return one of the variation strings, or null to use ExPlat. |
| 30 | * |
| 31 | * @param string|null $override The forced variation, or null. |
| 32 | */ |
| 33 | $override = apply_filters( 'wpcom_launchpad_personalization_variation', null ); |
| 34 | if ( null !== $override ) { |
| 35 | return self::normalize( $override ); |
| 36 | } |
| 37 | |
| 38 | return self::normalize( |
| 39 | Server_Assignment::get_variation( self::EXPERIMENT_NAME, array( 'platform' => 'calypso' ) ) |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Map any variation onto a known value; unknown/null becomes 'control'. |
| 45 | * |
| 46 | * @param string|null $variation The raw variation name. |
| 47 | * @return string |
| 48 | */ |
| 49 | private static function normalize( $variation ) { |
| 50 | if ( 'ai_launchpad' === $variation || 'no_guidance' === $variation ) { |
| 51 | return $variation; |
| 52 | } |
| 53 | return 'control'; |
| 54 | } |
| 55 | } |