Request   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 11
c 2
b 0
f 0
dl 0
loc 42
ccs 0
cts 16
cp 0
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A toNative() 0 3 1
A equals() 0 4 1
A makeEmpty() 0 3 1
A isEmpty() 0 3 1
A fromNative() 0 5 1
A __construct() 0 3 1
A __toString() 0 3 1
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