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

CustomRankingAttribute::getValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 3
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
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
/*
20
 * @internal
21
 */
22
final class CustomRankingAttribute implements SettingContract
23
{
24
    /**
25
     * @var string[]
26
     */
27
    private static $customRankingKeys = [
28
        '*ed_at',
29
        'count_*',
30
        '*_count',
31
        'number_*',
32
        '*_number',
33
    ];
34
35
    /**
36
     * Checks if the given key/value is a 'CustomRanking'.
37
     *
38
     * @param  string $key
39
     * @param  array|null|string $value
40
     * @param  array $customRanking
41
     *
42
     * @return array
43
     */
44 4
    public function getValue(string $key, $value, array $customRanking): array
45
    {
46 4
        if (Str::is(self::$customRankingKeys, $key)) {
47 4
            $customRanking[] = "desc({$key})";
48
        }
49
50 4
        return $customRanking;
51
    }
52
}
53