ParameterDefinition   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 44
ccs 13
cts 13
cp 1
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 9 2
A __construct() 0 5 1
A __toString() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin\SqlParser\Components;
6
7
use PhpMyAdmin\SqlParser\Component;
8
use PhpMyAdmin\SqlParser\Context;
9
10
use function trim;
11
12
/**
13
 * The definition of a parameter of a function or procedure.
14
 */
15
final class ParameterDefinition implements Component
16
{
17
    /**
18
     * The name of the new column.
19
     */
20
    public string|null $name = null;
21
22
    /**
23
     * Parameter's direction (IN, OUT or INOUT).
24
     */
25
    public string|null $inOut = null;
26
27
    /**
28
     * The data type of thew new column.
29
     */
30
    public DataType|null $type = null;
31
32
    /**
33
     * @param string|null   $name  parameter's name
34
     * @param string|null   $inOut parameter's directional type (IN / OUT or None)
35
     * @param DataType|null $type  parameter's type
36
     */
37 52
    public function __construct(string|null $name = null, string|null $inOut = null, DataType|null $type = null)
38
    {
39 52
        $this->name = $name;
40 52
        $this->inOut = $inOut;
41 52
        $this->type = $type;
42
    }
43
44 6
    public function build(): string
45
    {
46 6
        $tmp = '';
47 6
        if (! empty($this->inOut)) {
48 4
            $tmp .= $this->inOut . ' ';
49
        }
50
51 6
        return trim(
52 6
            $tmp . Context::escape($this->name) . ' ' . $this->type,
0 ignored issues
show
Bug introduced by
It seems like $this->name can also be of type null; however, parameter $str of PhpMyAdmin\SqlParser\Context::escape() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

52
            $tmp . Context::escape(/** @scrutinizer ignore-type */ $this->name) . ' ' . $this->type,
Loading history...
53 6
        );
54
    }
55
56 6
    public function __toString(): string
57
    {
58 6
        return $this->build();
59
    }
60
}
61