FuzzyMatcher::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
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