Complex classes like Merge 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 Merge, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
8 | final class Merge |
||
9 | { |
||
10 | const ADD = 1; |
||
11 | const REMOVE = 2; |
||
12 | |||
13 | const HEADERS_ADD = 4; |
||
14 | const HEADERS_REMOVE = 8; |
||
15 | const HEADERS_OVERRIDE = 16; |
||
16 | |||
17 | const LANGUAGE_OVERRIDE = 32; |
||
18 | const DOMAIN_OVERRIDE = 64; |
||
19 | const TRANSLATION_OVERRIDE = 128; |
||
20 | |||
21 | const COMMENTS_OURS = 256; |
||
22 | const COMMENTS_THEIRS = 512; |
||
23 | |||
24 | const EXTRACTED_COMMENTS_OURS = 1024; |
||
25 | const EXTRACTED_COMMENTS_THEIRS = 2048; |
||
26 | |||
27 | const FLAGS_OURS = 4096; |
||
28 | const FLAGS_THEIRS = 8192; |
||
29 | |||
30 | const REFERENCES_OURS = 16384; |
||
31 | const REFERENCES_THEIRS = 32768; |
||
32 | |||
33 | const DEFAULTS = 5; //1 + 4 |
||
34 | |||
35 | /** |
||
36 | * Merge the flags of two translations. |
||
37 | * |
||
38 | * @param Translation $from |
||
39 | * @param Translation $to |
||
40 | * @param int $options |
||
41 | */ |
||
42 | public static function mergeFlags(Translation $from, Translation $to, $options = self::DEFAULTS) |
||
54 | |||
55 | /** |
||
56 | * Merge the extracted comments of two translations. |
||
57 | * |
||
58 | * @param Translation $from |
||
59 | * @param Translation $to |
||
60 | * @param int $options |
||
61 | */ |
||
62 | public static function mergeExtractedComments(Translation $from, Translation $to, $options = self::DEFAULTS) |
||
74 | |||
75 | /** |
||
76 | * Merge the comments of two translations. |
||
77 | * |
||
78 | * @param Translation $from |
||
79 | * @param Translation $to |
||
80 | * @param int $options |
||
81 | */ |
||
82 | public static function mergeComments(Translation $from, Translation $to, $options = self::DEFAULTS) |
||
94 | |||
95 | /** |
||
96 | * Merge the references of two translations. |
||
97 | * |
||
98 | * @param Translation $from |
||
99 | * @param Translation $to |
||
100 | * @param int $options |
||
101 | */ |
||
102 | public static function mergeReferences(Translation $from, Translation $to, $options = self::DEFAULTS) |
||
114 | |||
115 | /** |
||
116 | * Merge the translations of two translations. |
||
117 | * |
||
118 | * @param Translation $from |
||
119 | * @param Translation $to |
||
120 | * @param int $options |
||
121 | */ |
||
122 | public static function mergeTranslation(Translation $from, Translation $to, $options = self::DEFAULTS) |
||
138 | |||
139 | /** |
||
140 | * Merge the translations of two translations. |
||
141 | * |
||
142 | * @param Translations $from |
||
143 | * @param Translations $to |
||
144 | * @param int $options |
||
145 | */ |
||
146 | public static function mergeTranslations(Translations $from, Translations $to, $options = self::DEFAULTS) |
||
168 | |||
169 | /** |
||
170 | * Merge the headers of two translations. |
||
171 | * |
||
172 | * @param Translations $from |
||
173 | * @param Translations $to |
||
174 | * @param int $options |
||
175 | */ |
||
176 | public static function mergeHeaders(Translations $from, Translations $to, $options = self::DEFAULTS) |
||
221 | } |
||
222 |