FuzzyMatcher   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

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

2 Methods

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