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 namespace Propaganistas\LaravelIntl; |
||
6 | class Date |
||
7 | { |
||
8 | /** |
||
9 | * @var \Jenssegers\Date\Date |
||
10 | */ |
||
11 | protected $date; |
||
12 | |||
13 | /** |
||
14 | * Date constructor. |
||
15 | */ |
||
16 | 12 | public function __construct() |
|
22 | |||
23 | /** |
||
24 | * Handle dynamic calls to the object. |
||
25 | * |
||
26 | * @param string $method |
||
27 | * @param array $args |
||
28 | * @return mixed |
||
29 | */ |
||
30 | 12 | public function __call($method, $args) |
|
38 | |||
39 | /** |
||
40 | * Handle dynamic, static calls to the object. |
||
41 | * |
||
42 | * @param string $method |
||
43 | * @param array $args |
||
44 | * @return mixed |
||
45 | */ |
||
46 | public static function __callStatic($method, $args) |
||
47 | { |
||
48 | $instance = new static; |
||
49 | |||
50 | View Code Duplication | if (method_exists($instance, '_' . $method)) { |
|
51 | return call_user_func_array([$instance, '_' . $method], $args); |
||
52 | } |
||
53 | |||
54 | return call_user_func_array([$instance, $method], $args); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Spoofed setLocale method. |
||
59 | * |
||
60 | * @param string $locale |
||
61 | * @return $this |
||
62 | */ |
||
63 | 12 | public function _setLocale($locale) |
|
69 | |||
70 | /** |
||
71 | * Spoofed setFallbackLocale method. |
||
72 | * |
||
73 | * @param string $locale |
||
74 | * @return $this |
||
75 | */ |
||
76 | 12 | public function _setFallbackLocale($locale) |
|
82 | } |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.