Completed
Push — master ( 8bb399...6d8696 )
by Randy
03:07
created

Some::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Dgame\Optional;
4
5
use function Dgame\Ensurance\enforce;
6
7
/**
8
 * Class Some
9
 * @package Dgame\Optional
10
 */
11
final class Some extends AbstractOptional
12
{
13
    /**
14
     * @var mixed
15
     */
16
    private $value;
17
18
    /**
19
     * Some constructor.
20
     *
21
     * @param $value
22
     */
23
    public function __construct($value)
24
    {
25
        enforce($value !== null)->orThrow('Value cannot be null');
26
27
        $this->value = $value;
28
    }
29
30
    /**
31
     * @param mixed $value
32
     *
33
     * @return bool
34
     */
35
    public function isSome(&$value = null): bool
36
    {
37
        $value = $this->value;
38
39
        return true;
40
    }
41
42
    /**
43
     * @return mixed
44
     */
45
    public function unwrap()
46
    {
47
        return $this->value;
48
    }
49
50
    /**
51
     * @param callable $callback
52
     *
53
     * @return OptionalInterface
54
     */
55
    public function ensure(callable $callback): OptionalInterface
56
    {
57
        return $callback($this->value) ? $this : None::instance();
58
    }
59
60
    /**
61
     * @param $value
62
     *
63
     * @return bool
64
     */
65
    public function isEqualTo($value): bool
66
    {
67
        return $value == $this->value;
68
    }
69
70
    /**
71
     * @param $value
72
     *
73
     * @return bool
74
     */
75
    public function isIdenticalTo($value): bool
76
    {
77
        return $value === $this->value;
78
    }
79
}