Passed
Push — master ( 365cfc...8e997c )
by Mr
04:36
created

BitcoinTransactionHashReceived::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the ngutech/bitcoin-interop project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace NGUtech\Bitcoin\Message;
10
11
use Daikon\Interop\Assertion;
12
use Daikon\ValueObject\Timestamp;
0 ignored issues
show
Bug introduced by
The type Daikon\ValueObject\Timestamp 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...
13
use NGUtech\Bitcoin\ValueObject\Hash;
14
15
final class BitcoinTransactionHashReceived implements BitcoinMessageInterface
16
{
17
    private Hash $hash;
18
19
    private Timestamp $receivedAt;
20
21
    /** @param array $state */
22
    public static function fromNative($state): self
23
    {
24
        Assertion::isArray($state);
25
        Assertion::keyExists($state, 'hash');
26
        Assertion::keyExists($state, 'receivedAt');
27
28
        return new self(
29
            Hash::fromNative($state['hash']),
30
            Timestamp::fromNative($state['receivedAt'])
31
        );
32
    }
33
34
    public function toNative(): array
35
    {
36
        return [
37
            'hash' => (string)$this->hash,
38
            'receivedAt' => (string)$this->receivedAt
39
        ];
40
    }
41
42
    public function getHash(): Hash
43
    {
44
        return $this->hash;
45
    }
46
47
    public function getReceivedAt(): Timestamp
48
    {
49
        return $this->receivedAt;
50
    }
51
52
    public function __toString(): string
53
    {
54
        return (string)$this->hash;
55
    }
56
57
    private function __construct(Hash $hash, Timestamp $receivedAt)
58
    {
59
        $this->hash = $hash;
60
        $this->receivedAt = $receivedAt;
61
    }
62
}
63