Completed
Pull Request — master (#591)
by thomas
30:58
created

CompactSignature   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 72
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 7
lcom 2
cbo 2

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A convert() 0 4 1
A getRecoveryId() 0 4 1
A isCompressed() 0 4 1
A getFlags() 0 4 2
A getBuffer() 0 4 1
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