Passed
Push — master ( 6c3f09...c54108 )
by William
03:43
created

UnionKeyword   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 55.56%

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 35
ccs 5
cts 9
cp 0.5556
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 3 1
A __toString() 0 3 1
A build() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin\SqlParser\Components;
6
7
use PhpMyAdmin\SqlParser\Component;
8
use PhpMyAdmin\SqlParser\Parser;
9
use PhpMyAdmin\SqlParser\TokensList;
10
use PhpMyAdmin\SqlParser\Translator;
11
use RuntimeException;
12
13
use function implode;
14
15
/**
16
 * `UNION` keyword builder.
17
 */
18
final class UnionKeyword implements Component
19
{
20
    /**
21
     * Parses the tokens contained in the given list in the context of the given parser.
22
     *
23
     * @param Parser               $parser  the parser that serves as context
24
     * @param TokensList           $list    the list of tokens that are being parsed
25
     * @param array<string, mixed> $options parameters for parsing
26
     *
27
     * @return mixed
28
     *
29
     * @throws RuntimeException not implemented yet.
30
     */
31
    public static function parse(Parser $parser, TokensList $list, array $options = [])
32
    {
33
        throw new RuntimeException(Translator::gettext('Not implemented yet.'));
34
    }
35
36
    /**
37
     * @param array<UnionKeyword[]> $component the component to be built
38
     * @param array<string, mixed>  $options   parameters for building
39
     */
40 8
    public static function build($component, array $options = []): string
41
    {
42 8
        $tmp = [];
43 8
        foreach ($component as $componentPart) {
44 8
            $tmp[] = $componentPart[0] . ' ' . $componentPart[1];
45
        }
46
47 8
        return implode(' ', $tmp);
48
    }
49
50
    public function __toString(): string
51
    {
52
        return static::build($this);
0 ignored issues
show
Bug introduced by
$this of type PhpMyAdmin\SqlParser\Components\UnionKeyword is incompatible with the type array<mixed,PhpMyAdmin\S...ponents\UnionKeyword[]> expected by parameter $component of PhpMyAdmin\SqlParser\Com...s\UnionKeyword::build(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

52
        return static::build(/** @scrutinizer ignore-type */ $this);
Loading history...
53
    }
54
}
55