Completed
Push — master ( a3c7f3...e65d14 )
by Arnold
02:17
created

FindingTrait::hasNone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Improved\IteratorPipeline\Traits;
6
7
use Improved as i;
8
9
/**
10
 * Pipeline methods for finding an element in an iterable.
11
 */
12
trait FindingTrait
13
{
14
    /**
15
     * @var iterable
16
     */
17
    protected $iterable;
18
19
20
    /**
21
     * Get the first value of an iterable.
22
     *
23
     * @param bool $required  Throw RangeException instead of returning null for empty iterable
24
     * @return mixed
25
     */
26 2
    public function first(bool $required = false)
27
    {
28 2
        return i\iterable_first($this->iterable, $required);
29
    }
30
31
    /**
32
     * Get the last value of an iterable.
33
     *
34
     * @param bool $required  Throw RangeException instead of returning null for empty iterable
35
     * @return mixed
36
     */
37 2
    public function last(bool $required = false)
38
    {
39 2
        return i\iterable_last($this->iterable, $required);
40
    }
41
42
43
    /**
44
     * Get the first value that matches a condition.
45
     * Returns null if no element is found.
46
     *
47
     * @param callable $matcher
48
     * @return mixed
49
     */
50 1
    public function find(callable $matcher)
51
    {
52 1
        return i\iterable_find($this->iterable, $matcher);
53
    }
54
55
    /**
56
     * Check if any element matches the condition.
57
     *
58
     * @param callable $matcher
59
     * @return bool
60
     */
61 1
    public function hasAny(callable $matcher): bool
62
    {
63 1
        return i\iterable_has_any($this->iterable, $matcher);
64
    }
65
66
    /**
67
     * Check if all elements match the condition.
68
     *
69
     * @param callable $matcher
70
     * @return bool
71
     */
72 1
    public function hasAll(callable $matcher): bool
73
    {
74 1
        return i\iterable_has_all($this->iterable, $matcher);
75
    }
76
77
    /**
78
     * Check that no elements match the condition.
79
     *
80
     * @param callable $matcher
81
     * @return bool
82
     */
83 1
    public function hasNone(callable $matcher): bool
84
    {
85 1
        return i\iterable_has_none($this->iterable, $matcher);
86
    }
87
88
89
    /**
90
     * Get the minimal value according to a given comparator.
91
     * Returns null for an empty iterable.
92
     *
93
     * @param callable|null $compare
94
     * @return mixed
95
     */
96 2
    public function min(?callable $compare = null)
97
    {
98 2
        return i\iterable_min($this->iterable, $compare);
99
    }
100
101
    /**
102
     * Get the maximal value according to a given comparator.
103
     * Returns null for an empty iterable.
104
     *
105
     * @param callable|null $compare
106
     * @return mixed
107
     */
108 2
    public function max(?callable $compare = null)
109
    {
110 2
        return i\iterable_max($this->iterable, $compare);
111
    }
112
}
113