PMGL   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 73
ccs 10
cts 15
cp 0.6667
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A getFreeSpace() 0 4 1
A getPreviousChunk() 0 4 1
A getNextChunk() 0 4 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
 * A PMGL (directory listing) header of a CHM file.
11
 */
12
class PMGL extends Header
13
{
14
    /**
15
     * The length of the free space and/or the QuickRef area at the end of the directory chunk.
16
     *
17
     * @var int
18
     */
19
    protected $freeSpace;
20
21
    /**
22
     * The chunk number of the previous listing chunk when reading directory in sequence (-1 if this is the first listing chunk).
23
     *
24
     * @var int
25
     */
26
    protected $previousChunk;
27
28
    /**
29
     * The chunk number of the next listing chunk when reading directory in sequence (-1 if this is the last listing chunk).
30
     *
31
     * @var int
32
     */
33
    protected $nextChunk;
34
35
    /**
36
     * Initializes the instance.
37
     *
38
     * @param \CHMLib\Reader\Reader $reader The reader that provides the data.
39
     *
40
     * @throws \CHMLib\Exception\UnexpectedHeaderException Throws an UnexpectedHeaderException if the header signature is not valid.
41
     * @throws \Exception Throws an Exception in case of errors.
42
     */
43 4
    public function __construct(Reader $reader)
44
    {
45 4
        parent::__construct($reader);
46 4
        if ($this->headerSignature !== 'PMGL') {
47
            throw UnexpectedHeaderException::create('PMGL', $this->headerSignature);
48
        }
49 4
        $this->freeSpace = $reader->readUInt32();
50 4
        /* Unknown (0) */ $reader->readUInt32();
51 4
        $this->previousChunk = $reader->readInt32();
52 4
        $this->nextChunk = $reader->readInt32();
53 4
    }
54
55
    /**
56
     * Get the length of the free space and/or the QuickRef area at the end of the directory chunk.
57
     *
58
     * @return int
59
     */
60 4
    public function getFreeSpace()
61
    {
62 4
        return $this->freeSpace;
63
    }
64
65
    /**
66
     * Get the chunk number of the previous listing chunk when reading directory in sequence (-1 if this is the first listing chunk).
67
     *
68
     * @return int
69
     */
70
    public function getPreviousChunk()
71
    {
72
        return $this->previousChunk;
73
    }
74
75
    /**
76
     * Get the chunk number of the next listing chunk when reading directory in sequence (-1 if this is the last listing chunk).
77
     *
78
     * @return int
79
     */
80
    public function getNextChunk()
81
    {
82
        return $this->nextChunk;
83
    }
84
}
85