Complex classes like TemplateManager often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use TemplateManager, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
38 | class TemplateManager { |
||
39 | |||
40 | /** @var string */ |
||
41 | protected $appName; |
||
42 | |||
43 | /** @var string */ |
||
44 | protected $userId; |
||
45 | |||
46 | /** @var IConfig */ |
||
47 | private $config; |
||
48 | |||
49 | /** @var IURLGenerator */ |
||
50 | private $urlGenerator; |
||
51 | |||
52 | /** @var IRootFolder */ |
||
53 | private $rootFolder; |
||
54 | |||
55 | /** @var IL10N */ |
||
56 | private $l; |
||
57 | |||
58 | /** Accepted templates mime types */ |
||
59 | const MIMES_DOCUMENTS = [ |
||
60 | 'application/vnd.oasis.opendocument.text-template' |
||
61 | ]; |
||
62 | const MIMES_SHEETS = [ |
||
63 | 'application/vnd.oasis.opendocument.spreadsheet-template' |
||
64 | ]; |
||
65 | const MIMES_PRESENTATIONS = [ |
||
66 | 'application/vnd.oasis.opendocument.presentation-template' |
||
67 | ]; |
||
68 | |||
69 | /** @var array Template mime types match */ |
||
70 | static public $tplTypes = [ |
||
71 | 'document' => self::MIMES_DOCUMENTS, |
||
72 | 'spreadsheet' => self::MIMES_SHEETS, |
||
73 | 'presentation' => self::MIMES_PRESENTATIONS |
||
74 | ]; |
||
75 | |||
76 | const EMPTY_TEMPLATE_ID_TYPE = [ |
||
77 | -1 => 'document', |
||
78 | -2 => 'spreadsheet', |
||
79 | -3 => 'presentation', |
||
80 | ]; |
||
81 | const EMPTY_TEMPLATE_TYPE_ID = [ |
||
82 | 'document' => -1, |
||
83 | 'spreadsheet' => -2, |
||
84 | 'presentation' => -3, |
||
85 | ]; |
||
86 | const TYPE_EXTENTION = [ |
||
87 | 'document' => 'odt', |
||
88 | 'spreadsheet' => 'ods', |
||
89 | 'presentation' => 'odp', |
||
90 | ]; |
||
91 | |||
92 | |||
93 | /** |
||
94 | * Template manager |
||
95 | * |
||
96 | * @param string $appName |
||
97 | * @param string $userId |
||
98 | * @param IConfig $config |
||
99 | * @param Factory $appDataFactory |
||
100 | * @param IURLGenerator $urlGenerator |
||
101 | * @param IRootFolder $rootFolder |
||
102 | * @param IL10N $l |
||
103 | * @throws \OCP\Files\NotPermittedException |
||
104 | */ |
||
105 | public function __construct($appName, |
||
137 | |||
138 | public function setUserId($userId) { |
||
141 | |||
142 | /** |
||
143 | * Get template ISimpleFile|Node |
||
144 | * |
||
145 | * @param int $fileId |
||
146 | * @return File |
||
147 | */ |
||
148 | public function get($fileId) { |
||
176 | |||
177 | /** |
||
178 | * @param File[] $templates |
||
179 | * @return File[] |
||
180 | */ |
||
181 | private function filterTemplates($templates, $type = null) { |
||
196 | |||
197 | private function getEmpty($type = null) { |
||
219 | |||
220 | /** |
||
221 | * Get all global templates |
||
222 | * |
||
223 | * @return File[] |
||
224 | */ |
||
225 | public function getSystem($type = null) { |
||
231 | |||
232 | /** |
||
233 | * @return array |
||
234 | */ |
||
235 | public function getSystemFormatted($type = null) { |
||
249 | |||
250 | /** |
||
251 | * Get all user templates |
||
252 | * |
||
253 | * @return File[] |
||
254 | */ |
||
255 | public function getUser($type = null) { |
||
265 | |||
266 | /** |
||
267 | * @return array |
||
268 | */ |
||
269 | public function getUserFormatted($type) { |
||
276 | |||
277 | /** |
||
278 | * Get all templates |
||
279 | * |
||
280 | * @return File[] |
||
281 | */ |
||
282 | public function getAll($type = 'document') { |
||
299 | |||
300 | public function getAllFormatted($type) { |
||
310 | |||
311 | /** |
||
312 | * Add a template to the global template folder |
||
313 | * |
||
314 | * @param string $templateName |
||
315 | * @param string $templateFile |
||
316 | * @return array |
||
317 | */ |
||
318 | public function add($templateName, $templateFile) { |
||
330 | |||
331 | /** |
||
332 | * Delete a template to the global template folder |
||
333 | * |
||
334 | * @param int $fileId |
||
335 | * @return boolean |
||
336 | * @throws NotFoundException |
||
337 | */ |
||
338 | public function delete($fileId) { |
||
349 | |||
350 | /** |
||
351 | * Flip $tplTypes to retrieve types by mime |
||
352 | * |
||
353 | * @return array |
||
354 | */ |
||
355 | private function flipTypes() { |
||
363 | |||
364 | /** |
||
365 | * Get the user template directory |
||
366 | * |
||
367 | * @return Folder |
||
368 | * @throws NotFoundException |
||
369 | */ |
||
370 | private function getUserTemplateDir() { |
||
396 | |||
397 | /** |
||
398 | * @return Folder |
||
399 | */ |
||
400 | private function getSystemTemplateDir() { |
||
405 | |||
406 | /** |
||
407 | * @return Folder |
||
408 | */ |
||
409 | private function getEmptyTemplateDir() { |
||
414 | |||
415 | /** |
||
416 | * Format template file for json return object |
||
417 | * |
||
418 | * @param File $template |
||
419 | * @return array |
||
420 | */ |
||
421 | public function formatNodeReturn(File $template) { |
||
431 | |||
432 | public function isTemplate($fileId) { |
||
447 | |||
448 | public function formatEmpty(File $template) { |
||
456 | } |
||
457 |
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.