FuzzyMatcher::matchFirst()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zored\Telegram\Util\Collection;
6
7
class FuzzyMatcher implements StringMatcherInterface
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 matchFirst(string $substring, callable $getString)
23
    {
24
        $substring = mb_strtolower($substring);
25
        foreach ($this->collection as $item) {
26
            $currentValue = mb_strtolower($getString($item));
27
28
            if (false !== mb_strpos($currentValue, $substring)) {
29
                return $item;
30
            }
31
        }
32
33
        return null;
34
    }
35
}
36