UncompressedSection::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace CHMLib\Section;
4
5
use CHMLib\CHM;
6
7
/**
8
 * Represent an uncompressed section of data in a CHM file.
9
 */
10
class UncompressedSection extends Section
11
{
12
    /**
13
     * Initializes the instance.
14
     *
15
     * @param \CHMLib\CHM $chm The parent CHM file.
16
     */
17 4
    public function __construct(CHM $chm)
18
    {
19 4
        parent::__construct($chm);
20 4
        $this->sectionOffset = $chm->getITSF()->getContentOffset();
21 4
    }
22
23
    /**
24
     * {@inheritdoc}
25
     *
26
     * @see \CHMLib\Section\Section::getContents()
27
     */
28 10
    public function getContents($offset, $length)
29
    {
30 10
        if ($length === 0) {
31 3
            $result = '';
32
        } else {
33 7
            $reader = $this->chm->getReader();
34 7
            $reader->setPosition($this->sectionOffset + $offset);
35 7
            $result = $reader->readString($length);
36
        }
37
38 10
        return $result;
39
    }
40
}
41