ConditionMatch::find()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 3
eloc 4
nc 3
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zored\Telegram\Util\Collection;
6
7
class ConditionMatch
8
{
9
    /**
10
     * @var iterable
11
     */
12
    private $collection;
13
14
    public function __construct(iterable $collection)
15
    {
16
        $this->collection = $collection;
17
    }
18
19
    /**
20
     * @return object|null
21
     */
22
    public function find(callable $condition)
23
    {
24
        foreach ($this->collection as $item) {
25
            if ($condition($item)) {
26
                return $item;
27
            }
28
        }
29
30
        return null;
31
    }
32
}
33