Conditions | 10 |
Paths | 7 |
Total Lines | 31 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
48 | public static function raise_memory_limit() { |
||
49 | if ( function_exists( 'wp_raise_memory_limit' ) ) { |
||
50 | return wp_raise_memory_limit( 'admin' ); |
||
51 | } |
||
52 | |||
53 | $current_limit = @ini_get( 'memory_limit' ); |
||
54 | $current_limit_int = self::convert_hr_to_bytes( $current_limit ); |
||
55 | |||
56 | if ( -1 === $current_limit_int ) { |
||
57 | return false; |
||
58 | } |
||
59 | |||
60 | $wp_max_limit = WP_MAX_MEMORY_LIMIT; |
||
61 | $wp_max_limit_int = self::convert_hr_to_bytes( $wp_max_limit ); |
||
62 | $filtered_limit = apply_filters( 'admin_memory_limit', $wp_max_limit ); |
||
63 | $filtered_limit_int = self::convert_hr_to_bytes( $filtered_limit ); |
||
64 | |||
65 | if ( -1 === $filtered_limit_int || ( $filtered_limit_int > $wp_max_limit_int && $filtered_limit_int > $current_limit_int ) ) { |
||
66 | if ( false !== @ini_set( 'memory_limit', $filtered_limit ) ) { |
||
67 | return $filtered_limit; |
||
68 | } else { |
||
69 | return false; |
||
70 | } |
||
71 | } elseif ( -1 === $wp_max_limit_int || $wp_max_limit_int > $current_limit_int ) { |
||
72 | if ( false !== @ini_set( 'memory_limit', $wp_max_limit ) ) { |
||
73 | return $wp_max_limit; |
||
74 | } else { |
||
75 | return false; |
||
76 | } |
||
77 | } |
||
78 | return false; |
||
79 | } |
||
100 |
If you suppress an error, we recommend checking for the error condition explicitly: