Completed
Push — master ( 8c9d7b...4620d7 )
by Randy
02:06
created

AbstractOptional::fetch()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 9 and the first side effect is on line 32.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace Dgame\Optional;
4
5
/**
6
 * Class AbstractOptional
7
 * @package Dgame\Optional
8
 */
9
abstract class AbstractOptional implements OptionalInterface
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
Coding Style introduced by
Possible parse error: non-abstract method defined as abstract
Loading history...
Coding Style introduced by
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 OptionalInterface
41
     */
42
    final public function ensureNotFalse(): OptionalInterface
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
}