Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
28 | abstract class BaseReader implements IReader |
||
29 | { |
||
30 | /** |
||
31 | * Read data only? |
||
32 | * Identifies whether the Reader should only read data values for cells, and ignore any formatting information; |
||
33 | * or whether it should read both data and formatting |
||
34 | * |
||
35 | * @var bool |
||
36 | */ |
||
37 | protected $readDataOnly = false; |
||
38 | |||
39 | /** |
||
40 | * Read empty cells? |
||
41 | * Identifies whether the Reader should read data values for cells all cells, or should ignore cells containing |
||
42 | * null value or empty string |
||
43 | * |
||
44 | * @var bool |
||
45 | */ |
||
46 | protected $readEmptyCells = true; |
||
47 | |||
48 | /** |
||
49 | * Read charts that are defined in the workbook? |
||
50 | * Identifies whether the Reader should read the definitions for any charts that exist in the workbook; |
||
51 | * |
||
52 | * @var bool |
||
53 | */ |
||
54 | protected $includeCharts = false; |
||
55 | |||
56 | /** |
||
57 | * Restrict which sheets should be loaded? |
||
58 | * This property holds an array of worksheet names to be loaded. If null, then all worksheets will be loaded. |
||
59 | * |
||
60 | * @var array of string |
||
61 | */ |
||
62 | protected $loadSheetsOnly; |
||
63 | |||
64 | /** |
||
65 | * IReadFilter instance |
||
66 | * |
||
67 | * @var IReadFilter |
||
68 | */ |
||
69 | protected $readFilter; |
||
70 | |||
71 | protected $fileHandle = null; |
||
72 | |||
73 | /** |
||
74 | * Read data only? |
||
75 | * If this is true, then the Reader will only read data values for cells, it will not read any formatting information. |
||
76 | * If false (the default) it will read data and formatting. |
||
77 | * |
||
78 | * @return bool |
||
79 | */ |
||
80 | public function getReadDataOnly() |
||
84 | |||
85 | /** |
||
86 | * Set read data only |
||
87 | * Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting information. |
||
88 | * Set to false (the default) to advise the Reader to read both data and formatting for cells. |
||
89 | * |
||
90 | * @param bool $pValue |
||
91 | * |
||
92 | * @return IReader |
||
93 | */ |
||
94 | public function setReadDataOnly($pValue = false) |
||
100 | |||
101 | /** |
||
102 | * Read empty cells? |
||
103 | * If this is true (the default), then the Reader will read data values for all cells, irrespective of value. |
||
104 | * If false it will not read data for cells containing a null value or an empty string. |
||
105 | * |
||
106 | * @return bool |
||
107 | */ |
||
108 | public function getReadEmptyCells() |
||
112 | |||
113 | /** |
||
114 | * Set read empty cells |
||
115 | * Set to true (the default) to advise the Reader read data values for all cells, irrespective of value. |
||
116 | * Set to false to advise the Reader to ignore cells containing a null value or an empty string. |
||
117 | * |
||
118 | * @param bool $pValue |
||
119 | * |
||
120 | * @return IReader |
||
121 | */ |
||
122 | public function setReadEmptyCells($pValue = true) |
||
128 | |||
129 | /** |
||
130 | * Read charts in workbook? |
||
131 | * If this is true, then the Reader will include any charts that exist in the workbook. |
||
132 | * Note that a ReadDataOnly value of false overrides, and charts won't be read regardless of the IncludeCharts value. |
||
133 | * If false (the default) it will ignore any charts defined in the workbook file. |
||
134 | * |
||
135 | * @return bool |
||
136 | */ |
||
137 | public function getIncludeCharts() |
||
141 | |||
142 | /** |
||
143 | * Set read charts in workbook |
||
144 | * Set to true, to advise the Reader to include any charts that exist in the workbook. |
||
145 | * Note that a ReadDataOnly value of false overrides, and charts won't be read regardless of the IncludeCharts value. |
||
146 | * Set to false (the default) to discard charts. |
||
147 | * |
||
148 | * @param bool $pValue |
||
149 | * |
||
150 | * @return IReader |
||
151 | */ |
||
152 | 2 | public function setIncludeCharts($pValue = false) |
|
158 | |||
159 | /** |
||
160 | * Get which sheets to load |
||
161 | * Returns either an array of worksheet names (the list of worksheets that should be loaded), or a null |
||
162 | * indicating that all worksheets in the workbook should be loaded. |
||
163 | * |
||
164 | * @return mixed |
||
165 | */ |
||
166 | public function getLoadSheetsOnly() |
||
170 | |||
171 | /** |
||
172 | * Set which sheets to load |
||
173 | * |
||
174 | * @param mixed $value |
||
175 | * This should be either an array of worksheet names to be loaded, or a string containing a single worksheet name. |
||
176 | * If NULL, then it tells the Reader to read all worksheets in the workbook |
||
177 | * |
||
178 | * @return IReader |
||
179 | */ |
||
180 | public function setLoadSheetsOnly($value = null) |
||
190 | |||
191 | /** |
||
192 | * Set all sheets to load |
||
193 | * Tells the Reader to load all worksheets from the workbook. |
||
194 | * |
||
195 | * @return IReader |
||
196 | */ |
||
197 | public function setLoadAllSheets() |
||
203 | |||
204 | /** |
||
205 | * Read filter |
||
206 | * |
||
207 | * @return IReadFilter |
||
208 | */ |
||
209 | 15 | public function getReadFilter() |
|
213 | |||
214 | /** |
||
215 | * Set read filter |
||
216 | * |
||
217 | * @param IReadFilter $pValue |
||
218 | * @return IReader |
||
219 | */ |
||
220 | 1 | public function setReadFilter(IReadFilter $pValue) |
|
226 | |||
227 | /** |
||
228 | * Open file for reading |
||
229 | * |
||
230 | * @param string $pFilename |
||
231 | * @throws Exception |
||
232 | * @return resource |
||
233 | */ |
||
234 | 6 | protected function openFile($pFilename) |
|
244 | |||
245 | /** |
||
246 | * Scan theXML for use of <!ENTITY to prevent XXE/XEE attacks |
||
247 | * |
||
248 | * @param string $xml |
||
249 | * @throws Exception |
||
250 | */ |
||
251 | 21 | View Code Duplication | public function securityScan($xml) |
260 | |||
261 | /** |
||
262 | * Scan theXML for use of <!ENTITY to prevent XXE/XEE attacks |
||
263 | * |
||
264 | * @param string $filestream |
||
265 | * @throws Exception |
||
266 | */ |
||
267 | 9 | public function securityScanFile($filestream) |
|
271 | } |
||
272 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..