Completed
Push — master ( 771781...0978d3 )
by Adrien
02:54
created

Reader::doesSupportStreamWrapper()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Box\Spout\Reader\ODS;
4
5
use Box\Spout\Common\Exception\IOException;
6
use Box\Spout\Reader\AbstractReader;
7
8
/**
9
 * Class Reader
10
 * This class provides support to read data from a ODS file
11
 *
12
 * @package Box\Spout\Reader\ODS
13
 */
14
class Reader extends AbstractReader
15
{
16
    /** @var \ZipArchive */
17
    protected $zip;
18
19
    /** @var SheetIterator To iterator over the ODS sheets */
20
    protected $sheetIterator;
21
22
    /**
23
     * Returns whether stream wrappers are supported
24
     *
25
     * @return bool
26
     */
27 6
    protected function doesSupportStreamWrapper()
28
    {
29 6
        return false;
30
    }
31
32
    /**
33
     * Opens the file at the given file path to make it ready to be read.
34
     *
35
     * @param  string $filePath Path of the file to be read
36
     * @return void
37
     * @throws \Box\Spout\Common\Exception\IOException If the file at the given path or its content cannot be read
38
     * @throws \Box\Spout\Reader\Exception\NoSheetsFoundException If there are no sheets in the file
39
     */
40 81
    protected function openReader($filePath)
41
    {
42 81
        $this->zip = new \ZipArchive();
43
44 81
        if ($this->zip->open($filePath) === true) {
45 81
            $this->sheetIterator = new SheetIterator($filePath, $this->shouldFormatDates, $this->shouldPreserveEmptyRows);
46 81
        } else {
47
            throw new IOException("Could not open $filePath for reading.");
48
        }
49 81
    }
50
51
    /**
52
     * Returns an iterator to iterate over sheets.
53
     *
54
     * @return SheetIterator To iterate over sheets
55
     */
56 81
    public function getConcreteSheetIterator()
57
    {
58 81
        return $this->sheetIterator;
59 3
    }
60
61
    /**
62
     * Closes the reader. To be used after reading the file.
63
     *
64
     * @return void
65
     */
66 72
    protected function closeReader()
67
    {
68 72
        if ($this->zip) {
69 72
            $this->zip->close();
70 72
        }
71 72
    }
72
}
73