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

Reader   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 59
ccs 16
cts 17
cp 0.9412
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A doesSupportStreamWrapper() 0 4 1
A openReader() 0 10 2
A closeReader() 0 6 2
A getConcreteSheetIterator() 0 4 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