Failed Conditions
Push — master ( dcb275...c3bea1 )
by Arnold
02:34
created

FindingTrait   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 99
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A last() 0 3 1
A max() 0 3 1
A hasNone() 0 3 1
A hasAny() 0 3 1
A first() 0 3 1
A find() 0 3 1
A hasAll() 0 3 1
A min() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ipl\IteratorPipeline\Traits;
6
7
use Ipl 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);
1 ignored issue
show
Bug introduced by
The function iterable_first was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
        return /** @scrutinizer ignore-call */ i\iterable_first($this->iterable, $required);
Loading history...
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);
1 ignored issue
show
Bug introduced by
The function iterable_last was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
        return /** @scrutinizer ignore-call */ i\iterable_last($this->iterable, $required);
Loading history...
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);
1 ignored issue
show
Bug introduced by
The function iterable_find was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
        return /** @scrutinizer ignore-call */ i\iterable_find($this->iterable, $matcher);
Loading history...
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);
1 ignored issue
show
Bug introduced by
The function iterable_has_any was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

63
        return /** @scrutinizer ignore-call */ i\iterable_has_any($this->iterable, $matcher);
Loading history...
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);
1 ignored issue
show
Bug introduced by
The function iterable_has_all was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

74
        return /** @scrutinizer ignore-call */ i\iterable_has_all($this->iterable, $matcher);
Loading history...
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);
1 ignored issue
show
Bug introduced by
The function iterable_has_none was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

85
        return /** @scrutinizer ignore-call */ i\iterable_has_none($this->iterable, $matcher);
Loading history...
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);
1 ignored issue
show
Bug introduced by
The function iterable_min was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

98
        return /** @scrutinizer ignore-call */ i\iterable_min($this->iterable, $compare);
Loading history...
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);
1 ignored issue
show
Bug introduced by
The function iterable_max was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

110
        return /** @scrutinizer ignore-call */ i\iterable_max($this->iterable, $compare);
Loading history...
111
    }
112
}
113