Complex classes like SettingsManager 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 SettingsManager, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
28 | class SettingsManager |
||
29 | { |
||
30 | /** |
||
31 | * Symfony event dispatcher. |
||
32 | * |
||
33 | * @var EventDispatcherInterface |
||
34 | */ |
||
35 | private $eventDispatcher; |
||
36 | |||
37 | /** |
||
38 | * Elasticsearch manager which handles setting repository. |
||
39 | * |
||
40 | * @var Manager |
||
41 | */ |
||
42 | private $manager; |
||
43 | |||
44 | /** |
||
45 | * Settings repository. |
||
46 | * |
||
47 | * @var Repository |
||
48 | */ |
||
49 | private $repo; |
||
50 | |||
51 | /** |
||
52 | * Cache pool container. |
||
53 | * |
||
54 | * @var CacheProvider |
||
55 | */ |
||
56 | private $cache; |
||
57 | |||
58 | /** |
||
59 | * Cookie storage for active cookies. |
||
60 | * |
||
61 | * @var GenericCookie |
||
62 | */ |
||
63 | private $activeProfilesCookie; |
||
64 | |||
65 | /** |
||
66 | * Active profiles setting name to store in the cache engine. |
||
67 | * |
||
68 | * @var string |
||
69 | */ |
||
70 | private $activeProfilesSettingName; |
||
71 | |||
72 | /** |
||
73 | * Active profiles list collected from es, cache and cookie. |
||
74 | * |
||
75 | * @var array |
||
76 | */ |
||
77 | private $activeProfilesList = []; |
||
78 | |||
79 | /** |
||
80 | * @param Repository $repo |
||
81 | * @param EventDispatcherInterface $eventDispatcher |
||
82 | */ |
||
83 | public function __construct( |
||
91 | |||
92 | /** |
||
93 | * @return CacheProvider |
||
94 | */ |
||
95 | public function getCache() |
||
99 | |||
100 | /** |
||
101 | * @param CacheProvider $cache |
||
102 | */ |
||
103 | public function setCache($cache) |
||
107 | |||
108 | /** |
||
109 | * @return GenericCookie |
||
110 | */ |
||
111 | public function getActiveProfilesCookie() |
||
115 | |||
116 | /** |
||
117 | * @param GenericCookie $activeProfilesCookie |
||
118 | */ |
||
119 | public function setActiveProfilesCookie($activeProfilesCookie) |
||
123 | |||
124 | /** |
||
125 | * @return string |
||
126 | */ |
||
127 | public function getActiveProfilesSettingName() |
||
131 | |||
132 | /** |
||
133 | * @param string $activeProfilesSettingName |
||
134 | */ |
||
135 | public function setActiveProfilesSettingName($activeProfilesSettingName) |
||
139 | |||
140 | /** |
||
141 | * @return array |
||
142 | */ |
||
143 | public function getActiveProfilesList() |
||
147 | |||
148 | /** |
||
149 | * @param array $activeProfilesList |
||
150 | */ |
||
151 | public function setActiveProfilesList(array $activeProfilesList) |
||
155 | |||
156 | /** |
||
157 | * @param array $activeProfilesList |
||
158 | */ |
||
159 | public function appendActiveProfilesList(array $activeProfilesList) |
||
163 | |||
164 | /** |
||
165 | * Creates setting. |
||
166 | * |
||
167 | * @param array $data |
||
168 | * |
||
169 | * @return Setting |
||
170 | */ |
||
171 | public function create(array $data = []) |
||
203 | |||
204 | /** |
||
205 | * Overwrites setting parameters with given name. |
||
206 | * |
||
207 | * @param string $name |
||
208 | * @param array $data |
||
209 | * |
||
210 | * @return Setting |
||
211 | */ |
||
212 | public function update($name, $data = []) |
||
230 | |||
231 | /** |
||
232 | * Deletes a setting. |
||
233 | * |
||
234 | * @param string $name |
||
235 | * |
||
236 | * @throws \LogicException |
||
237 | * @return array |
||
238 | */ |
||
239 | public function delete($name) |
||
248 | |||
249 | /** |
||
250 | * Returns setting object. |
||
251 | * |
||
252 | * @param string $name |
||
253 | * |
||
254 | * @return Setting |
||
255 | */ |
||
256 | public function get($name) |
||
263 | |||
264 | /** |
||
265 | * Returns setting object. |
||
266 | * |
||
267 | * @param string $name |
||
268 | * |
||
269 | * @return bool |
||
270 | */ |
||
271 | public function has($name) |
||
282 | |||
283 | /** |
||
284 | * Get setting value by current active profiles setting. |
||
285 | * |
||
286 | * @param string $name |
||
287 | * @param bool $default |
||
288 | * |
||
289 | * @return string|array|bool |
||
290 | */ |
||
291 | public function getValue($name, $default = null) |
||
301 | |||
302 | /** |
||
303 | * Get setting value by checking also from cache engine. |
||
304 | * |
||
305 | * @param string $name |
||
306 | * @param bool $checkWithActiveProfiles Checks if setting is in active profile. |
||
307 | * |
||
308 | * @return mixed |
||
309 | */ |
||
310 | public function getCachedValue($name, $checkWithActiveProfiles = true) |
||
335 | |||
336 | /** |
||
337 | * Get all full profile information. |
||
338 | * |
||
339 | * @return array |
||
340 | */ |
||
341 | public function getAllProfiles() |
||
373 | |||
374 | /** |
||
375 | * Returns profiles settings array |
||
376 | * |
||
377 | * @param string $profile |
||
378 | * |
||
379 | * @return array |
||
380 | */ |
||
381 | public function getProfileSettings($profile) |
||
392 | |||
393 | /** |
||
394 | * Returns cached active profiles names list. |
||
395 | * |
||
396 | * @return array |
||
397 | */ |
||
398 | public function getActiveProfiles() |
||
421 | } |
||
422 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.