Completed
Pull Request — refacto/local-factory (#166)
by Nuno
19:50 queued 15:15
created

DisableTypoToleranceAttribute::exist()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.576

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 3
dl 0
loc 9
ccs 3
cts 5
cp 0.6
crap 3.576
rs 10
c 0
b 0
f 0
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
class DisableTypoToleranceAttribute implements SettingContract
20
{
21
    /**
22
     * @var string[]
23
     */
24
    private static $disableTypoToleranceOnAttributesKeys = [
25
        'slug',
26
        '*_slug',
27
        'slug_*',
28
        '*code*',
29
        '*sku*',
30
        '*reference*',
31
    ];
32
33
    /**
34
     * Checks if the given key/value is a 'disableTypoToleranceOnAttributes'.
35
     *
36
     * @param  string $key
37
     * @param  array|null|string $value
38
     * @param  array $disableTypoToleranceOnAttributes
39
     *
40
     * @return array
41
     */
42 3
    public function getValue(string $key, $value, array $disableTypoToleranceOnAttributes): array
43
    {
44 3
        if (is_string($key) && Str::is(self::$disableTypoToleranceOnAttributesKeys, $key)) {
45
            $disableTypoToleranceOnAttributes[] = $key;
46
        }
47
48 3
        return $disableTypoToleranceOnAttributes;
49
    }
50
}
51