Complex classes like SRFExcel 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 SRFExcel, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class SRFExcel extends FileExportPrinter { |
||
20 | |||
21 | const HEADER_ROW_OFFSET = 1; |
||
22 | |||
23 | /** |
||
24 | * @var int |
||
25 | */ |
||
26 | protected $rowNum; |
||
27 | |||
28 | /** |
||
29 | * @var int |
||
30 | */ |
||
31 | protected $colNum; |
||
32 | |||
33 | /** |
||
34 | * @var \PHPExcel_Worksheet |
||
35 | */ |
||
36 | protected $sheet; |
||
37 | |||
38 | protected $styled = false; |
||
39 | |||
40 | /** |
||
41 | * Some printers do not mainly produce embeddable HTML or Wikitext, but |
||
42 | * produce stand-alone files. An example is RSS or iCalendar. This function |
||
43 | * returns the mimetype string that this file would have, or FALSE if no |
||
44 | * standalone files are produced. |
||
45 | * |
||
46 | * If this function returns something other than FALSE, then the printer will |
||
47 | * not be regarded as a printer that displays in-line results. This is used to |
||
48 | * determine if a file output should be generated in Special:Ask. |
||
49 | * |
||
50 | * @since 1.8 |
||
51 | * |
||
52 | * @param SMWQueryResult $queryResult |
||
53 | * |
||
54 | * @return string |
||
55 | */ |
||
56 | public function getMimeType( SMWQueryResult $queryResult ) { |
||
59 | |||
60 | public function getFileName( SMWQueryResult $queryResult ) { |
||
64 | |||
65 | public function outputAsFile( SMWQueryResult $queryResult, array $params ) { |
||
73 | |||
74 | /** |
||
75 | * @param $definitions \ParamProcessor\ParamDefinition[] |
||
76 | * |
||
77 | * @return array |
||
78 | */ |
||
79 | public function getParamDefinitions( array $definitions ) { |
||
100 | |||
101 | /** |
||
102 | * Return serialised results in specified format. |
||
103 | */ |
||
104 | protected function getResultText( SMWQueryResult $res, $outputMode ) { |
||
113 | |||
114 | /* |
||
115 | * Turns the PHPExcel document object into a string |
||
116 | */ |
||
117 | /** |
||
118 | * @param $document |
||
119 | * @return string |
||
120 | */ |
||
121 | protected function writeDocumentToString( $document ) { |
||
128 | |||
129 | /** |
||
130 | * Populates the PHPExcel document with the query data |
||
131 | * |
||
132 | * @param $res SMWQueryResult the query result |
||
133 | */ |
||
134 | protected function populateDocumentWithQueryData( $res ) { |
||
141 | |||
142 | /** |
||
143 | * @param SMWQueryResult $res |
||
144 | * @return string |
||
145 | */ |
||
146 | protected function getResultFileContents( SMWQueryResult $res ) { |
||
169 | |||
170 | /** |
||
171 | * Sets or appends a string value at the given col,row location |
||
172 | * |
||
173 | * If there already exists a value at a given col,row location, then |
||
174 | * convert the cell to a string and append the data value. Creating |
||
175 | * a list of comma separated entries. |
||
176 | * |
||
177 | * @param $object \SMWDataValue the raw data value object |
||
178 | */ |
||
179 | protected function setOrAppendStringDataValue( $object ) { |
||
192 | |||
193 | /** |
||
194 | * Sets a numeric value at the given col,row location |
||
195 | * |
||
196 | * @param $object \SMWDataValue the raw data value object |
||
197 | */ |
||
198 | protected function setNumberDataValue( $object ) { |
||
205 | |||
206 | /** |
||
207 | * Sets a quantity value at the given col,row location |
||
208 | * |
||
209 | * @param $object \SMWDataValue the raw data value object |
||
210 | */ |
||
211 | protected function setQuantityDataValue( $object ) { |
||
225 | |||
226 | /** |
||
227 | * Sets a date/time value at the given col,row location |
||
228 | * |
||
229 | * @param \SMWTimeValue $object the raw data value object |
||
230 | */ |
||
231 | protected function setTimeDataValue ( \SMWTimeValue $object ) { |
||
246 | |||
247 | /** |
||
248 | * Populates the PHPExcel sheet with the headers from the result query |
||
249 | * |
||
250 | * @param SMWQueryResult $res The query result |
||
251 | */ |
||
252 | protected function populateDocumentWithHeaders( SMWQueryResult $res ) { |
||
265 | |||
266 | /** |
||
267 | * Creates a new PHPExcel document and returns it |
||
268 | * |
||
269 | * @return PHPExcel |
||
270 | */ |
||
271 | protected function createExcelDocument() { |
||
300 | |||
301 | /** |
||
302 | * Check for the existence of the extra mainlabel. |
||
303 | * @param $label |
||
304 | * @return bool |
||
305 | */ |
||
306 | private function showLabel( $label ) { |
||
309 | |||
310 | protected function readFieldValue( $field ) { |
||
321 | |||
322 | /** |
||
323 | * Checks the type of the value, and set's it in the sheet accordingly |
||
324 | * @param $object |
||
325 | */ |
||
326 | protected function setValueAccordingToType( $object ) { |
||
338 | |||
339 | /** |
||
340 | * @param $row |
||
341 | */ |
||
342 | protected function readRowData( $row ) { |
||
350 | |||
351 | private function isPHPExcelInstalled() { |
||
354 | |||
355 | } |
||
356 | |||
357 |