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

ParameterDefinition::parse()   D

Complexity

Conditions 19
Paths 8

Size

Total Lines 77
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 37
CRAP Score 19

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 19
eloc 37
c 1
b 0
f 0
nc 8
nop 3
dl 0
loc 77
ccs 37
cts 37
cp 1
crap 19
rs 4.5166

1 Method

Rating   Name   Duplication   Size   Complexity  
A ParameterDefinition::__toString() 0 3 1

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
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