GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

OrderBy::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 3
eloc 6
nc 4
nop 3
1
<?php
2
3
namespace Rb\Specification\Doctrine\Query;
4
5
use Doctrine\ORM\QueryBuilder;
6
use Rb\Specification\Doctrine\AbstractSpecification;
7
use Rb\Specification\Doctrine\Exception\InvalidArgumentException;
8
9
/**
10
 * Class OrderBy.
11
 */
12
class OrderBy extends AbstractSpecification
13
{
14
    const ASC  = 'ASC';
15
    const DESC = 'DESC';
16
17
    /**
18
     * @var string
19
     */
20
    protected $order;
21
22
    private static $validOrder = [self::ASC, self::DESC];
23
24
    /**
25
     * @param string      $field
26
     * @param string      $order
27
     * @param string|null $dqlAlias
28
     *
29
     * @throws InvalidArgumentException
30
     */
31
    public function __construct($field, $order = null, $dqlAlias = null)
32
    {
33
        $order = ! $order ? self::ASC : strtoupper($order);
34
35
        if (! in_array($order, self::$validOrder, true)) {
36
            throw new InvalidArgumentException();
37
        }
38
39
        $this->order = $order;
40
41
        parent::__construct($field, $dqlAlias);
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function modify(QueryBuilder $queryBuilder, $dqlAlias)
48
    {
49
        $queryBuilder->addOrderBy(
50
            $this->createPropertyWithAlias($dqlAlias),
51
            $this->order
52
        );
53
    }
54
}
55