Completed
Push — master ( 1d7ad2...efdc9e )
by Michele
05:30
created

LZXC::getCacheSize()   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 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace CHMLib\Header;
4
5
use Exception;
6
use CHMLib\Reader\Reader;
7
use CHMLib\Exception\UnexpectedHeaderException;
8
9
/**
10
 * The LXZ header of a CHM file.
11
 */
12
class LZXC extends Header
13
{
14
    /**
15
     * The header version.
16
     *
17
     * @var int
18
     */
19
    protected $version;
20
21
    /**
22
     * The LZX reset interval.
23
     *
24
     * @var int
25
     */
26
    protected $resetInterval;
27
28
    /**
29
     * The window size in 32KB blocks.
30
     *
31
     * @var int
32
     */
33
    protected $windowSize;
34
35
    /**
36
     * The cache size.
37
     *
38
     * @var int
39
     */
40
    protected $cacheSize;
41
42
    /**
43
     * Initializes the instance.
44
     *
45
     * @param Reader $reader The reader that provides the data.
46
     *
47
     * @throws UnexpectedHeaderException Throws an UnexpectedHeaderException if the header signature is not valid.
48
     * @throws Exception Throws an Exception in case of errors.
49
     */
50 1
    public function __construct(Reader $reader)
51
    {
52 1
        $size = $reader->readUInt32();
53 1
        if ($size < 6) {
54
            throw new Exception('The LZXC entry is too small');
55
        }
56 1
        parent::__construct($reader);
57 1
        if ($this->headerSignature !== 'LZXC') {
58
            throw UnexpectedHeaderException::create('LZXC', $this->headerSignature);
59
        }
60 1
        $this->version = $reader->readUInt32();
61 1
        if ($this->version !== 2) {
62
            throw new Exception("Unsupported LZXC header version: {$this->version}");
63
        }
64 1
        $this->resetInterval = $reader->readUInt32();
65 1
        $this->windowSize = $reader->readUInt32();
66 1
        $this->cacheSize = $reader->readUInt32();
67 1
    }
68
69
    /**
70
     * Get the header version.
71
     *
72
     * @return int
73
     */
74
    public function getVersion()
75
    {
76
        return $this->version;
77
    }
78
79
    /**
80
     * Get the LZX reset interval.
81
     *
82
     * @return int
83
     */
84 1
    public function getResetInterval()
85
    {
86 1
        return $this->resetInterval;
87
    }
88
89
    /**
90
     * Get the window size in 32KB blocks.
91
     *
92
     * @return int
93
     */
94 1
    public function getWindowSize()
95
    {
96 1
        return $this->windowSize;
97
    }
98
99
    /**
100
     * Get the cache size.
101
     *
102
     * @return int
103
     */
104 1
    public function getCacheSize()
105
    {
106 1
        return $this->cacheSize;
107
    }
108
}
109