Passed
Push — master ( aeafff...f9e723 )
by Mr
02:06
created

Address::toNative()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/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 Daikon\Bitcoin\ValueObject;
10
11
use Daikon\Interop\Assertion;
12
use Daikon\Interop\MakeEmptyInterface;
13
use Daikon\ValueObject\ValueObjectInterface;
14
15
final class Address implements MakeEmptyInterface, ValueObjectInterface
16
{
17
    private string $address;
18
19
    /** @param string|null $value */
20 5
    public static function fromNative($value): self
21
    {
22
        //@todo improve address validation
23 5
        Assertion::nullOrString($value, 'Must be a string.');
24 5
        return is_null($value) ? new self : new self($value);
25
    }
26
27 3
    public static function makeEmpty(): self
28
    {
29 3
        return new self;
30
    }
31
32 2
    public function isEmpty(): bool
33
    {
34 2
        return $this->address === '';
35
    }
36
37
    /** @param self $comparator */
38 1
    public function equals($comparator): bool
39
    {
40 1
        Assertion::isInstanceOf($comparator, self::class);
41 1
        return $this->toNative() === $comparator->toNative();
42
    }
43
44 3
    public function toNative(): string
45
    {
46 3
        return $this->address;
47
    }
48
49 2
    public function __toString(): string
50
    {
51 2
        return (string)$this->address;
52
    }
53
54 5
    private function __construct(string $address = '')
55
    {
56 5
        $this->address = $address;
57 5
    }
58
}
59