Complex classes like CompositePropertyTableDiffIterator 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 CompositePropertyTableDiffIterator, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class CompositePropertyTableDiffIterator implements IteratorAggregate { |
||
17 | |||
18 | /** |
||
19 | * Type of change operations |
||
20 | */ |
||
21 | const TYPE_INSERT = 'insert'; |
||
22 | const TYPE_DELETE = 'delete'; |
||
23 | |||
24 | /** |
||
25 | * @var array |
||
26 | */ |
||
27 | private $diff = array(); |
||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | private $data = array(); |
||
33 | |||
34 | /** |
||
35 | * @var array |
||
36 | */ |
||
37 | private $orderedDiff = array(); |
||
38 | |||
39 | /** |
||
40 | * @var DIWikiPage |
||
41 | */ |
||
42 | private $subject; |
||
43 | 278 | ||
44 | 278 | /** |
|
45 | 278 | * @var string |
|
46 | */ |
||
47 | private $hash = ''; |
||
48 | |||
49 | /** |
||
50 | * @var array |
||
51 | */ |
||
52 | 272 | private $fixedPropertyRecords = array(); |
|
53 | 272 | ||
54 | 272 | /** |
|
55 | * @since 2.3 |
||
56 | * |
||
57 | * @param array $diff |
||
58 | */ |
||
59 | public function __construct( array $diff = array() ) { |
||
62 | |||
63 | /** |
||
64 | * @since 2.5 |
||
65 | * |
||
66 | * @return DIWikiPage $subject |
||
67 | */ |
||
68 | public function setSubject( DIWikiPage $subject ) { |
||
71 | 207 | ||
72 | /** |
||
73 | * @since 2.5 |
||
74 | * |
||
75 | * @return DIWikiPage |
||
76 | */ |
||
77 | public function getSubject() { |
||
80 | 1 | ||
81 | /** |
||
82 | * @since 2.3 |
||
83 | * |
||
84 | * @return ArrayIterator |
||
85 | */ |
||
86 | public function getIterator() { |
||
89 | 271 | ||
90 | /** |
||
91 | * @since 2.5 |
||
92 | 271 | * |
|
93 | 271 | * @return string |
|
94 | */ |
||
95 | public function getHash() { |
||
98 | 271 | ||
99 | 271 | /** |
|
100 | * @since 3.0 |
||
101 | * |
||
102 | * @param array $data |
||
103 | */ |
||
104 | public function addDataRecord( $hash, array $data ) { |
||
107 | 234 | ||
108 | 234 | /** |
|
109 | * @since 3.0 |
||
110 | * |
||
111 | * @return TableChangeOp[] |
||
112 | */ |
||
113 | public function getDataChangeOps() { |
||
125 | |||
126 | /** |
||
127 | * @since 2.3 |
||
128 | * |
||
129 | 203 | * @param array $insertChangeOp |
|
130 | * @param array $deleteChangeOp |
||
131 | 203 | */ |
|
132 | public function addTableDiffChangeOp( array $insertChangeOp, array $deleteChangeOp ) { |
||
143 | |||
144 | /** |
||
145 | * @since 2.3 |
||
146 | * |
||
147 | * @param array $fixedPropertyRecord |
||
148 | 207 | */ |
|
149 | public function addFixedPropertyRecord( $tableName, array $fixedPropertyRecord ) { |
||
152 | 207 | ||
153 | 205 | /** |
|
154 | 205 | * @since 2.4 |
|
155 | * |
||
156 | 200 | * @return array |
|
157 | 199 | */ |
|
158 | public function getFixedPropertyRecords() { |
||
161 | 195 | ||
162 | /** |
||
163 | * ChangeOp (TableChangeOp/FieldChangeOp) representation of the composite |
||
164 | 200 | * diff. |
|
165 | 184 | * |
|
166 | * @since 2.4 |
||
167 | * |
||
168 | 200 | * @param string|null $table |
|
169 | 200 | * |
|
170 | * @return TableChangeOp[]|[] |
||
|
|||
171 | */ |
||
172 | 200 | public function getTableChangeOps( $table = null ) { |
|
182 | |||
183 | /** |
||
184 | * Simplified (ordered by table) diff array to allow for an easier |
||
185 | * post-processing |
||
186 | * |
||
187 | 205 | * @since 2.3 |
|
188 | * |
||
189 | 205 | * @return array |
|
190 | */ |
||
191 | 205 | public function getOrderedDiffByTable( $table = null ) { |
|
232 | |||
233 | /** |
||
234 | * @since 3.0 |
||
235 | * |
||
236 | * @param string|null $type |
||
237 | * |
||
238 | * @return array |
||
239 | */ |
||
240 | public function getListOfChangedEntityIdsByType( $type = null ) { |
||
261 | |||
262 | /** |
||
263 | * @since 2.3 |
||
264 | * |
||
265 | * @return array |
||
266 | */ |
||
267 | public function getCombinedIdListOfChangedEntities() { |
||
270 | |||
271 | private function addToIdList( &$list, $value ) { |
||
287 | |||
288 | } |
||
289 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.