Package::getParkInformation()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 9
rs 9.6666
1
<?php
2
3
namespace Thepixeldeveloper\Nolimits2PackageLoader;
4
5
use SimpleXMLElement;
6
use ZipArchive;
7
8
class Package
9
{
10
    /**
11
     * @var ZipArchive
12
     */
13
    protected $archive;
14
15
    /**
16
     * @var Park
17
     */
18
    protected $park;
19
20
    /**
21
     * @var
22
     */
23
    protected $parkXml;
24
25
    /**
26
     * @var Coasters
27
     */
28
    protected $coasters;
29
30
    /**
31
     * Package constructor.
32
     *
33
     * @param ZipArchive $archive
34
     */
35
    public function __construct(ZipArchive $archive)
36
    {
37
        $this->archive = $archive;
38
    }
39
40
    /**
41
     * @return Park
42
     */
43
    public function getParkInformation()
44
    {
45
        if ($this->park === null) {
46
            $this->park = new Park($this->getParkXml());
47
        }
48
49
        return $this->park;
50
51
    }
52
53
    /**
54
     * @return Coasters
55
     */
56
    public function getCoasters()
57
    {
58
        if ($this->coasters === null) {
59
            $this->coasters = new Coasters($this->getParkXml(), new Styles());
60
        }
61
62
        return $this->coasters;
63
    }
64
65
    /**
66
     * @return resource
67
     */
68
    public function getPreviewImageStream()
69
    {
70
        $park = $this->getParkInformation();
71
72
        return $this->archive->getStream($park->getFilesPrefix() . DIRECTORY_SEPARATOR . $park->getPreviewImage());
73
    }
74
75
    /**
76
     * @return resource
77
     */
78
    public function getParkFileStream()
79
    {
80
        $park = $this->getParkInformation();
81
82
        return $this->archive->getStream($park->getFilesPrefix() . DIRECTORY_SEPARATOR . $park->getParkFile());
83
    }
84
85
    /**
86
     * @return SimpleXMLElement
87
     */
88
    protected function getParkXml()
89
    {
90
        if ($this->parkXml === null) {
91
            $this->parkXml = (new SimpleXMLElement($this->archive->getFromName('index.xml')))->park[0];
92
        }
93
94
        return $this->parkXml;
95
    }
96
}
97