Address::__toString()   A
last analyzed

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