Some::isIdenticalTo()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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