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 |
||
20 | class UiOptionsStorage extends Component implements OrientationInterface |
||
21 | { |
||
22 | /** |
||
23 | * @var string the cache key that will be used to cache storage values |
||
24 | */ |
||
25 | public $cacheKey; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | public $settingsStorageKey = 'uiOptions'; |
||
31 | |||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $storage; |
||
36 | |||
37 | /** |
||
38 | * {@inheritdoc} |
||
39 | */ |
||
40 | public function init() |
||
46 | |||
47 | /** |
||
48 | * @return \yii\caching\Cache |
||
49 | */ |
||
50 | protected function getCache() |
||
54 | |||
55 | /** |
||
56 | * @return SettingsStorageInterface |
||
57 | */ |
||
58 | protected function getSettingsStorage() |
||
62 | |||
63 | /** |
||
64 | * Ensures that [[storage]] contains actual orientations storage. |
||
65 | * |
||
66 | * @return array |
||
67 | */ |
||
68 | View Code Duplication | private function ensureStorage() |
|
81 | |||
82 | /** |
||
83 | * Saves current [[storage]]. |
||
84 | */ |
||
85 | protected function saveStorage() |
||
90 | |||
91 | /** |
||
92 | * Caches current [[storage]]. |
||
93 | */ |
||
94 | protected function cache() |
||
98 | |||
99 | /** |
||
100 | * Sets orientation for the $route. |
||
101 | * |
||
102 | * @param string $route |
||
103 | * @param string $orientation |
||
104 | */ |
||
105 | public function set($route, $options = []) |
||
112 | |||
113 | /** |
||
114 | * Gets orientation for the $route. |
||
115 | * |
||
116 | * @param $route |
||
117 | * @return string |
||
118 | */ |
||
119 | public function get($route) |
||
125 | |||
126 | /** |
||
127 | * @return string |
||
128 | */ |
||
129 | View Code Duplication | public function getDefaultOption() |
|
139 | |||
140 | public function getOption($option) |
||
144 | |||
145 | public function getAllUiOptions() |
||
149 | } |
||
150 |
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..