Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
15 | class Jetpack_Photon_ImageSizes { |
||
16 | |||
17 | /** |
||
18 | * @var array $data Attachment metadata. |
||
19 | */ |
||
20 | public $data; |
||
21 | |||
22 | /** |
||
23 | * @var Image Image to be resized. |
||
24 | */ |
||
25 | public $image; |
||
26 | |||
27 | /** |
||
28 | * @var null|array $sizes Intermediate sizes. |
||
29 | */ |
||
30 | public static $sizes = null; |
||
31 | |||
32 | /** |
||
33 | * Construct new sizes meta |
||
34 | * |
||
35 | * @param int $attachment_id Attachment ID. |
||
36 | * @param array $data Attachment metadata. |
||
37 | */ |
||
38 | public function __construct( $attachment_id, $data ) { |
||
43 | |||
44 | /** |
||
45 | * Generate sizes for attachment. |
||
46 | * |
||
47 | * @return array Array of sizes; empty array as failure fallback. |
||
48 | */ |
||
49 | protected function generate_sizes() { |
||
100 | |||
101 | /** |
||
102 | * @return array |
||
103 | */ |
||
104 | public function filtered_sizes() { |
||
122 | |||
123 | /** |
||
124 | * Standardises and validates the size_data array. |
||
125 | * |
||
126 | * @param array $size_data Size data array - at least containing height or width key. Can contain crop as well. |
||
127 | * |
||
128 | * @return array Array with populated width, height and crop keys; empty array if no width and height are provided. |
||
129 | */ |
||
130 | public function standardize_size_data( $size_data ) { |
||
144 | |||
145 | /** |
||
146 | * Get sizes for attachment post meta. |
||
147 | * |
||
148 | * @return array ImageSizes for attachment postmeta. |
||
149 | */ |
||
150 | public function generate_sizes_meta() { |
||
171 | |||
172 | /** |
||
173 | * @param array $size_data |
||
174 | * |
||
175 | * @return array|\WP_Error Array for usage in $metadata['sizes']; WP_Error on failure. |
||
176 | */ |
||
177 | protected function resize( $size_data ) { |
||
182 | } |
||
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..