ScoreMode::scoreMode()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 0
loc 15
ccs 0
cts 13
cp 0
crap 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of PhpStorm.
4
 *
5
 * (c) PHPinnacle Team <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace PHPinnacle\Elastics\Traits;
14
15
use PHPinnacle\Elastics\Exception;
16
17
trait ScoreMode
18
{
19
    /**
20
     * @var string
21
     */
22
    private $scoreMode;
23
24
    /**
25
     * @param string $mode
26
     *
27
     * @return self
28
     */
29
    public function scoreMode(string $mode): self
30
    {
31
        if (!\in_array($mode, [
32
            \ELASTICS_SCORE_MODE_AVG,
33
            \ELASTICS_SCORE_MODE_SUM,
34
            \ELASTICS_SCORE_MODE_MIN,
35
            \ELASTICS_SCORE_MODE_MAX,
36
            \ELASTICS_SCORE_MODE_NONE,
37
        ], true)) {
38
            throw new Exception\InvalidScoreMode($mode);
39
        }
40
41
        $this->scoreMode = $mode;
42
43
        return $this;
44
    }
45
}
46