Completed
Push — master ( 572b1e...a6e9a9 )
by thomas
54:39 queued 51:18
created

CompactSignature::getR()   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 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Signature;
5
6
use BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Adapter\EcAdapter;
7
use BitWasp\Bitcoin\Crypto\EcAdapter\Impl\PhpEcc\Serializer\Signature\CompactSignatureSerializer;
8
9
class CompactSignature extends Signature implements CompactSignatureInterface
10
{
11
    /**
12
     * @var EcAdapter
13
     */
14
    private $ecAdapter;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
15
16
    /**
17
     * @var int|string
18
     */
19
    private $recid;
20
21
    /**
22
     * @var bool
23
     */
24
    private $compressed;
25
26
    /**
27
     * @param EcAdapter $adapter
28
     * @param \GMP $r
29
     * @param \GMP $s
30
     * @param int $recid
31
     * @param bool $compressed
32
     */
33 19
    public function __construct(EcAdapter $adapter, \GMP $r, \GMP $s, $recid, $compressed)
34
    {
35 19
        if (!is_bool($compressed)) {
36
            throw new \InvalidArgumentException('CompactSignature: $compressed must be a boolean');
37
        }
38
39 19
        $this->ecAdapter = $adapter;
40 19
        $this->recid = $recid;
41 19
        $this->compressed = $compressed;
42 19
        parent::__construct($adapter, $r, $s);
43 19
    }
44
45
    /**
46
     * @return Signature
47
     */
48 17
    public function convert()
49
    {
50 17
        return new Signature($this->ecAdapter, $this->getR(), $this->getS());
51
    }
52
53
    /**
54
     * @return int
55
     */
56 17
    public function getRecoveryId()
57
    {
58 17
        return $this->recid;
59
    }
60
61
    /**
62
     * @return bool
63
     */
64 17
    public function isCompressed()
65
    {
66 17
        return $this->compressed;
67
    }
68
69
    /**
70
     * @return int
71
     */
72 12
    public function getFlags()
73
    {
74 12
        return $this->getRecoveryId() + 27 + ($this->isCompressed() ? 4 : 0);
75
    }
76
77
    /**
78
     * @return \BitWasp\Buffertools\BufferInterface
79
     */
80 12
    public function getBuffer()
81
    {
82 12
        return (new CompactSignatureSerializer($this->ecAdapter))->serialize($this);
83
    }
84
}
85