Completed
Push — develop ( e1f81f...539a89 )
by Adrien
16:11
created

SYLK::loadIntoExisting()   F

Complexity

Conditions 66
Paths 723

Size

Total Lines 242
Code Lines 176

Duplication

Lines 98
Ratio 40.5 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 66
eloc 176
nc 723
nop 2
dl 98
loc 242
rs 2
c 1
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
3
namespace PhpSpreadsheet\Reader;
4
5
/**
6
 * Copyright (c) 2006 - 2016 PhpSpreadsheet
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with this library; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21
 *
22
 * @category   PhpSpreadsheet
23
 * @copyright  Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet)
24
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
25
 * @version    ##VERSION##, ##DATE##
26
 */
27
class SYLK extends BaseReader implements IReader
28
{
29
    /**
30
     * Input encoding
31
     *
32
     * @var string
33
     */
34
    private $inputEncoding = 'ANSI';
35
36
    /**
37
     * Sheet index to read
38
     *
39
     * @var int
40
     */
41
    private $sheetIndex = 0;
42
43
    /**
44
     * Formats
45
     *
46
     * @var array
47
     */
48
    private $formats = array();
49
50
    /**
51
     * Format Count
52
     *
53
     * @var int
54
     */
55
    private $format = 0;
56
57
    /**
58
     * Create a new SYLK Reader instance
59
     */
60
    public function __construct()
61
    {
62
        $this->readFilter = new DefaultReadFilter();
63
    }
64
65
    /**
66
     * Validate that the current file is a SYLK file
67
     *
68
     * @return boolean
69
     */
70
    protected function isValidFormat()
71
    {
72
        // Read sample data (first 2 KB will do)
73
        $data = fread($this->fileHandle, 2048);
74
75
        // Count delimiters in file
76
        $delimiterCount = substr_count($data, ';');
77
        if ($delimiterCount < 1) {
78
            return false;
79
        }
80
81
        // Analyze first line looking for ID; signature
82
        $lines = explode("\n", $data);
83
        if (substr($lines[0], 0, 4) != 'ID;P') {
84
            return false;
85
        }
86
87
        return true;
88
    }
89
90
    /**
91
     * Set input encoding
92
     *
93
     * @param string $pValue Input encoding
94
     */
95
    public function setInputEncoding($pValue = 'ANSI')
96
    {
97
        $this->inputEncoding = $pValue;
98
        return $this;
99
    }
100
101
    /**
102
     * Get input encoding
103
     *
104
     * @return string
105
     */
106
    public function getInputEncoding()
107
    {
108
        return $this->inputEncoding;
109
    }
110
111
    /**
112
     * Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns)
113
     *
114
     * @param    string     $pFilename
115
     * @throws   Exception
116
     */
117
    public function listWorksheetInfo($pFilename)
118
    {
119
        // Open file
120
        $this->openFile($pFilename);
121
        if (!$this->isValidFormat()) {
122
            fclose($this->fileHandle);
123
            throw new Exception($pFilename . " is an Invalid Spreadsheet file.");
124
        }
125
        $fileHandle = $this->fileHandle;
126
        rewind($fileHandle);
127
128
        $worksheetInfo = array();
129
        $worksheetInfo[0]['worksheetName'] = 'Worksheet';
130
        $worksheetInfo[0]['lastColumnLetter'] = 'A';
131
        $worksheetInfo[0]['lastColumnIndex'] = 0;
132
        $worksheetInfo[0]['totalRows'] = 0;
133
        $worksheetInfo[0]['totalColumns'] = 0;
134
135
        // Loop through file
136
        $rowData = array();
0 ignored issues
show
Unused Code introduced by
$rowData is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
137
138
        // loop through one row (line) at a time in the file
139
        $rowIndex = 0;
140
        while (($rowData = fgets($fileHandle)) !== false) {
141
            $columnIndex = 0;
142
143
            // convert SYLK encoded $rowData to UTF-8
144
            $rowData = \PhpSpreadsheet\Shared\StringHelper::SYLKtoUTF8($rowData);
145
146
            // explode each row at semicolons while taking into account that literal semicolon (;)
147
            // is escaped like this (;;)
148
            $rowData = explode("\t", str_replace('¤', ';', str_replace(';', "\t", str_replace(';;', '¤', rtrim($rowData)))));
149
150
            $dataType = array_shift($rowData);
151
            if ($dataType == 'C') {
152
                //  Read cell value data
153
                foreach ($rowData as $rowDatum) {
154 View Code Duplication
                    switch ($rowDatum{0}) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
155
                        case 'C':
156
                        case 'X':
157
                            $columnIndex = substr($rowDatum, 1) - 1;
158
                            break;
159
                        case 'R':
160
                        case 'Y':
161
                            $rowIndex = substr($rowDatum, 1);
162
                            break;
163
                    }
164
165
                    $worksheetInfo[0]['totalRows'] = max($worksheetInfo[0]['totalRows'], $rowIndex);
166
                    $worksheetInfo[0]['lastColumnIndex'] = max($worksheetInfo[0]['lastColumnIndex'], $columnIndex);
167
                }
168
            }
169
        }
170
171
        $worksheetInfo[0]['lastColumnLetter'] = \PhpSpreadsheet\Cell::stringFromColumnIndex($worksheetInfo[0]['lastColumnIndex']);
172
        $worksheetInfo[0]['totalColumns'] = $worksheetInfo[0]['lastColumnIndex'] + 1;
173
174
        // Close file
175
        fclose($fileHandle);
176
177
        return $worksheetInfo;
178
    }
179
180
    /**
181
     * Loads PhpSpreadsheet from file
182
     *
183
     * @param     string         $pFilename
184
     * @return     \PhpSpreadsheet\Spreadsheet
185
     * @throws     Exception
186
     */
187
    public function load($pFilename)
188
    {
189
        // Create new Spreadsheet
190
        $spreadsheet = new \PhpSpreadsheet\Spreadsheet();
191
192
        // Load into this instance
193
        return $this->loadIntoExisting($pFilename, $spreadsheet);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->loadIntoEx...ilename, $spreadsheet); (PhpSpreadsheet\Spreadsheet) is incompatible with the return type declared by the interface PhpSpreadsheet\Reader\IReader::load of type PhpSpreadsheet\Reader\PhpSpreadsheet.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
194
    }
195
196
    /**
197
     * Loads PhpSpreadsheet from file into PhpSpreadsheet instance
198
     *
199
     * @param     string         $pFilename
200
     * @param     \PhpSpreadsheet\Spreadsheet    $spreadsheet
201
     * @return    \PhpSpreadsheet\Spreadsheet
202
     * @throws    Exception
203
     */
204
    public function loadIntoExisting($pFilename, \PhpSpreadsheet\Spreadsheet $spreadsheet)
205
    {
206
        // Open file
207
        $this->openFile($pFilename);
208
        if (!$this->isValidFormat()) {
209
            fclose($this->fileHandle);
210
            throw new Exception($pFilename . " is an Invalid Spreadsheet file.");
211
        }
212
        $fileHandle = $this->fileHandle;
213
        rewind($fileHandle);
214
215
        // Create new Worksheets
216
        while ($spreadsheet->getSheetCount() <= $this->sheetIndex) {
217
            $spreadsheet->createSheet();
218
        }
219
        $spreadsheet->setActiveSheetIndex($this->sheetIndex);
220
221
        $fromFormats    = array('\-',    '\ ');
222
        $toFormats        = array('-',    ' ');
223
224
        // Loop through file
225
        $rowData = array();
0 ignored issues
show
Unused Code introduced by
$rowData is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
226
        $column = $row = '';
227
228
        // loop through one row (line) at a time in the file
229
        while (($rowData = fgets($fileHandle)) !== false) {
230
            // convert SYLK encoded $rowData to UTF-8
231
            $rowData = \PhpSpreadsheet\Shared\StringHelper::SYLKtoUTF8($rowData);
232
233
            // explode each row at semicolons while taking into account that literal semicolon (;)
234
            // is escaped like this (;;)
235
            $rowData = explode("\t", str_replace('¤', ';', str_replace(';', "\t", str_replace(';;', '¤', rtrim($rowData)))));
236
237
            $dataType = array_shift($rowData);
238
            //    Read shared styles
239
            if ($dataType == 'P') {
240
                $formatArray = array();
241
                foreach ($rowData as $rowDatum) {
242
                    switch ($rowDatum{0}) {
243
                        case 'P':
244
                            $formatArray['numberformat']['code'] = str_replace($fromFormats, $toFormats, substr($rowDatum, 1));
245
                            break;
246
                        case 'E':
247
                        case 'F':
248
                            $formatArray['font']['name'] = substr($rowDatum, 1);
249
                            break;
250
                        case 'L':
251
                            $formatArray['font']['size'] = substr($rowDatum, 1);
252
                            break;
253 View Code Duplication
                        case 'S':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
254
                            $styleSettings = substr($rowDatum, 1);
255
                            for ($i=0; $i<strlen($styleSettings); ++$i) {
256
                                switch ($styleSettings{$i}) {
257
                                    case 'I':
258
                                        $formatArray['font']['italic'] = true;
259
                                        break;
260
                                    case 'D':
261
                                        $formatArray['font']['bold'] = true;
262
                                        break;
263
                                    case 'T':
264
                                        $formatArray['borders']['top']['style'] = \PhpSpreadsheet\Style\Border::BORDER_THIN;
265
                                        break;
266
                                    case 'B':
267
                                        $formatArray['borders']['bottom']['style'] = \PhpSpreadsheet\Style\Border::BORDER_THIN;
268
                                        break;
269
                                    case 'L':
270
                                        $formatArray['borders']['left']['style'] = \PhpSpreadsheet\Style\Border::BORDER_THIN;
271
                                        break;
272
                                    case 'R':
273
                                        $formatArray['borders']['right']['style'] = \PhpSpreadsheet\Style\Border::BORDER_THIN;
274
                                        break;
275
                                }
276
                            }
277
                            break;
278
                    }
279
                }
280
                $this->formats['P'.$this->format++] = $formatArray;
281
            //    Read cell value data
282
            } elseif ($dataType == 'C') {
283
                $hasCalculatedValue = false;
284
                $cellData = $cellDataFormula = '';
285
                foreach ($rowData as $rowDatum) {
286
                    switch ($rowDatum{0}) {
287
                        case 'C':
288
                        case 'X':
289
                            $column = substr($rowDatum, 1);
290
                            break;
291
                        case 'R':
292
                        case 'Y':
293
                            $row = substr($rowDatum, 1);
294
                            break;
295
                        case 'K':
296
                            $cellData = substr($rowDatum, 1);
297
                            break;
298
                        case 'E':
299
                            $cellDataFormula = '='.substr($rowDatum, 1);
300
                            //    Convert R1C1 style references to A1 style references (but only when not quoted)
301
                            $temp = explode('"', $cellDataFormula);
302
                            $key = false;
303 View Code Duplication
                            foreach ($temp as &$value) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
304
                                //    Only count/replace in alternate array entries
305
                                if ($key = !$key) {
306
                                    preg_match_all('/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/', $value, $cellReferences, PREG_SET_ORDER+PREG_OFFSET_CAPTURE);
307
                                    //    Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way
308
                                    //        through the formula from left to right. Reversing means that we work right to left.through
309
                                    //        the formula
310
                                    $cellReferences = array_reverse($cellReferences);
311
                                    //    Loop through each R1C1 style reference in turn, converting it to its A1 style equivalent,
312
                                    //        then modify the formula to use that new reference
313
                                    foreach ($cellReferences as $cellReference) {
314
                                        $rowReference = $cellReference[2][0];
315
                                        //    Empty R reference is the current row
316
                                        if ($rowReference == '') {
317
                                            $rowReference = $row;
318
                                        }
319
                                        //    Bracketed R references are relative to the current row
320
                                        if ($rowReference{0} == '[') {
321
                                            $rowReference = $row + trim($rowReference, '[]');
322
                                        }
323
                                        $columnReference = $cellReference[4][0];
324
                                        //    Empty C reference is the current column
325
                                        if ($columnReference == '') {
326
                                            $columnReference = $column;
327
                                        }
328
                                        //    Bracketed C references are relative to the current column
329
                                        if ($columnReference{0} == '[') {
330
                                            $columnReference = $column + trim($columnReference, '[]');
331
                                        }
332
                                        $A1CellReference = \PhpSpreadsheet\Cell::stringFromColumnIndex($columnReference-1).$rowReference;
333
334
                                        $value = substr_replace($value, $A1CellReference, $cellReference[0][1], strlen($cellReference[0][0]));
335
                                    }
336
                                }
337
                            }
338
                            unset($value);
339
                            //    Then rebuild the formula string
340
                            $cellDataFormula = implode('"', $temp);
341
                            $hasCalculatedValue = true;
342
                            break;
343
                    }
344
                }
345
                $columnLetter = \PhpSpreadsheet\Cell::stringFromColumnIndex($column-1);
346
                $cellData = \PhpSpreadsheet\Calculation::unwrapResult($cellData);
347
348
                // Set cell value
349
                $spreadsheet->getActiveSheet()->getCell($columnLetter.$row)->setValue(($hasCalculatedValue) ? $cellDataFormula : $cellData);
350
                if ($hasCalculatedValue) {
351
                    $cellData = \PhpSpreadsheet\Calculation::unwrapResult($cellData);
352
                    $spreadsheet->getActiveSheet()->getCell($columnLetter.$row)->setCalculatedValue($cellData);
353
                }
354
            //    Read cell formatting
355
            } elseif ($dataType == 'F') {
356
                $formatStyle = $columnWidth = $styleSettings = '';
0 ignored issues
show
Unused Code introduced by
$styleSettings is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
357
                $styleData = array();
358
                foreach ($rowData as $rowDatum) {
359
                    switch ($rowDatum{0}) {
360
                        case 'C':
361
                        case 'X':
362
                            $column = substr($rowDatum, 1);
363
                            break;
364
                        case 'R':
365
                        case 'Y':
366
                            $row = substr($rowDatum, 1);
367
                            break;
368
                        case 'P':
369
                            $formatStyle = $rowDatum;
370
                            break;
371
                        case 'W':
372
                            list($startCol, $endCol, $columnWidth) = explode(' ', substr($rowDatum, 1));
373
                            break;
374 View Code Duplication
                        case 'S':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
375
                            $styleSettings = substr($rowDatum, 1);
376
                            for ($i=0; $i<strlen($styleSettings); ++$i) {
377
                                switch ($styleSettings{$i}) {
378
                                    case 'I':
379
                                        $styleData['font']['italic'] = true;
380
                                        break;
381
                                    case 'D':
382
                                        $styleData['font']['bold'] = true;
383
                                        break;
384
                                    case 'T':
385
                                        $styleData['borders']['top']['style'] = \PhpSpreadsheet\Style\Border::BORDER_THIN;
386
                                        break;
387
                                    case 'B':
388
                                        $styleData['borders']['bottom']['style'] = \PhpSpreadsheet\Style\Border::BORDER_THIN;
389
                                        break;
390
                                    case 'L':
391
                                        $styleData['borders']['left']['style'] = \PhpSpreadsheet\Style\Border::BORDER_THIN;
392
                                        break;
393
                                    case 'R':
394
                                        $styleData['borders']['right']['style'] = \PhpSpreadsheet\Style\Border::BORDER_THIN;
395
                                        break;
396
                                }
397
                            }
398
                            break;
399
                    }
400
                }
401
                if (($formatStyle > '') && ($column > '') && ($row > '')) {
402
                    $columnLetter = \PhpSpreadsheet\Cell::stringFromColumnIndex($column-1);
403 View Code Duplication
                    if (isset($this->formats[$formatStyle])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
404
                        $spreadsheet->getActiveSheet()->getStyle($columnLetter.$row)->applyFromArray($this->formats[$formatStyle]);
405
                    }
406
                }
407
                if ((!empty($styleData)) && ($column > '') && ($row > '')) {
408
                    $columnLetter = \PhpSpreadsheet\Cell::stringFromColumnIndex($column-1);
409
                    $spreadsheet->getActiveSheet()->getStyle($columnLetter.$row)->applyFromArray($styleData);
410
                }
411
                if ($columnWidth > '') {
412
                    if ($startCol == $endCol) {
413
                        $startCol = \PhpSpreadsheet\Cell::stringFromColumnIndex($startCol-1);
0 ignored issues
show
Bug introduced by
The variable $startCol does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
414
                        $spreadsheet->getActiveSheet()->getColumnDimension($startCol)->setWidth($columnWidth);
415
                    } else {
416
                        $startCol = \PhpSpreadsheet\Cell::stringFromColumnIndex($startCol-1);
417
                        $endCol = \PhpSpreadsheet\Cell::stringFromColumnIndex($endCol-1);
0 ignored issues
show
Bug introduced by
The variable $endCol does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
418
                        $spreadsheet->getActiveSheet()->getColumnDimension($startCol)->setWidth($columnWidth);
419
                        do {
420
                            $spreadsheet->getActiveSheet()->getColumnDimension(++$startCol)->setWidth($columnWidth);
421
                        } while ($startCol != $endCol);
422
                    }
423
                }
424
            } else {
425
                foreach ($rowData as $rowDatum) {
426 View Code Duplication
                    switch ($rowDatum{0}) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
427
                        case 'C':
428
                        case 'X':
429
                            $column = substr($rowDatum, 1);
430
                            break;
431
                        case 'R':
432
                        case 'Y':
433
                            $row = substr($rowDatum, 1);
434
                            break;
435
                    }
436
                }
437
            }
438
        }
439
440
        // Close file
441
        fclose($fileHandle);
442
443
        // Return
444
        return $spreadsheet;
445
    }
446
447
    /**
448
     * Get sheet index
449
     *
450
     * @return int
451
     */
452
    public function getSheetIndex()
453
    {
454
        return $this->sheetIndex;
455
    }
456
457
    /**
458
     * Set sheet index
459
     *
460
     * @param    int        $pValue        Sheet index
461
     * @return SYLK
462
     */
463
    public function setSheetIndex($pValue = 0)
464
    {
465
        $this->sheetIndex = $pValue;
466
        return $this;
467
    }
468
}
469