Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| Provider_Setting | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
4 | |
100.00% |
1 / 1 |
| get_providers | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * The site's choice of report providers. |
| 4 | * |
| 5 | * @package automattic/jetpack-woocommerce-stats |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\WooCommerceStats\Report_Execution; |
| 9 | |
| 10 | /** |
| 11 | * The registered providers a `provider=auto` request may use, in order of preference. |
| 12 | * |
| 13 | * @internal Not a stable contract yet: the format may change before a settings UI exists. |
| 14 | * |
| 15 | * @since $$next-version$$ |
| 16 | */ |
| 17 | class Provider_Setting { |
| 18 | |
| 19 | /** |
| 20 | * Option holding the provider names, as a list or comma-separated. Write it with autoload off: only report requests read it. |
| 21 | */ |
| 22 | const OPTION = 'jetpack_woocommerce_stats_report_providers'; |
| 23 | |
| 24 | /** |
| 25 | * Filter overriding the option. |
| 26 | */ |
| 27 | const FILTER = 'jetpack_woocommerce_stats_report_providers'; |
| 28 | |
| 29 | /** |
| 30 | * Provider of a site without a setting, and of a request that names none. |
| 31 | */ |
| 32 | const DEFAULT_PROVIDER = 'wpcom'; |
| 33 | |
| 34 | /** |
| 35 | * Provider names to try, in order, for a `provider=auto` request; the default provider when the site has no setting. |
| 36 | * |
| 37 | * @return non-empty-array<string> |
| 38 | */ |
| 39 | public static function get_providers() { |
| 40 | /** |
| 41 | * Filters the providers a store report requested with `provider=auto` may use, in order of |
| 42 | * preference. Experimental: the format may change before a settings UI exists. |
| 43 | * |
| 44 | * @since $$next-version$$ |
| 45 | * |
| 46 | * @param string[]|string $providers Registered provider names, such as `wpcom` or `local`, as a list or comma-separated. |
| 47 | */ |
| 48 | $providers = apply_filters( self::FILTER, get_option( self::OPTION, array() ) ); |
| 49 | $names = array(); |
| 50 | if ( is_array( $providers ) || is_string( $providers ) ) { |
| 51 | $names = array_values( array_unique( array_filter( array_map( 'trim', array_filter( wp_parse_list( $providers ), 'is_string' ) ) ) ) ); |
| 52 | } |
| 53 | |
| 54 | return $names ? $names : array( self::DEFAULT_PROVIDER ); |
| 55 | } |
| 56 | } |