ConditionMatch   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 24
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A find() 0 9 3
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