Crc32Exception::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1.0046

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 3
dl 0
loc 12
ccs 5
cts 6
cp 0.8333
crap 1.0046
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PhpZip\Exception;
4
5
/**
6
 * Thrown to indicate a CRC32 mismatch between the declared value in the
7
 * Central File Header and the Data Descriptor or between the declared value
8
 * and the computed value from the decompressed data.
9
 *
10
 * The exception detail message is the name of the ZIP entry.
11
 *
12
 * @author Ne-Lexa [email protected]
13
 * @license MIT
14
 */
15
class Crc32Exception extends ZipException
16
{
17
    /**
18
     * Expected crc.
19
     *
20
     * @var int
21
     */
22
    private $expectedCrc;
23
24
    /**
25
     * Actual crc.
26
     *
27
     * @var int
28
     */
29
    private $actualCrc;
30
31
    /**
32
     * Crc32Exception constructor.
33
     *
34
     * @param string $name
35
     * @param int    $expected
36
     * @param int    $actual
37
     */
38 2
    public function __construct($name, $expected, $actual)
39
    {
40 2
        parent::__construct(
41
            sprintf(
42 2
                '%s (expected CRC32 value 0x%x, but is actually 0x%x)',
43
                $name,
44
                $expected,
45
                $actual
46
            )
47
        );
48 2
        $this->expectedCrc = $expected;
49 2
        $this->actualCrc = $actual;
50 2
    }
51
52
    /**
53
     * Returns expected crc.
54
     *
55
     * @return int
56
     */
57
    public function getExpectedCrc()
58
    {
59
        return $this->expectedCrc;
60
    }
61
62
    /**
63
     * Returns actual crc.
64
     *
65
     * @return int
66
     */
67
    public function getActualCrc()
68
    {
69
        return $this->actualCrc;
70
    }
71
}
72