Passed
Push — develop ( 3bea6f...0f8f07 )
by Mark
36:13
created

BaseReader::securityScanFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Reader;
4
5
use PhpOffice\PhpSpreadsheet\Shared\File;
6
7
abstract class BaseReader implements IReader
8
{
9
    /**
10
     * Read data only?
11
     * Identifies whether the Reader should only read data values for cells, and ignore any formatting information;
12
     *        or whether it should read both data and formatting.
13
     *
14
     * @var bool
15
     */
16
    protected $readDataOnly = false;
17
18
    /**
19
     * Read empty cells?
20
     * Identifies whether the Reader should read data values for cells all cells, or should ignore cells containing
21
     *         null value or empty string.
22
     *
23
     * @var bool
24
     */
25
    protected $readEmptyCells = true;
26
27
    /**
28
     * Read charts that are defined in the workbook?
29
     * Identifies whether the Reader should read the definitions for any charts that exist in the workbook;.
30
     *
31
     * @var bool
32
     */
33
    protected $includeCharts = false;
34
35
    /**
36
     * Restrict which sheets should be loaded?
37
     * This property holds an array of worksheet names to be loaded. If null, then all worksheets will be loaded.
38
     *
39
     * @var array of string
40
     */
41
    protected $loadSheetsOnly;
42
43
    /**
44
     * IReadFilter instance.
45
     *
46
     * @var IReadFilter
47
     */
48
    protected $readFilter;
49
50
    protected $fileHandle;
51
52
    /**
53
     * Read data only?
54
     *        If this is true, then the Reader will only read data values for cells, it will not read any formatting information.
55
     *        If false (the default) it will read data and formatting.
56
     *
57
     * @return bool
58
     */
59
    public function getReadDataOnly()
60
    {
61
        return $this->readDataOnly;
62
    }
63
64
    /**
65
     * Set read data only
66
     *        Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting information.
67
     *        Set to false (the default) to advise the Reader to read both data and formatting for cells.
68
     *
69
     * @param bool $pValue
70
     *
71
     * @return IReader
72
     */
73 1
    public function setReadDataOnly($pValue)
74
    {
75 1
        $this->readDataOnly = (bool) $pValue;
76
77 1
        return $this;
78
    }
79
80
    /**
81
     * Read empty cells?
82
     *        If this is true (the default), then the Reader will read data values for all cells, irrespective of value.
83
     *        If false it will not read data for cells containing a null value or an empty string.
84
     *
85
     * @return bool
86
     */
87
    public function getReadEmptyCells()
88
    {
89
        return $this->readEmptyCells;
90
    }
91
92
    /**
93
     * Set read empty cells
94
     *        Set to true (the default) to advise the Reader read data values for all cells, irrespective of value.
95
     *        Set to false to advise the Reader to ignore cells containing a null value or an empty string.
96
     *
97
     * @param bool $pValue
98
     *
99
     * @return IReader
100
     */
101
    public function setReadEmptyCells($pValue)
102
    {
103
        $this->readEmptyCells = (bool) $pValue;
104
105
        return $this;
106
    }
107
108
    /**
109
     * Read charts in workbook?
110
     *        If this is true, then the Reader will include any charts that exist in the workbook.
111
     *      Note that a ReadDataOnly value of false overrides, and charts won't be read regardless of the IncludeCharts value.
112
     *        If false (the default) it will ignore any charts defined in the workbook file.
113
     *
114
     * @return bool
115
     */
116
    public function getIncludeCharts()
117
    {
118
        return $this->includeCharts;
119
    }
120
121
    /**
122
     * Set read charts in workbook
123
     *        Set to true, to advise the Reader to include any charts that exist in the workbook.
124
     *      Note that a ReadDataOnly value of false overrides, and charts won't be read regardless of the IncludeCharts value.
125
     *        Set to false (the default) to discard charts.
126
     *
127
     * @param bool $pValue
128
     *
129
     * @return IReader
130
     */
131 3
    public function setIncludeCharts($pValue)
132
    {
133 3
        $this->includeCharts = (bool) $pValue;
134
135 3
        return $this;
136
    }
137
138
    /**
139
     * Get which sheets to load
140
     * Returns either an array of worksheet names (the list of worksheets that should be loaded), or a null
141
     *        indicating that all worksheets in the workbook should be loaded.
142
     *
143
     * @return mixed
144
     */
145
    public function getLoadSheetsOnly()
146
    {
147
        return $this->loadSheetsOnly;
148
    }
149
150
    /**
151
     * Set which sheets to load.
152
     *
153
     * @param mixed $value
154
     *        This should be either an array of worksheet names to be loaded, or a string containing a single worksheet name.
155
     *        If NULL, then it tells the Reader to read all worksheets in the workbook
156
     *
157
     * @return IReader
158
     */
159 6
    public function setLoadSheetsOnly($value)
160
    {
161 6
        if ($value === null) {
162
            return $this->setLoadAllSheets();
163
        }
164
165 6
        $this->loadSheetsOnly = is_array($value) ? $value : [$value];
166
167 6
        return $this;
168
    }
169
170
    /**
171
     * Set all sheets to load
172
     *        Tells the Reader to load all worksheets from the workbook.
173
     *
174
     * @return IReader
175
     */
176 1
    public function setLoadAllSheets()
177
    {
178 1
        $this->loadSheetsOnly = null;
179
180 1
        return $this;
181
    }
182
183
    /**
184
     * Read filter.
185
     *
186
     * @return IReadFilter
187
     */
188 69
    public function getReadFilter()
189
    {
190 69
        return $this->readFilter;
191
    }
192
193
    /**
194
     * Set read filter.
195
     *
196
     * @param IReadFilter $pValue
197
     *
198
     * @return IReader
199
     */
200 8
    public function setReadFilter(IReadFilter $pValue)
201
    {
202 8
        $this->readFilter = $pValue;
203
204 8
        return $this;
205
    }
206
207
    /**
208
     * Open file for reading.
209
     *
210
     * @param string $pFilename
211
     *
212
     * @throws Exception
213
     */
214 48
    protected function openFile($pFilename)
215
    {
216 48
        File::assertFile($pFilename);
217
218
        // Open file
219 48
        $this->fileHandle = fopen($pFilename, 'r');
220 48
        if ($this->fileHandle === false) {
221
            throw new Exception('Could not open file ' . $pFilename . ' for reading.');
222
        }
223 48
    }
224
}
225