Completed
Push — master ( 578d3a...04a929 )
by Maurício
34s queued 14s
created

OrderKeyword::parse()   C

Complexity

Conditions 14
Paths 6

Size

Total Lines 64
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 27
CRAP Score 14

Importance

Changes 0
Metric Value
cc 14
eloc 28
c 0
b 0
f 0
nc 6
nop 3
dl 0
loc 64
ccs 27
cts 27
cp 1
crap 14
rs 6.2666

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin\SqlParser\Components;
6
7
use PhpMyAdmin\SqlParser\Component;
8
9
/**
10
 * `ORDER BY` keyword parser.
11
 */
12
final class OrderKeyword implements Component
13
{
14
    /**
15
     * The expression that is used for ordering.
16
     *
17
     * @var Expression
18
     */
19
    public $expr;
20
21
    /**
22
     * The order type.
23
     *
24
     * @var string
25
     */
26
    public $type;
27
28
    /**
29
     * @param Expression $expr the expression that we are sorting by
30
     * @param string     $type the sorting type
31
     */
32 58
    public function __construct(Expression|null $expr = null, string $type = 'ASC')
33
    {
34 58
        $this->expr = $expr;
35 58
        $this->type = $type;
36
    }
37
38 20
    public function build(): string
39
    {
40 20
        return $this->expr . ' ' . $this->type;
41
    }
42
43 20
    public function __toString(): string
44
    {
45 20
        return $this->build();
46
    }
47
}
48