Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Features_Index | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| get_all_features | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_sub_features_of | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\Jetpack_Boost\Modules; |
| 4 | |
| 5 | use Automattic\Jetpack_Boost\Contracts\Feature; |
| 6 | use Automattic\Jetpack_Boost\Contracts\Sub_Feature; |
| 7 | use Automattic\Jetpack_Boost\Modules\Image_Guide\Image_Guide; |
| 8 | use Automattic\Jetpack_Boost\Modules\Optimizations\Cloud_CSS\Cloud_CSS; |
| 9 | use Automattic\Jetpack_Boost\Modules\Optimizations\Critical_CSS\Critical_CSS; |
| 10 | use Automattic\Jetpack_Boost\Modules\Optimizations\Image_CDN\Image_CDN; |
| 11 | use Automattic\Jetpack_Boost\Modules\Optimizations\Image_CDN\Liar; |
| 12 | use Automattic\Jetpack_Boost\Modules\Optimizations\Image_CDN\Quality_Settings; |
| 13 | use Automattic\Jetpack_Boost\Modules\Optimizations\Lcp\Lcp; |
| 14 | use Automattic\Jetpack_Boost\Modules\Optimizations\Minify\Minify_Common; |
| 15 | use Automattic\Jetpack_Boost\Modules\Optimizations\Minify\Minify_CSS; |
| 16 | use Automattic\Jetpack_Boost\Modules\Optimizations\Minify\Minify_JS; |
| 17 | use Automattic\Jetpack_Boost\Modules\Optimizations\Page_Cache\Cache_Preload; |
| 18 | use Automattic\Jetpack_Boost\Modules\Optimizations\Page_Cache\Page_Cache; |
| 19 | use Automattic\Jetpack_Boost\Modules\Optimizations\Render_Blocking_JS\Render_Blocking_JS; |
| 20 | use Automattic\Jetpack_Boost\Modules\Optimizations\Speculation_Rules\Speculation_Rules; |
| 21 | use Automattic\Jetpack_Boost\Modules\Performance_History\Performance_History; |
| 22 | |
| 23 | class Features_Index { |
| 24 | |
| 25 | /** |
| 26 | * @var class-string<Feature>[] - Classes that handle all Jetpack Boost features. |
| 27 | */ |
| 28 | const FEATURES = array( |
| 29 | Critical_CSS::class, |
| 30 | Cloud_CSS::class, |
| 31 | Lcp::class, |
| 32 | Minify_JS::class, |
| 33 | Minify_CSS::class, |
| 34 | Render_Blocking_JS::class, |
| 35 | Image_Guide::class, |
| 36 | Image_CDN::class, |
| 37 | Performance_History::class, |
| 38 | Page_Cache::class, |
| 39 | Speculation_Rules::class, |
| 40 | ); |
| 41 | |
| 42 | /** |
| 43 | * @var class-string<Sub_Feature>[] - Classes that handle all Jetpack Boost subfeatures. |
| 44 | */ |
| 45 | const SUB_FEATURES = array( |
| 46 | Minify_Common::class, |
| 47 | Liar::class, |
| 48 | Quality_Settings::class, |
| 49 | Cache_Preload::class, |
| 50 | ); |
| 51 | |
| 52 | /** |
| 53 | * Get all features and subfeatures. |
| 54 | * |
| 55 | * @return class-string<Feature>[] |
| 56 | */ |
| 57 | public static function get_all_features() { |
| 58 | return array_merge( self::FEATURES, self::SUB_FEATURES ); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Get the subfeatures of a feature. |
| 63 | * |
| 64 | * @param Feature $feature The feature to get the subfeatures of. |
| 65 | * @return class-string<Sub_Feature>[] The subfeatures of the feature. |
| 66 | */ |
| 67 | public static function get_sub_features_of( Feature $feature ) { |
| 68 | /** |
| 69 | * @var class-string<Sub_Feature>[] |
| 70 | */ |
| 71 | $subfeatures = array(); |
| 72 | $feature_class = get_class( $feature ); |
| 73 | foreach ( self::SUB_FEATURES as $subfeature ) { |
| 74 | if ( in_array( $feature_class, $subfeature::get_parent_features(), true ) ) { |
| 75 | $subfeatures[] = $subfeature; |
| 76 | } |
| 77 | } |
| 78 | return $subfeatures; |
| 79 | } |
| 80 | } |