Passed
Pull Request — master (#170)
by
unknown
08:08
created

DisableTypoToleranceAttribute   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 30
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 7 3
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Scout Extended.
7
 *
8
 * (c) Algolia Team <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Algolia\ScoutExtended\Settings\SettingAttribute;
15
16
use Illuminate\Support\Str;
17
use Algolia\ScoutExtended\Contracts\SettingContract;
18
19
/*
20
 * @internal
21
 */
22
final class DisableTypoToleranceAttribute implements SettingContract
23
{
24
    /**
25
     * @var string[]
26
     */
27
    private static $disableTypoToleranceOnAttributesKeys = [
28
        'slug',
29
        '*_slug',
30
        'slug_*',
31
        '*code*',
32
        '*sku*',
33
        '*reference*',
34
    ];
35
36
    /**
37
     * Checks if the given key/value is a 'disableTypoToleranceOnAttributes'.
38
     *
39
     * @param  string $key
40
     * @param  array|null|string $value
41
     * @param  array $disableTypoToleranceOnAttributes
42
     *
43
     * @return array
44
     */
45 4
    public function getValue(string $key, $value, array $disableTypoToleranceOnAttributes): array
46
    {
47 4
        if (is_string($key) && Str::is(self::$disableTypoToleranceOnAttributesKeys, $key)) {
48 1
            $disableTypoToleranceOnAttributes[] = $key;
49
        }
50
51 4
        return $disableTypoToleranceOnAttributes;
52
    }
53
}
54