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

searchableAttribute   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 48
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 9 5
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 searchableAttribute implements SettingContract
20
{
21
    /**
22
     * @var string[]
23
     */
24
    private static $unsearchableAttributesKeys = [
25
        'id',
26
        '*_id',
27
        'id_*',
28
        '*ed_at',
29
        '*_count',
30
        'count_*',
31
        'number_*',
32
        '*_number',
33
        '*image*',
34
        '*url*',
35
        '*link*',
36
        '*password*',
37
        '*token*',
38
        '*hash*',
39
    ];
40
41
    /**
42
     * @var string[]
43
     */
44
    private static $unsearchableAttributesValues = [
45
        'http://*',
46
        'https://*',
47
    ];
48
49
    /**
50
     * Checks if the given key/value is a 'searchableAttributes'.
51
     *
52
     * @param  string $key
53
     * @param  array|null|string $value
54
     * @param  array $searchableAttributes
55
     *
56
     * @return array
57
     */
58 3
    public function getValue(string $key, $value, array $searchableAttributes): array
59
    {
60 3
        if (! is_object($value) && ! is_array($value) &&
61 3
            ! Str::is(self::$unsearchableAttributesKeys, $key) &&
62 3
            ! Str::is(self::$unsearchableAttributesValues, $value)) {
63 3
            $searchableAttributes[] = $key;
64
        }
65
66 3
        return $searchableAttributes;
67
    }
68
}
69