Completed
Pull Request — master (#316)
by thomas
72:49 queued 02:58
created

CompactSignature::getS()   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
    public function __construct(EcAdapter $adapter, \GMP $r, \GMP $s, $recid, $compressed)
34
    {
35
        if (!is_bool($compressed)) {
36
            throw new \InvalidArgumentException('CompactSignature: $compressed must be a boolean');
37
        }
38
39
        $this->ecAdapter = $adapter;
40
        $this->recid = $recid;
41
        $this->compressed = $compressed;
42
        parent::__construct($adapter, $r, $s);
43
    }
44 19
45
    /**
46 19
     * @return Signature
47
     */
48
    public function convert()
49
    {
50 19
        return new Signature($this->ecAdapter, $this->getR(), $this->getS());
51 19
    }
52 19
53 19
    /**
54 19
     * @return int
55 19
     */
56
    public function getRecoveryId()
57
    {
58
        return $this->recid;
59
    }
60 17
61
    /**
62 17
     * @return bool
63
     */
64
    public function isCompressed()
65
    {
66
        return $this->compressed;
67
    }
68 17
69
    /**
70 17
     * @return int
71
     */
72
    public function getFlags()
73
    {
74
        return $this->getRecoveryId() + 27 + ($this->isCompressed() ? 4 : 0);
75
    }
76 17
77
    /**
78 17
     * @return \BitWasp\Buffertools\BufferInterface
79
     */
80
    public function getBuffer()
81
    {
82
        return (new CompactSignatureSerializer($this->ecAdapter))->serialize($this);
83
    }
84
}
85