Completed
Pull Request — master (#446)
by thomas
222:53 queued 219:12
created

TransactionInputSerializer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 11

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 65
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 11

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A serialize() 0 8 1
A fromParser() 0 8 1
A parse() 0 4 1
1
<?php
2
3
namespace BitWasp\Bitcoin\Serializer\Transaction;
4
5
use BitWasp\Bitcoin\Script\Script;
6
use BitWasp\Bitcoin\Serializer\Types;
7
use BitWasp\Bitcoin\Transaction\TransactionInput;
8
use BitWasp\Bitcoin\Transaction\TransactionInputInterface;
9
use BitWasp\Buffertools\Buffer;
10
use BitWasp\Buffertools\BufferInterface;
11
use BitWasp\Buffertools\Parser;
12
13
class TransactionInputSerializer
14
{
15
    /**
16
     * @var OutPointSerializer
17
     */
18
    private $outpointSerializer;
19
20
    /**
21
     * @var \BitWasp\Buffertools\Types\VarString
22
     */
23
    private $varstring;
24
25
    /**
26
     * @var \BitWasp\Buffertools\Types\Uint32
27
     */
28
    private $uint32le;
29 2692
30
    /**
31 2692
     * TransactionInputSerializer constructor.
32 2692
     * @param OutPointSerializerInterface $outPointSerializer
33 2692
     */
34
    public function __construct(OutPointSerializerInterface $outPointSerializer)
35
    {
36
        $this->outpointSerializer = $outPointSerializer;
0 ignored issues
show
Documentation Bug introduced by
$outPointSerializer is of type object<BitWasp\Bitcoin\S...intSerializerInterface>, but the property $outpointSerializer was declared to be of type object<BitWasp\Bitcoin\S...ion\OutPointSerializer>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
37
        $this->varstring = Types::varstring();
38 2692
        $this->uint32le = Types::uint32le();
39
    }
40 2692
41 2692
    /**
42 2692
     * @param TransactionInputInterface $input
43 2692
     * @return BufferInterface
44
     */
45
    public function serialize(TransactionInputInterface $input)
46
    {
47
        return new Buffer(
48
            $this->outpointSerializer->serialize($input->getOutPoint())->getBinary() .
49
            $this->varstring->write($input->getScript()->getBuffer()) .
50 2602
            $this->uint32le->write($input->getSequence())
51
        );
52 2602
    }
53 2602
54 2602
    /**
55 2602
     * @param Parser $parser
56 2602
     * @return TransactionInput
57 1301
     * @throws \BitWasp\Buffertools\Exceptions\ParserOutOfRange
58 1301
     */
59
    public function fromParser(Parser $parser)
60
    {
61
        return new TransactionInput(
62
            $this->outpointSerializer->fromParser($parser),
63
            new Script($this->varstring->read($parser)),
64
            $this->uint32le->read($parser)
65
        );
66 198
    }
67
68 198
    /**
69
     * @param BufferInterface|string $string
70
     * @return TransactionInput
71
     * @throws \BitWasp\Buffertools\Exceptions\ParserOutOfRange
72
     */
73
    public function parse($string)
74 198
    {
75
        return $this->fromParser(new Parser($string));
76 198
    }
77
}
78