Completed
Push — feature/pilot_information ( 13ff1e...cc067b )
by Laurent
01:46
created

IsOwner::fromValue()   A

Complexity

Conditions 6
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
nc 4
nop 1
dl 0
loc 16
rs 9.1111
c 0
b 0
f 0
1
<?php
2
3
4
namespace FlightLog\Domain\Pilot\ValueObject;
5
6
7
final class IsOwner
8
{
9
10
    /**
11
     * @var bool|null
12
     */
13
    private $value;
14
15
    private function __construct(bool $value)
16
    {
17
        $this->value = $value;
18
    }
19
20
    public static function fromValue($value)
21
    {
22
        if (null === $value) {
23
            return self::no();
24
        }
25
26
        if (is_numeric($value) || is_int($value) || (int)$value == $value) {
27
            return new self($value == 1);
28
        }
29
30
        if (is_string($value)) {
31
            return new self(in_array($value, ['y', 't']));
32
        }
33
34
        return new self($value);
35
    }
36
37
    public static function no(): self
38
    {
39
        return new self(false);
40
    }
41
42
    public static function create(): self
43
    {
44
        return self::no();
45
    }
46
47
    public static function yes(): self
48
    {
49
        return new self(true);
50
    }
51
52
    public function is(): bool
53
    {
54
        return $this->value;
55
    }
56
57
58
}