Passed
Push — master ( 7f4693...cd6053 )
by Mark
42:18 queued 34:20
created

BaseReader::getSecuritySCanner()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

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