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

IndexHint::parse()   D

Complexity

Conditions 24
Paths 6

Size

Total Lines 109
Code Lines 60

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 54
CRAP Score 24

Importance

Changes 0
Metric Value
cc 24
eloc 60
c 0
b 0
f 0
nc 6
nop 3
dl 0
loc 109
ccs 54
cts 54
cp 1
crap 24
rs 4.1666

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
 * Parses an Index hint.
11
 */
12
final class IndexHint implements Component
13
{
14
    /**
15
     * The type of hint (USE/FORCE/IGNORE)
16
     */
17
    public string|null $type;
18
19
    /**
20
     * What the hint is for (INDEX/KEY)
21
     */
22
    public string|null $indexOrKey;
23
24
    /**
25
     * The clause for which this hint is (JOIN/ORDER BY/GROUP BY)
26
     */
27
    public string|null $for;
28
29
    /**
30
     * List of indexes in this hint
31
     *
32
     * @var Expression[]
33
     */
34
    public array $indexes = [];
35
36
    /**
37
     * @param string       $type       the type of hint (USE/FORCE/IGNORE)
38
     * @param string       $indexOrKey What the hint is for (INDEX/KEY)
39
     * @param string       $for        the clause for which this hint is (JOIN/ORDER BY/GROUP BY)
40
     * @param Expression[] $indexes    List of indexes in this hint
41
     */
42 14
    public function __construct(
43
        string|null $type = null,
44
        string|null $indexOrKey = null,
45
        string|null $for = null,
46
        array $indexes = [],
47
    ) {
48 14
        $this->type = $type;
49 14
        $this->indexOrKey = $indexOrKey;
50 14
        $this->for = $for;
51 14
        $this->indexes = $indexes;
52
    }
53
54 2
    public function build(): string
55
    {
56 2
        $ret = $this->type . ' ' . $this->indexOrKey . ' ';
57 2
        if ($this->for !== null) {
58 2
            $ret .= 'FOR ' . $this->for . ' ';
59
        }
60
61 2
        return $ret . Expression::buildAll($this->indexes);
62
    }
63
64 2
    public function __toString(): string
65
    {
66 2
        return $this->build();
67
    }
68
}
69