Conditions | 15 |
Paths | 133 |
Total Lines | 51 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
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 |
||
21 | public static function init_hooks() { |
||
22 | if ( false === ( $page_uris = get_transient( 'wpinv_cache_excluded_uris' ) ) ) { |
||
23 | $checkout_page = wpinv_get_option( 'checkout_page', '' ); |
||
24 | $success_page = wpinv_get_option( 'success_page', '' ); |
||
25 | $failure_page = wpinv_get_option( 'failure_page', '' ); |
||
26 | $history_page = wpinv_get_option( 'invoice_history_page', '' ); |
||
27 | $subscr_page = wpinv_get_option( 'invoice_subscription_page', '' ); |
||
28 | if ( empty( $checkout_page ) || empty( $success_page ) || empty( $failure_page ) || empty( $history_page ) || empty( $subscr_page ) ) { |
||
29 | return; |
||
30 | } |
||
31 | |||
32 | $page_uris = array(); |
||
33 | |||
34 | // Exclude querystring when using page ID |
||
35 | $page_uris[] = 'p=' . $checkout_page; |
||
36 | $page_uris[] = 'p=' . $success_page; |
||
37 | $page_uris[] = 'p=' . $failure_page; |
||
38 | $page_uris[] = 'p=' . $history_page; |
||
39 | $page_uris[] = 'p=' . $subscr_page; |
||
40 | |||
41 | // Exclude permalinks |
||
42 | $checkout_page = get_post( $checkout_page ); |
||
|
|||
43 | $success_page = get_post( $success_page ); |
||
44 | $failure_page = get_post( $failure_page ); |
||
45 | $history_page = get_post( $history_page ); |
||
46 | $subscr_page = get_post( $subscr_page ); |
||
47 | |||
48 | if ( ! is_null( $checkout_page ) ) { |
||
49 | $page_uris[] = '/' . $checkout_page->post_name; |
||
50 | } |
||
51 | if ( ! is_null( $success_page ) ) { |
||
52 | $page_uris[] = '/' . $success_page->post_name; |
||
53 | } |
||
54 | if ( ! is_null( $failure_page ) ) { |
||
55 | $page_uris[] = '/' . $failure_page->post_name; |
||
56 | } |
||
57 | if ( ! is_null( $history_page ) ) { |
||
58 | $page_uris[] = '/' . $history_page->post_name; |
||
59 | } |
||
60 | if ( ! is_null( $subscr_page ) ) { |
||
61 | $page_uris[] = '/' . $subscr_page->post_name; |
||
62 | } |
||
63 | |||
64 | set_transient( 'wpinv_cache_excluded_uris', $page_uris ); |
||
65 | } |
||
66 | |||
67 | if ( is_array( $page_uris ) ) { |
||
68 | foreach ( $page_uris as $uri ) { |
||
69 | if ( strstr( $_SERVER['REQUEST_URI'], $uri ) ) { |
||
70 | self::nocache(); |
||
71 | break; |
||
72 | } |
||
117 |