AbstractXMLResource   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 80
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __destruct() 0 6 2
A getXMLReader() 0 8 2
A createXMLReader() 0 7 1
A closeXMLReader() 0 5 1
1
<?php
2
3
namespace Akeneo\Component\SpreadsheetParser\Xlsx;
4
5
/**
6
 * Base class for single files XML resources
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
abstract class AbstractXMLResource
13
{
14
    /**
15
     * @var string
16
     */
17
    protected $path;
18
19
    /**
20
     * @var \XMLReader
21
     */
22
    private $xml;
23
24
    /**
25
     * The Archive from which the path was extracted.
26
     *
27
     * A reference to the object is kept here to ensure that it is not deleted
28
     * before the RowIterator, as this would remove the extraction folder.
29
     *
30
     * @var Archive
31
     */
32
    private $archive;
33
34
    /**
35
     * Constructor
36
     *
37
     * @param string        $path    path to the extracted shared strings XML file
38
     * @param Archive|null  $archive The Archive from which the path was extracted
39
     */
40
    public function __construct($path, Archive $archive = null)
41
    {
42
        $this->path = $path;
43
        $this->archive = $archive;
44
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49
    public function __destruct()
50
    {
51
        if ($this->xml) {
52
            $this->closeXMLReader();
53
        }
54
    }
55
56
    /**
57
     * Returns the XML reader
58
     *
59
     * @return \XMLReader
60
     */
61
    protected function getXMLReader()
62
    {
63
        if (!$this->xml) {
64
            $this->xml = $this->createXMLReader();
65
        }
66
67
        return $this->xml;
68
    }
69
70
    /**
71
     * Creates the XML Reader
72
     *
73
     * @return \XMLReader
74
     */
75
    protected function createXMLReader()
76
    {
77
        $xml = new \XMLReader();
78
        $xml->open($this->path);
79
80
        return $xml;
81
    }
82
83
    /**
84
     * Closes the XML reader
85
     */
86
    protected function closeXMLReader()
87
    {
88
        $this->xml->close();
89
        $this->xml = null;
90
    }
91
}
92