Conditions | 14 |
Paths | 15 |
Total Lines | 96 |
Code Lines | 56 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
61 | protected function listWorksheetInfo2(string $filename, Xls $xls): array |
||
62 | { |
||
63 | File::assertFile($filename); |
||
64 | |||
65 | $worksheetInfo = []; |
||
66 | |||
67 | // Read the OLE file |
||
68 | $xls->loadOLE($filename); |
||
69 | |||
70 | // total byte size of Excel data (workbook global substream + sheet substreams) |
||
71 | $xls->dataSize = strlen($xls->data); |
||
72 | |||
73 | // initialize |
||
74 | $xls->pos = 0; |
||
75 | $xls->sheets = []; |
||
76 | |||
77 | // Parse Workbook Global Substream |
||
78 | while ($xls->pos < $xls->dataSize) { |
||
79 | $code = self::getUInt2d($xls->data, $xls->pos); |
||
80 | |||
81 | match ($code) { |
||
82 | self::XLS_TYPE_BOF => $xls->readBof(), |
||
83 | self::XLS_TYPE_SHEET => $xls->readSheet(), |
||
84 | self::XLS_TYPE_EOF => $xls->readDefault(), |
||
85 | self::XLS_TYPE_CODEPAGE => $xls->readCodepage(), |
||
86 | default => $xls->readDefault(), |
||
87 | }; |
||
88 | |||
89 | if ($code === self::XLS_TYPE_EOF) { |
||
90 | break; |
||
91 | } |
||
92 | } |
||
93 | |||
94 | // Parse the individual sheets |
||
95 | foreach ($xls->sheets as $sheet) { |
||
96 | if ($sheet['sheetType'] != 0x00) { |
||
97 | // 0x00: Worksheet |
||
98 | // 0x02: Chart |
||
99 | // 0x06: Visual Basic module |
||
100 | continue; |
||
101 | } |
||
102 | |||
103 | $tmpInfo = []; |
||
104 | $tmpInfo['worksheetName'] = $sheet['name']; |
||
105 | $tmpInfo['lastColumnLetter'] = 'A'; |
||
106 | $tmpInfo['lastColumnIndex'] = 0; |
||
107 | $tmpInfo['totalRows'] = 0; |
||
108 | $tmpInfo['totalColumns'] = 0; |
||
109 | |||
110 | $xls->pos = $sheet['offset']; |
||
111 | |||
112 | while ($xls->pos <= $xls->dataSize - 4) { |
||
113 | $code = self::getUInt2d($xls->data, $xls->pos); |
||
114 | |||
115 | switch ($code) { |
||
116 | case self::XLS_TYPE_RK: |
||
117 | case self::XLS_TYPE_LABELSST: |
||
118 | case self::XLS_TYPE_NUMBER: |
||
119 | case self::XLS_TYPE_FORMULA: |
||
120 | case self::XLS_TYPE_BOOLERR: |
||
121 | case self::XLS_TYPE_LABEL: |
||
122 | $length = self::getUInt2d($xls->data, $xls->pos + 2); |
||
123 | $recordData = $xls->readRecordData($xls->data, $xls->pos + 4, $length); |
||
124 | |||
125 | // move stream pointer to next record |
||
126 | $xls->pos += 4 + $length; |
||
127 | |||
128 | $rowIndex = self::getUInt2d($recordData, 0) + 1; |
||
129 | $columnIndex = self::getUInt2d($recordData, 2); |
||
130 | |||
131 | $tmpInfo['totalRows'] = max($tmpInfo['totalRows'], $rowIndex); |
||
132 | $tmpInfo['lastColumnIndex'] = max($tmpInfo['lastColumnIndex'], $columnIndex); |
||
133 | |||
134 | break; |
||
135 | case self::XLS_TYPE_BOF: |
||
136 | $xls->readBof(); |
||
137 | |||
138 | break; |
||
139 | case self::XLS_TYPE_EOF: |
||
140 | $xls->readDefault(); |
||
141 | |||
142 | break 2; |
||
143 | default: |
||
144 | $xls->readDefault(); |
||
145 | |||
146 | break; |
||
147 | } |
||
148 | } |
||
149 | |||
150 | $tmpInfo['lastColumnLetter'] = Coordinate::stringFromColumnIndex($tmpInfo['lastColumnIndex'] + 1); |
||
151 | $tmpInfo['totalColumns'] = $tmpInfo['lastColumnIndex'] + 1; |
||
152 | |||
153 | $worksheetInfo[] = $tmpInfo; |
||
154 | } |
||
155 | |||
156 | return $worksheetInfo; |
||
157 | } |
||
159 |