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

SortParam::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0932

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 9
ccs 5
cts 7
cp 0.7143
rs 10
c 1
b 0
f 0
cc 2
nc 2
nop 2
crap 2.0932
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