Completed
Push — master ( b93bd2...539d39 )
by Randy
01:46
created

src/OptionalBase.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Dgame\Optional;
4
5
/**
6
 * Class OptionalBase
7
 * @package Dgame\Optional
8
 */
9
abstract class OptionalBase implements Optional
10
{
11
    /**
12
     * @return bool
13
     */
14
    final public function isNone(): bool
15
    {
16
        return !$this->isSome();
17
    }
18
19
    /**
20
     * @param $default
21
     *
22
     * @return mixed
23
     */
24
    final public function default($default)
0 ignored issues
show
Possible parse error: non-abstract method defined as abstract
Loading history...
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
25
    {
26
        return $this->isSome($value) ? $value : $default;
27
    }
28
29
    /**
30
     * @param callable $callback
31
     */
32
    final public function do(callable $callback)
33
    {
34
        if ($this->isSome($value)) {
35
            $callback($value);
36
        }
37
    }
38
39
    /**
40
     * @return Optional
41
     */
42
    final public function ensureNotFalse(): Optional
43
    {
44
        return $this->ensure(function ($value): bool {
45
            return $value !== false;
46
        });
47
    }
48
49
    /**
50
     * @param $value
51
     *
52
     * @return bool
53
     */
54
    final public function isNotEqualTo($value): bool
55
    {
56
        return !$this->isEqualTo($value);
57
    }
58
59
    /**
60
     * @param $value
61
     *
62
     * @return bool
63
     */
64
    final public function isNotIdenticalTo($value): bool
65
    {
66
        return !$this->isIdenticalTo($value);
67
    }
68
}