WorksheetListReader::getWorksheetPaths()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 4
nc 3
nop 2
1
<?php
2
3
namespace Akeneo\Component\SpreadsheetParser\Xlsx;
4
5
/**
6
 * Reads the worksheet list from a spreadsheet
7
 *
8
 * @author    Antoine Guigan <[email protected]>
9
 * @copyright 2014 Akeneo SAS (http://www.akeneo.com)
10
 * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
11
 */
12
class WorksheetListReader
13
{
14
    /**
15
     * Returns the list of worksheets inside the archive
16
     *
17
     * The keys of the array should be the titles of the worksheets
18
     * The values of the array are the names of the XML worksheet files inside the archive
19
     *
20
     * @param Relationships $relationships
21
     * @param string        $path
22
     * 
23
     * @return array
24
     */
25
    public function getWorksheetPaths(Relationships $relationships, $path)
26
    {
27
        $xml = new \XMLReader();
28
        $xml->open($path);
29
        $paths = [];
30
        while ($xml->read()) {
31
            if (\XMLReader::ELEMENT === $xml->nodeType && 'sheet' === $xml->name) {
32
                $rId = $xml->getAttributeNs(
33
                    'id',
34
                    'http://schemas.openxmlformats.org/officeDocument/2006/relationships'
35
                );
36
                $paths[$xml->getAttribute('name')] = $relationships->getWorksheetPath($rId);
37
            }
38
        }
39
40
        return $paths;
41
    }
42
}
43