Passed
Pull Request — master (#776)
by
unknown
40:03
created

ExtraPayloadSerializer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getBuffer() 0 3 1
A fromParser() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BitWasp\Bitcoin\Serializer\ExtraPayload;
6
7
use BitWasp\Bitcoin\ExtraPayload\ExtraPayload;
8
use BitWasp\Bitcoin\ExtraPayload\ExtraPayloadInterface;
9
use BitWasp\Bitcoin\Serializer\Types;
10
use BitWasp\Buffertools\Buffer;
11
use BitWasp\Buffertools\BufferInterface;
12
use BitWasp\Buffertools\Parser;
13
14
class ExtraPayloadSerializer
15
{
16
    /**
17
     * @var \BitWasp\Buffertools\Types\VarInt
18
     */
19
    private $varint;
20
21
    public function __construct()
22
    {
23
        $this->varint = Types::varint();
24
    }
25
26
    /**
27
     * @param Parser $parser
28
     * @return ExtraPayloadInterface
29
     */
30
    public function fromParser(Parser $parser): ExtraPayloadInterface
31
    {
32
        $extra_payload_size = $this->varint->read($parser);
33
34
        if ($extra_payload_size > $parser->getSize() - $parser->getPosition()) {
35
            throw new ParserOutOfRange("Invalid Extra Payload Size");
0 ignored issues
show
Bug introduced by
The type BitWasp\Bitcoin\Serializ...ayload\ParserOutOfRange was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
36
        }
37
38
        $extraPayloadBuffer = $parser->readBytes((int) $extra_payload_size);
39
40
        return new ExtraPayload($extraPayloadBuffer);
41
    }
42
43
    /**
44
     * @param ExtraPayloadInterface $extra_payload
45
     * @return BufferInterface
46
     */
47
    public function getBuffer(ExtraPayloadInterface $extra_payload): BufferInterface
48
    {
49
        return $extra_payload[0];
50
    }
51
}
52