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

IsOwner   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fromValue() 0 16 6
A no() 0 4 1
A create() 0 4 1
A yes() 0 4 1
A is() 0 4 1
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
}