Complex classes like BridgeFileSystem 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 BridgeFileSystem, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
20 | class BridgeFileSystem implements BridgeInterface |
||
21 | { |
||
22 | /** |
||
23 | * @var Filesystem |
||
24 | */ |
||
25 | private $fileSystemService; |
||
26 | |||
27 | /** |
||
28 | * @var CacheInterface |
||
29 | */ |
||
30 | private $cache; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | private $repositoryDir = ''; |
||
36 | |||
37 | /** |
||
38 | * @var string[] |
||
39 | */ |
||
40 | private $directorySeparators = ['.', ':', '-', '\\']; |
||
41 | |||
42 | /** |
||
43 | * @var array |
||
44 | */ |
||
45 | private $jobFileMap = []; |
||
46 | |||
47 | /** |
||
48 | * @var array |
||
49 | */ |
||
50 | private $groupedApps = []; |
||
51 | |||
52 | /** |
||
53 | * @param Filesystem $oFileSystemService |
||
54 | * @param CacheInterface $cache |
||
55 | * @param string $repositoryDir |
||
56 | */ |
||
57 | 9 | public function __construct( |
|
66 | |||
67 | /** |
||
68 | * @return JobEntityInterface[] |
||
69 | */ |
||
70 | 8 | public function getJobs() |
|
78 | |||
79 | /** |
||
80 | * @param ChronosJobEntity|JobEntityInterface $jobEntity |
||
81 | * @return bool |
||
82 | * @throws JobLoadException |
||
83 | */ |
||
84 | 2 | public function addJob(JobEntityInterface $jobEntity) |
|
96 | |||
97 | /** |
||
98 | * @param JobEntityInterface $jobEntity |
||
99 | * @return bool |
||
100 | */ |
||
101 | 3 | public function updateJob(JobEntityInterface $jobEntity) |
|
115 | |||
116 | /** |
||
117 | * @param ChronosJobEntity|JobEntityInterface $jobEntity |
||
118 | * @return bool |
||
119 | */ |
||
120 | 3 | public function removeJob(JobEntityInterface $jobEntity) |
|
139 | |||
140 | /** |
||
141 | * @param JobEntityInterface $jobEntity |
||
142 | * @return string |
||
143 | */ |
||
144 | 2 | private function generateJobFilePath(JobEntityInterface $jobEntity) |
|
158 | |||
159 | /** |
||
160 | * @param string $path |
||
161 | * @param array $jobFiles |
||
162 | * @return array |
||
163 | */ |
||
164 | 8 | private function getJobFilesFromFileSystem($path, array &$jobFiles = []) |
|
182 | |||
183 | /** |
||
184 | * @param string $jobName |
||
185 | * @param string $jobFile |
||
186 | * @throws JobLoadException |
||
187 | */ |
||
188 | 7 | private function setJobFileToMap($jobName, $jobFile) |
|
200 | |||
201 | /** |
||
202 | * @param string $jobName |
||
203 | * @return string |
||
204 | * @throws \RuntimeException |
||
205 | */ |
||
206 | 4 | private function getJobFileFromMap($jobName) |
|
213 | |||
214 | /** |
||
215 | * @param string $jobName |
||
216 | * @param string $jobFile |
||
217 | * @return bool |
||
218 | * @throws \RuntimeException |
||
219 | */ |
||
220 | 2 | private function hasUnsetJobFileFromMap($jobName, $jobFile = '') |
|
231 | |||
232 | /** |
||
233 | * @param array $jobFiles |
||
234 | * @param bool $setToFileMap |
||
235 | * @return JobEntityInterface[] |
||
236 | * @throws JobLoadException |
||
237 | */ |
||
238 | 8 | private function loadJobsFromFileContent(array $jobFiles, $setToFileMap) |
|
288 | |||
289 | |||
290 | 4 | private function getMarathonEntitiesForConfig($entityData) |
|
305 | |||
306 | /** |
||
307 | * @param string $jobFile |
||
308 | * @param JobEntityInterface $jobEntity |
||
309 | * @return bool |
||
310 | */ |
||
311 | 2 | private function hasDumpFile($jobFile, JobEntityInterface $jobEntity) |
|
320 | |||
321 | /** |
||
322 | * @param string $jobFile |
||
323 | * @param JobEntityInterface $jobEntity |
||
324 | * @param bool $add |
||
325 | * @return bool |
||
326 | */ |
||
327 | 2 | private function dumpFileWithGroup($jobFile, JobEntityInterface $jobEntity, $add = true) |
|
383 | } |
||
384 |