Completed
Pull Request — master (#557)
by Adrien
03:10
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\ODS\Creator\InternalEntityFactory;
7
use Box\Spout\Reader\ReaderAbstract;
8
9
/**
10
 * Class Reader
11
 * This class provides support to read data from a ODS file
12
 */
13
class Reader extends ReaderAbstract
14
{
15
    /** @var \ZipArchive */
16
    protected $zip;
17
18
    /** @var SheetIterator To iterator over the ODS sheets */
19
    protected $sheetIterator;
20
21
    /**
22
     * Returns whether stream wrappers are supported
23
     *
24
     * @return bool
25
     */
26 2
    protected function doesSupportStreamWrapper()
27
    {
28 2
        return false;
29
    }
30
31
    /**
32
     * Opens the file at the given file path to make it ready to be read.
33
     *
34
     * @param  string $filePath Path of the file to be read
35
     * @throws \Box\Spout\Common\Exception\IOException If the file at the given path or its content cannot be read
36
     * @throws \Box\Spout\Reader\Exception\NoSheetsFoundException If there are no sheets in the file
37
     * @return void
38
     */
39 31
    protected function openReader($filePath)
40
    {
41
        /** @var InternalEntityFactory $entityFactory */
42 31
        $entityFactory = $this->entityFactory;
43
44 31
        $this->zip = $entityFactory->createZipArchive();
45
46 31
        if ($this->zip->open($filePath) === true) {
47
            /** @var InternalEntityFactory $entityFactory */
48 31
            $entityFactory = $this->entityFactory;
49 31
            $this->sheetIterator = $entityFactory->createSheetIterator($filePath, $this->optionsManager);
50
        } else {
51
            throw new IOException("Could not open $filePath for reading.");
52
        }
53 31
    }
54
55
    /**
56
     * Returns an iterator to iterate over sheets.
57
     *
58
     * @return SheetIterator To iterate over sheets
59
     */
60 31
    protected function getConcreteSheetIterator()
61
    {
62 31
        return $this->sheetIterator;
63
    }
64
65
    /**
66
     * Closes the reader. To be used after reading the file.
67
     *
68
     * @return void
69
     */
70 28
    protected function closeReader()
71
    {
72 28
        if ($this->zip) {
73 28
            $this->zip->close();
74
        }
75 28
    }
76
}
77