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 |
||
10 | class Select extends Field |
||
11 | { |
||
12 | |||
13 | protected $direction = "ltr"; |
||
14 | |||
15 | protected static $css = [ |
||
16 | '/vendor/laravel-admin/AdminLTE/plugins/select2/select2.min.css', |
||
17 | ]; |
||
18 | |||
19 | protected static $js = [ |
||
20 | '/vendor/laravel-admin/AdminLTE/plugins/select2/select2.full.min.js', |
||
21 | ]; |
||
22 | |||
23 | public function render() |
||
48 | |||
49 | /** |
||
50 | * Set options. |
||
51 | * |
||
52 | * @param array|callable|string $options |
||
53 | * |
||
54 | * @return $this|mixed |
||
55 | */ |
||
56 | public function options($options = []) |
||
78 | |||
79 | /** |
||
80 | * Set direction setting of select2. |
||
81 | * |
||
82 | */ |
||
83 | public function dir($dir = 'ltr') |
||
89 | |||
90 | /** |
||
91 | * Load options for other select on change. |
||
92 | * |
||
93 | * @param string $field |
||
94 | * @param string $sourceUrl |
||
95 | * @param string $idField |
||
96 | * @param string $textField |
||
97 | * |
||
98 | * @return $this |
||
99 | */ |
||
100 | public function load($field, $sourceUrl, $idField = 'id', $textField = 'text') |
||
135 | |||
136 | /** |
||
137 | * Load options from remote. |
||
138 | * |
||
139 | * @param string $url |
||
140 | * @param array $parameters |
||
141 | * @param array $options |
||
142 | * |
||
143 | * @return $this |
||
144 | */ |
||
145 | protected function loadOptionsFromRemote($url, $parameters = [], $options = []) |
||
167 | |||
168 | /** |
||
169 | * Load options from ajax results. |
||
170 | * |
||
171 | * @param string $url |
||
172 | * @param $idField |
||
173 | * @param $textField |
||
174 | * |
||
175 | * @return $this |
||
176 | */ |
||
177 | View Code Duplication | public function ajax($url, $idField = 'id', $textField = 'text') |
|
220 | } |
||
221 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: