Conditions | 11 |
Paths | 33 |
Total Lines | 90 |
Lines | 14 |
Ratio | 15.56 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
||
56 | public static function get() { |
||
57 | global $active_plan_cache; |
||
58 | |||
59 | // this can be expensive to compute so we cache for the duration of a request. |
||
60 | if ( is_array( $active_plan_cache ) && ! empty( $active_plan_cache ) ) { |
||
61 | return $active_plan_cache; |
||
62 | } |
||
63 | |||
64 | $plan = get_option( 'jetpack_active_plan', array() ); |
||
65 | |||
66 | // Set the default options. |
||
67 | $plan = wp_parse_args( |
||
68 | $plan, |
||
69 | array( |
||
70 | 'product_slug' => 'jetpack_free', |
||
71 | 'class' => 'free', |
||
72 | 'features' => array( |
||
73 | 'active' => array(), |
||
74 | ), |
||
75 | ) |
||
76 | ); |
||
77 | |||
78 | $supports = array(); |
||
79 | |||
80 | // Define what paid modules are supported by personal plans. |
||
81 | $personal_plans = array( |
||
82 | 'jetpack_personal', |
||
83 | 'jetpack_personal_monthly', |
||
84 | 'personal-bundle', |
||
85 | 'personal-bundle-2y', |
||
86 | ); |
||
87 | |||
88 | if ( in_array( $plan['product_slug'], $personal_plans, true ) ) { |
||
89 | // special support value, not a module but a separate plugin. |
||
90 | $supports[] = 'akismet'; |
||
91 | $plan['class'] = 'personal'; |
||
92 | } |
||
93 | |||
94 | // Define what paid modules are supported by premium plans. |
||
95 | $premium_plans = array( |
||
96 | 'jetpack_premium', |
||
97 | 'jetpack_premium_monthly', |
||
98 | 'value_bundle', |
||
99 | 'value_bundle-2y', |
||
100 | ); |
||
101 | |||
102 | View Code Duplication | if ( in_array( $plan['product_slug'], $premium_plans, true ) ) { |
|
103 | $supports[] = 'akismet'; |
||
104 | $supports[] = 'simple-payments'; |
||
105 | $supports[] = 'vaultpress'; |
||
106 | $supports[] = 'videopress'; |
||
107 | $plan['class'] = 'premium'; |
||
108 | } |
||
109 | |||
110 | // Define what paid modules are supported by professional plans. |
||
111 | $business_plans = array( |
||
112 | 'jetpack_business', |
||
113 | 'jetpack_business_monthly', |
||
114 | 'business-bundle', |
||
115 | 'business-bundle-2y', |
||
116 | 'ecommerce-bundle', |
||
117 | 'ecommerce-bundle-2y', |
||
118 | 'vip', |
||
119 | ); |
||
120 | |||
121 | View Code Duplication | if ( in_array( $plan['product_slug'], $business_plans, true ) ) { |
|
122 | $supports[] = 'akismet'; |
||
123 | $supports[] = 'simple-payments'; |
||
124 | $supports[] = 'vaultpress'; |
||
125 | $supports[] = 'videopress'; |
||
126 | $plan['class'] = 'business'; |
||
127 | } |
||
128 | |||
129 | // get available features. |
||
130 | foreach ( Jetpack::get_available_modules() as $module_slug ) { |
||
131 | $module = Jetpack::get_module( $module_slug ); |
||
132 | if ( ! isset( $module ) || ! is_array( $module ) ) { |
||
133 | continue; |
||
134 | } |
||
135 | if ( in_array( 'free', $module['plan_classes'], true ) || in_array( $plan['class'], $module['plan_classes'], true ) ) { |
||
136 | $supports[] = $module_slug; |
||
137 | } |
||
138 | } |
||
139 | |||
140 | $plan['supports'] = $supports; |
||
141 | |||
142 | $active_plan_cache = $plan; |
||
143 | |||
144 | return $plan; |
||
145 | } |
||
146 | |||
184 |