Passed
Pull Request — master (#535)
by
unknown
02:58
created

ParameterDefinition::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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
     * @var string
21
     */
22
    public $name;
23
24
    /**
25
     * Parameter's direction (IN, OUT or INOUT).
26
     *
27
     * @var string
28
     */
29
    public $inOut;
30
31
    /**
32
     * The data type of thew new column.
33
     *
34
     * @var DataType
35
     */
36
    public $type;
37
38
    /**
39
     * @param string   $name  parameter's name
40
     * @param string   $inOut parameter's directional type (IN / OUT or None)
41
     * @param DataType $type  parameter's type
42
     */
43 52
    public function __construct(string|null $name = null, string|null $inOut = null, DataType|null $type = null)
44
    {
45 52
        $this->name = $name;
46 52
        $this->inOut = $inOut;
47 52
        $this->type = $type;
48
    }
49
50 6
    public function build(): string
51
    {
52 6
        $tmp = '';
53 6
        if (! empty($this->inOut)) {
54 4
            $tmp .= $this->inOut . ' ';
55
        }
56
57 6
        return trim(
58 6
            $tmp . Context::escape($this->name) . ' ' . $this->type,
59 6
        );
60
    }
61
62 6
    public function __toString(): string
63
    {
64 6
        return $this->build();
65
    }
66
}
67