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 |
||
27 | abstract class BaseReader implements IReader |
||
28 | { |
||
29 | /** |
||
30 | * Read data only? |
||
31 | * Identifies whether the Reader should only read data values for cells, and ignore any formatting information; |
||
32 | * or whether it should read both data and formatting |
||
33 | * |
||
34 | * @var bool |
||
35 | */ |
||
36 | protected $readDataOnly = false; |
||
37 | |||
38 | /** |
||
39 | * Read empty cells? |
||
40 | * Identifies whether the Reader should read data values for cells all cells, or should ignore cells containing |
||
41 | * null value or empty string |
||
42 | * |
||
43 | * @var bool |
||
44 | */ |
||
45 | protected $readEmptyCells = true; |
||
46 | |||
47 | /** |
||
48 | * Read charts that are defined in the workbook? |
||
49 | * Identifies whether the Reader should read the definitions for any charts that exist in the workbook; |
||
50 | * |
||
51 | * @var bool |
||
52 | */ |
||
53 | protected $includeCharts = false; |
||
54 | |||
55 | /** |
||
56 | * Restrict which sheets should be loaded? |
||
57 | * This property holds an array of worksheet names to be loaded. If null, then all worksheets will be loaded. |
||
58 | * |
||
59 | * @var array of string |
||
60 | */ |
||
61 | protected $loadSheetsOnly; |
||
62 | |||
63 | /** |
||
64 | * IReadFilter instance |
||
65 | * |
||
66 | * @var IReadFilter |
||
67 | */ |
||
68 | protected $readFilter; |
||
69 | |||
70 | protected $fileHandle = null; |
||
71 | |||
72 | /** |
||
73 | * Read data only? |
||
74 | * If this is true, then the Reader will only read data values for cells, it will not read any formatting information. |
||
75 | * If false (the default) it will read data and formatting. |
||
76 | * |
||
77 | * @return bool |
||
78 | */ |
||
79 | public function getReadDataOnly() |
||
83 | |||
84 | /** |
||
85 | * Set read data only |
||
86 | * Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting information. |
||
87 | * Set to false (the default) to advise the Reader to read both data and formatting for cells. |
||
88 | * |
||
89 | * @param bool $pValue |
||
90 | * |
||
91 | * @return IReader |
||
92 | */ |
||
93 | public function setReadDataOnly($pValue = false) |
||
99 | |||
100 | /** |
||
101 | * Read empty cells? |
||
102 | * If this is true (the default), then the Reader will read data values for all cells, irrespective of value. |
||
103 | * If false it will not read data for cells containing a null value or an empty string. |
||
104 | * |
||
105 | * @return bool |
||
106 | */ |
||
107 | public function getReadEmptyCells() |
||
111 | |||
112 | /** |
||
113 | * Set read empty cells |
||
114 | * Set to true (the default) to advise the Reader read data values for all cells, irrespective of value. |
||
115 | * Set to false to advise the Reader to ignore cells containing a null value or an empty string. |
||
116 | * |
||
117 | * @param bool $pValue |
||
118 | * |
||
119 | * @return IReader |
||
120 | */ |
||
121 | public function setReadEmptyCells($pValue = true) |
||
127 | |||
128 | /** |
||
129 | * Read charts in workbook? |
||
130 | * If this is true, then the Reader will include any charts that exist in the workbook. |
||
131 | * Note that a ReadDataOnly value of false overrides, and charts won't be read regardless of the IncludeCharts value. |
||
132 | * If false (the default) it will ignore any charts defined in the workbook file. |
||
133 | * |
||
134 | * @return bool |
||
135 | */ |
||
136 | public function getIncludeCharts() |
||
140 | |||
141 | /** |
||
142 | * Set read charts in workbook |
||
143 | * Set to true, to advise the Reader to include any charts that exist in the workbook. |
||
144 | * Note that a ReadDataOnly value of false overrides, and charts won't be read regardless of the IncludeCharts value. |
||
145 | * Set to false (the default) to discard charts. |
||
146 | * |
||
147 | * @param bool $pValue |
||
148 | * |
||
149 | * @return IReader |
||
150 | */ |
||
151 | 2 | public function setIncludeCharts($pValue = false) |
|
152 | { |
||
153 | 2 | $this->includeCharts = (boolean) $pValue; |
|
154 | |||
155 | 2 | return $this; |
|
156 | } |
||
157 | |||
158 | /** |
||
159 | * Get which sheets to load |
||
160 | * Returns either an array of worksheet names (the list of worksheets that should be loaded), or a null |
||
161 | * indicating that all worksheets in the workbook should be loaded. |
||
162 | * |
||
163 | * @return mixed |
||
164 | */ |
||
165 | public function getLoadSheetsOnly() |
||
169 | |||
170 | /** |
||
171 | * Set which sheets to load |
||
172 | * |
||
173 | * @param mixed $value |
||
174 | * This should be either an array of worksheet names to be loaded, or a string containing a single worksheet name. |
||
175 | * If NULL, then it tells the Reader to read all worksheets in the workbook |
||
176 | * |
||
177 | * @return IReader |
||
178 | */ |
||
179 | public function setLoadSheetsOnly($value = null) |
||
189 | |||
190 | /** |
||
191 | * Set all sheets to load |
||
192 | * Tells the Reader to load all worksheets from the workbook. |
||
193 | * |
||
194 | * @return IReader |
||
195 | */ |
||
196 | public function setLoadAllSheets() |
||
202 | |||
203 | /** |
||
204 | * Read filter |
||
205 | * |
||
206 | * @return IReadFilter |
||
207 | */ |
||
208 | 15 | public function getReadFilter() |
|
212 | |||
213 | /** |
||
214 | * Set read filter |
||
215 | * |
||
216 | * @param IReadFilter $pValue |
||
217 | * @return IReader |
||
218 | */ |
||
219 | 1 | public function setReadFilter(IReadFilter $pValue) |
|
225 | |||
226 | /** |
||
227 | * Open file for reading |
||
228 | * |
||
229 | * @param string $pFilename |
||
230 | * @throws Exception |
||
231 | * @return resource |
||
232 | */ |
||
233 | 4 | protected function openFile($pFilename) |
|
246 | |||
247 | /** |
||
248 | * Scan theXML for use of <!ENTITY to prevent XXE/XEE attacks |
||
249 | * |
||
250 | * @param string $xml |
||
251 | * @throws Exception |
||
252 | */ |
||
253 | 20 | View Code Duplication | public function securityScan($xml) |
262 | |||
263 | /** |
||
264 | * Scan theXML for use of <!ENTITY to prevent XXE/XEE attacks |
||
265 | * |
||
266 | * @param string $filestream |
||
267 | * @throws Exception |
||
268 | */ |
||
269 | 9 | public function securityScanFile($filestream) |
|
273 | } |
||
274 |
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..