Completed
Pull Request — master (#405)
by Adrien
04:04
created

SettingsHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 38
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getActiveSheetName() 0 24 5
1
<?php
2
3
namespace Box\Spout\Reader\ODS\Helper;
4
5
use Box\Spout\Reader\Wrapper\XMLReader;
6
7
/**
8
 * Class SettingsHelper
9
 * This class provides helper functions to extract data from the "settings.xml" file.
10
 *
11
 * @package Box\Spout\Reader\ODS\Helper
12
 */
13
class SettingsHelper
14
{
15
    const SETTINGS_XML_FILE_PATH = 'settings.xml';
16
17
    /** Definition of XML nodes name and attribute used to parse settings data */
18
    const XML_NODE_CONFIG_ITEM = 'config:config-item';
19
    const XML_ATTRIBUTE_CONFIG_NAME = 'config:name';
20
    const XML_ATTRIBUTE_VALUE_ACTIVE_TABLE = 'ActiveTable';
21
22
    /**
23
     * @param string $filePath Path of the file to be read
24
     * @return string|null Name of the sheet that was defined as active or NULL if none found
25
     */
26 90
    public function getActiveSheetName($filePath)
27
    {
28 90
        $xmlReader = new XMLReader();
29 90
        if ($xmlReader->openFileInZip($filePath, self::SETTINGS_XML_FILE_PATH) === false) {
30 57
            return null;
31
        }
32
33 33
        $activeSheetName = null;
34
35
        try {
36 33
            while ($xmlReader->readUntilNodeFound(self::XML_NODE_CONFIG_ITEM)) {
37 33
                if ($xmlReader->getAttribute(self::XML_ATTRIBUTE_CONFIG_NAME) === self::XML_ATTRIBUTE_VALUE_ACTIVE_TABLE) {
38 33
                    $activeSheetName = $xmlReader->readString();
39 33
                    break;
40
                }
41 33
            }
42 33
        } catch (XMLProcessingException $exception) {
0 ignored issues
show
Bug introduced by
The class Box\Spout\Reader\ODS\Helper\XMLProcessingException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
43
            // do nothing
44
        }
45
46 33
        $xmlReader->close();
47
48 33
        return $activeSheetName;
49
    }
50
}
51