SortParam   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 8
c 1
b 0
f 0
dl 0
loc 27
ccs 6
cts 6
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
1
<?php
2
/**
3
 * Created by Marcin.
4
 * Date: 16.06.2018
5
 * Time: 19:21
6
 */
7
declare(strict_types=1);
8
9
namespace Mrcnpdlk\Lib\UrlSearchParser\Criteria;
10
11
use Mrcnpdlk\Lib\UrlSearchParser\Exception\InvalidParamException;
12
13
/**
14
 * Class SortParam
15
 */
16
class SortParam
17
{
18
    /**
19
     * @var string
20
     */
21
    public $param;
22
    /**
23
     * @var string
24
     */
25
    public $direction;
26
27
    /**
28
     * SortParam constructor.
29
     *
30
     * @param string $param
31
     * @param string $direction
32
     *
33
     * @throws \Mrcnpdlk\Lib\UrlSearchParser\Exception\InvalidParamException
34
     */
35 6
    public function __construct(string $param, string $direction)
36
    {
37 6
        $direction = strtoupper($direction);
38 6
        if (!in_array($direction, [Sort::DIRECTION_ASC, Sort::DIRECTION_DESC], true)) {
39 1
            throw new InvalidParamException(sprintf('Invalid direction type `%s`. Only %s is allowed', $direction, implode(',', [Sort::DIRECTION_ASC, Sort::DIRECTION_DESC])));
40
        }
41 5
        $this->param     = $param;
42 5
        $this->direction = $direction;
43 5
    }
44
}
45