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 |
||
9 | class File extends Field |
||
10 | { |
||
11 | use UploadField; |
||
12 | |||
13 | /** |
||
14 | * Css. |
||
15 | * |
||
16 | * @var array |
||
17 | */ |
||
18 | protected static $css = [ |
||
19 | '/vendor/laravel-admin/bootstrap-fileinput/css/fileinput.min.css?v=4.3.7', |
||
20 | ]; |
||
21 | |||
22 | /** |
||
23 | * Js. |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | protected static $js = [ |
||
28 | '/vendor/laravel-admin/bootstrap-fileinput/js/plugins/canvas-to-blob.min.js?v=4.3.7', |
||
29 | '/vendor/laravel-admin/bootstrap-fileinput/js/fileinput.min.js?v=4.3.7', |
||
30 | ]; |
||
31 | |||
32 | /** |
||
33 | * Create a new File instance. |
||
34 | * |
||
35 | * @param string $column |
||
36 | * @param array $arguments |
||
37 | */ |
||
38 | public function __construct($column, $arguments = []) |
||
44 | |||
45 | /** |
||
46 | * Default directory for file to upload. |
||
47 | * |
||
48 | * @return mixed |
||
49 | */ |
||
50 | public function defaultDirectory() |
||
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | public function getValidator(array $input) |
||
94 | |||
95 | /** |
||
96 | * Prepare for saving. |
||
97 | * |
||
98 | * @param UploadedFile|array $file |
||
99 | * |
||
100 | * @return mixed|string |
||
101 | */ |
||
102 | View Code Duplication | public function prepare($file) |
|
112 | |||
113 | /** |
||
114 | * Upload file and delete original file. |
||
115 | * |
||
116 | * @param UploadedFile $file |
||
117 | * |
||
118 | * @return mixed |
||
119 | */ |
||
120 | protected function uploadAndDeleteOriginal(UploadedFile $file) |
||
130 | |||
131 | /** |
||
132 | * Preview html for file-upload plugin. |
||
133 | * |
||
134 | * @return string |
||
135 | */ |
||
136 | protected function preview() |
||
140 | |||
141 | /** |
||
142 | * Initialize the caption. |
||
143 | * |
||
144 | * @param string $caption |
||
145 | * |
||
146 | * @return string |
||
147 | */ |
||
148 | protected function initialCaption($caption) |
||
152 | |||
153 | /** |
||
154 | * @return array |
||
155 | */ |
||
156 | protected function initialPreviewConfig() |
||
162 | |||
163 | /** |
||
164 | * Render file upload field. |
||
165 | * |
||
166 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
167 | */ |
||
168 | View Code Duplication | public function render() |
|
190 | } |
||
191 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.