Passed
Push — master ( 18a4d8...e0d339 )
by Marcin
02:40 queued 11s
created

SortParam   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 71.43%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 9
dl 0
loc 28
ccs 5
cts 7
cp 0.7143
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 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 4
    public function __construct(string $param, string $direction)
36
    {
37 4
        $direction = strtoupper($direction);
38 4
        if (!in_array($direction, [Sort::DIRECTION_ASC, Sort::DIRECTION_DESC], true)) {
39
            throw new InvalidParamException(sprintf('Invalid direction type `%s`. Only %s is allowed', $direction,
40
                implode(',', [Sort::DIRECTION_ASC, Sort::DIRECTION_DESC])));
41
        }
42 4
        $this->param     = $param;
43 4
        $this->direction = $direction;
44 4
    }
45
}
46