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 |
||
27 | class FileService { |
||
28 | |||
29 | /** |
||
30 | * |
||
31 | * @var ILogger |
||
32 | */ |
||
33 | private $logger; |
||
34 | |||
35 | /** |
||
36 | * |
||
37 | * @var FileMapper |
||
38 | */ |
||
39 | private $fileMapper; |
||
40 | |||
41 | /** |
||
42 | * |
||
43 | * @var ShareMapper |
||
44 | */ |
||
45 | private $shareMapper; |
||
46 | |||
47 | /** |
||
48 | * |
||
49 | * @var string |
||
50 | */ |
||
51 | private $userId; |
||
52 | |||
53 | /** |
||
54 | * |
||
55 | * @var IL10N |
||
56 | */ |
||
57 | private $l10n; |
||
58 | |||
59 | public function __construct(IL10N $l10n, ILogger $logger, $userId, FileMapper $fileMapper, ShareMapper $shareMapper) { |
||
66 | |||
67 | /** |
||
68 | * Checks if shared with the process initiator |
||
69 | * |
||
70 | * @param File $fileInfo |
||
71 | * @return boolean|null |
||
72 | */ |
||
73 | public function checkSharedWithInitiator($fileInfo) { |
||
87 | |||
88 | /** |
||
89 | * Builds the target name. |
||
90 | * |
||
91 | * @param File $fileInfo |
||
92 | * @param boolean $shared |
||
93 | * @return string |
||
94 | */ |
||
95 | public function buildTarget($fileInfo, $shared) { |
||
103 | |||
104 | /** |
||
105 | * Builds the source name. |
||
106 | * |
||
107 | * @param File $fileInfo |
||
108 | * @param boolean $shared |
||
109 | * @return string |
||
110 | */ |
||
111 | public function buildSource($fileInfo, $shared) { |
||
120 | |||
121 | /** |
||
122 | * Returns the fileInfo for each file in files and checks |
||
123 | * if it has a allowed MIME type and some other conditions. |
||
124 | * |
||
125 | * @param array $files |
||
126 | * @return File[] |
||
127 | * @throws NotFoundException |
||
128 | */ |
||
129 | public function buildFileInfo($files) { |
||
149 | |||
150 | /** |
||
151 | * Removes ".txt" from the newName of a OCR job |
||
152 | * |
||
153 | * @param $job OcrJob |
||
154 | * @return string |
||
155 | */ |
||
156 | public function removeFileExtension($job) { |
||
159 | |||
160 | /** |
||
161 | * Determines the correct type for the ocr process worker. |
||
162 | * |
||
163 | * @param File $fileInfo |
||
164 | * @return integer |
||
165 | */ |
||
166 | public function getCorrectType($fileInfo) { |
||
173 | |||
174 | /** |
||
175 | * Executes the exec function with a remove statement for a given file path. |
||
176 | * |
||
177 | * @codeCoverageIgnore |
||
178 | * |
||
179 | * @param string $pathToFile |
||
180 | */ |
||
181 | public function execRemove($pathToFile) { |
||
184 | |||
185 | /** |
||
186 | * Wraps the static file_get_contents method of php. |
||
187 | * |
||
188 | * @codeCoverageIgnore |
||
189 | * |
||
190 | * @param string $pathToFile |
||
191 | * @return string |
||
192 | */ |
||
193 | public function getFileContents($pathToFile) { |
||
196 | |||
197 | /** |
||
198 | * Wraps the static file_exists method of php. |
||
199 | * |
||
200 | * @codeCoverageIgnore |
||
201 | * |
||
202 | * @param string $pathToFile |
||
203 | * @return boolean |
||
204 | */ |
||
205 | public function fileExists($pathToFile) { |
||
208 | |||
209 | /** |
||
210 | * Returns a not existing file name for pdf or image processing |
||
211 | * protected as of testing issues with static methods. |
||
212 | * (Actually |
||
213 | * it will be mocked partially) FIXME: Change this behaviour as soon as the buidlNotExistingFileName function is not static anymore |
||
214 | * @codeCoverageIgnore |
||
215 | * |
||
216 | * @param File $fileInfo |
||
217 | * @return string |
||
218 | */ |
||
219 | protected function buildTargetForShared(File $fileInfo) { |
||
249 | |||
250 | /** |
||
251 | * Returns a not existing file name for PDF or image processing |
||
252 | * protected as of testing issues with static methods. |
||
253 | * (Actually |
||
254 | * it will be mocked partially) FIXME: Change this behaviour as soon as the buidlNotExistingFileName function is not static anymore |
||
255 | * @codeCoverageIgnore |
||
256 | * |
||
257 | * @param File $fileInfo |
||
258 | * @return string |
||
259 | */ |
||
260 | protected function buildTargetNotForShared(File $fileInfo) { |
||
291 | |||
292 | /** |
||
293 | * Checks a MIME type for a specifically given FileInfo. |
||
294 | * |
||
295 | * @param File $fileInfo |
||
296 | */ |
||
297 | private function checkMimeType(File $fileInfo) { |
||
307 | |||
308 | /** |
||
309 | * Handle the possible thrown Exceptions from all methods of this class. |
||
310 | * |
||
311 | * @param Exception $e |
||
312 | * @throws Exception |
||
313 | * @throws NotFoundException |
||
314 | */ |
||
315 | View Code Duplication | private function handleException($e) { |
|
326 | } |
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.