Total Complexity | 41 |
Total Lines | 268 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like Manager 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.
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 Manager, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
48 | class Manager implements IManager { |
||
49 | |||
50 | /** @var ILogger */ |
||
51 | private $log; |
||
52 | |||
53 | /** @var IL10N */ |
||
54 | private $l; |
||
55 | |||
56 | /** @var IFactory */ |
||
57 | private $l10nFactory; |
||
58 | |||
59 | /** @var IURLGenerator */ |
||
60 | private $url; |
||
61 | |||
62 | /** @var IServerContainer */ |
||
63 | private $container; |
||
64 | |||
65 | public function __construct( |
||
66 | ILogger $log, |
||
67 | IFactory $l10nFactory, |
||
68 | IURLGenerator $url, |
||
69 | IServerContainer $container |
||
70 | ) { |
||
71 | $this->log = $log; |
||
72 | $this->l10nFactory = $l10nFactory; |
||
73 | $this->url = $url; |
||
74 | $this->container = $container; |
||
75 | } |
||
76 | |||
77 | /** @var array */ |
||
78 | protected $sectionClasses = []; |
||
79 | |||
80 | /** @var array */ |
||
81 | protected $sections = []; |
||
82 | |||
83 | /** |
||
84 | * @param string $type 'admin' or 'personal' |
||
85 | * @param string $section Class must implement OCP\Settings\ISection |
||
86 | * |
||
87 | * @return void |
||
88 | */ |
||
89 | public function registerSection(string $type, string $section) { |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * @param string $type 'admin' or 'personal' |
||
99 | * |
||
100 | * @return ISection[] |
||
101 | */ |
||
102 | protected function getSections(string $type): array { |
||
138 | } |
||
139 | |||
140 | /** @var array */ |
||
141 | protected $settingClasses = []; |
||
142 | |||
143 | /** @var array */ |
||
144 | protected $settings = []; |
||
145 | |||
146 | /** |
||
147 | * @param string $type 'admin' or 'personal' |
||
148 | * @param string $setting Class must implement OCP\Settings\ISetting |
||
149 | * |
||
150 | * @return void |
||
151 | */ |
||
152 | public function registerSetting(string $type, string $setting) { |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * @param string $type 'admin' or 'personal' |
||
158 | * @param string $section |
||
159 | * @param Closure $filter optional filter to apply on all loaded ISettings |
||
160 | * |
||
161 | * @return ISettings[] |
||
162 | */ |
||
163 | protected function getSettings(string $type, string $section, Closure $filter = null): array { |
||
205 | } |
||
206 | |||
207 | /** |
||
208 | * @inheritdoc |
||
209 | */ |
||
210 | public function getAdminSections(): array { |
||
228 | } |
||
229 | |||
230 | /** |
||
231 | * @inheritdoc |
||
232 | */ |
||
233 | public function getAdminSettings($section, bool $subAdminOnly = false): array { |
||
234 | if ($subAdminOnly) { |
||
235 | $subAdminSettingsFilter = function(ISettings $settings) { |
||
236 | return $settings instanceof ISubAdminSettings; |
||
237 | }; |
||
238 | $appSettings = $this->getSettings('admin', $section, $subAdminSettingsFilter); |
||
239 | } else { |
||
240 | $appSettings = $this->getSettings('admin', $section); |
||
241 | } |
||
242 | |||
243 | $settings = []; |
||
244 | foreach ($appSettings as $setting) { |
||
245 | if (!isset($settings[$setting->getPriority()])) { |
||
246 | $settings[$setting->getPriority()] = []; |
||
247 | } |
||
248 | $settings[$setting->getPriority()][] = $setting; |
||
249 | } |
||
250 | |||
251 | ksort($settings); |
||
252 | return $settings; |
||
253 | } |
||
254 | |||
255 | /** |
||
256 | * @inheritdoc |
||
257 | */ |
||
258 | public function getPersonalSections(): array { |
||
259 | if ($this->l === null) { |
||
260 | $this->l = $this->l10nFactory->get('lib'); |
||
261 | } |
||
262 | |||
263 | $sections = []; |
||
264 | |||
265 | $legacyForms = \OC_App::getForms('personal'); |
||
266 | if (!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms)) { |
||
267 | $sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))]; |
||
268 | } |
||
269 | |||
270 | $appSections = $this->getSections('personal'); |
||
271 | |||
272 | foreach ($appSections as $section) { |
||
273 | /** @var ISection $section */ |
||
274 | if (!isset($sections[$section->getPriority()])) { |
||
275 | $sections[$section->getPriority()] = []; |
||
276 | } |
||
277 | |||
278 | $sections[$section->getPriority()][] = $section; |
||
279 | } |
||
280 | |||
281 | ksort($sections); |
||
282 | |||
283 | return $sections; |
||
284 | } |
||
285 | |||
286 | /** |
||
287 | * @param string[] $forms |
||
288 | * |
||
289 | * @return bool |
||
290 | */ |
||
291 | private function hasLegacyPersonalSettingsToRender(array $forms): bool { |
||
292 | foreach ($forms as $form) { |
||
293 | if (trim($form) !== '') { |
||
294 | return true; |
||
295 | } |
||
296 | } |
||
297 | return false; |
||
298 | } |
||
299 | |||
300 | /** |
||
301 | * @inheritdoc |
||
302 | */ |
||
303 | public function getPersonalSettings($section): array { |
||
316 | } |
||
317 | } |
||
318 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths