Request::toNative()   A
last analyzed

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