Conditions | 6 |
Paths | 10 |
Total Lines | 51 |
Lines | 14 |
Ratio | 27.45 % |
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 |
||
49 | protected function generate_sizes() { |
||
50 | |||
51 | // There is no need to generate the sizes a new for every single image. |
||
52 | if ( null !== self::$sizes ) { |
||
53 | return self::$sizes; |
||
54 | } |
||
55 | |||
56 | /* |
||
57 | * The following logic is copied over from wp_generate_attachment_metadata |
||
58 | */ |
||
59 | $_wp_additional_image_sizes = wp_get_additional_image_sizes(); |
||
60 | |||
61 | $sizes = array(); |
||
62 | |||
63 | $intermediate_image_sizes = get_intermediate_image_sizes(); |
||
64 | |||
65 | foreach ( $intermediate_image_sizes as $s ) { |
||
66 | $sizes[ $s ] = array( |
||
67 | 'width' => '', |
||
68 | 'height' => '', |
||
69 | 'crop' => false, |
||
70 | ); |
||
71 | View Code Duplication | if ( isset( $_wp_additional_image_sizes[ $s ]['width'] ) ) { |
|
72 | // For theme-added sizes. |
||
73 | $sizes[ $s ]['width'] = intval( $_wp_additional_image_sizes[ $s ]['width'] ); |
||
74 | } else { |
||
75 | // For default sizes set in options. |
||
76 | $sizes[ $s ]['width'] = get_option( "{$s}_size_w" ); |
||
77 | } |
||
78 | |||
79 | View Code Duplication | if ( isset( $_wp_additional_image_sizes[ $s ]['height'] ) ) { |
|
80 | // For theme-added sizes. |
||
81 | $sizes[ $s ]['height'] = intval( $_wp_additional_image_sizes[ $s ]['height'] ); |
||
82 | } else { |
||
83 | // For default sizes set in options. |
||
84 | $sizes[ $s ]['height'] = get_option( "{$s}_size_h" ); |
||
85 | } |
||
86 | |||
87 | if ( isset( $_wp_additional_image_sizes[ $s ]['crop'] ) ) { |
||
88 | // For theme-added sizes. |
||
89 | $sizes[ $s ]['crop'] = $_wp_additional_image_sizes[ $s ]['crop']; |
||
90 | } else { |
||
91 | // For default sizes set in options. |
||
92 | $sizes[ $s ]['crop'] = get_option( "{$s}_crop" ); |
||
93 | } |
||
94 | } |
||
95 | |||
96 | self::$sizes = $sizes; |
||
97 | |||
98 | return $sizes; |
||
99 | } |
||
100 | |||
183 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..