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 |
||
19 | class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin { |
||
20 | |||
21 | /** |
||
22 | * Holds the WP_Error object. |
||
23 | * |
||
24 | * @since 4.6.0 |
||
25 | * @access protected |
||
26 | * @var null|WP_Error |
||
27 | */ |
||
28 | protected $errors = null; |
||
29 | |||
30 | /** |
||
31 | * Constructor. |
||
32 | * |
||
33 | * @since 4.6.0 |
||
34 | * @access public |
||
35 | * |
||
36 | * @param array $args Options for the upgrader, see WP_Upgrader_Skin::__construct(). |
||
37 | */ |
||
38 | public function __construct( $args = array() ) { |
||
43 | |||
44 | /** |
||
45 | * Retrieves the list of errors. |
||
46 | * |
||
47 | * @since 4.6.0 |
||
48 | * @access public |
||
49 | * |
||
50 | * @return WP_Error Errors during an upgrade. |
||
51 | */ |
||
52 | public function get_errors() { |
||
55 | |||
56 | /** |
||
57 | * Retrieves a string for error messages. |
||
58 | * |
||
59 | * @since 4.6.0 |
||
60 | * @access public |
||
61 | * |
||
62 | * @return string Error messages during an upgrade. |
||
63 | */ |
||
64 | public function get_error_messages() { |
||
77 | |||
78 | /** |
||
79 | * Stores a log entry for an error. |
||
80 | * |
||
81 | * @since 4.6.0 |
||
82 | * @access public |
||
83 | * |
||
84 | * @param string|WP_Error $errors Errors. |
||
85 | */ |
||
86 | public function error( $errors ) { |
||
113 | |||
114 | /** |
||
115 | * Stores a log entry. |
||
116 | * |
||
117 | * @since 4.6.0 |
||
118 | * @access public |
||
119 | * |
||
120 | * @param string|array|WP_Error $data Log entry data. |
||
121 | */ |
||
122 | public function feedback( $data ) { |
||
132 | } |
||
133 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.