Completed
Pull Request — master (#591)
by thomas
30:19 queued 12s
created

CompactSignature::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

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