Completed
Push — develop ( 29208e...50a0ec )
by Adrien
05:34
created

MyReadFilter::readCell()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 5
nc 3
nop 3
dl 0
loc 11
rs 9.2
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 14 and the first side effect is on line 8.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace Sample;
4
5
use PhpOffice\PhpSpreadsheet\IOFactory;
6
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
7
8
require __DIR__ . '/../Header.php';
9
10
$inputFileType = 'Xls';
11
$inputFileName = __DIR__ . '/sampleData/example1.xls';
12
$sheetname = 'Data Sheet #3';
13
14
class MyReadFilter implements IReadFilter
15
{
16
    public function readCell($column, $row, $worksheetName = '')
17
    {
18
        // Read rows 1 to 7 and columns A to E only
19
        if ($row >= 1 && $row <= 7) {
20
            if (in_array($column, range('A', 'E'))) {
21
                return true;
22
            }
23
        }
24
25
        return false;
26
    }
27
}
28
29
$filterSubset = new MyReadFilter();
30
31
$helper->log('Loading file ' . pathinfo($inputFileName, PATHINFO_BASENAME) . ' using IOFactory with a defined reader type of ' . $inputFileType);
32
$reader = IOFactory::createReader($inputFileType);
33
$helper->log('Loading Sheet "' . $sheetname . '" only');
34
$reader->setLoadSheetsOnly($sheetname);
35
$helper->log('Loading Sheet using filter');
36
$reader->setReadFilter($filterSubset);
37
$spreadsheet = $reader->load($inputFileName);
38
39
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
40
var_dump($sheetData);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($sheetData); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
41