Completed
Pull Request — master (#8107)
by
unknown
63:20
created

Parameter::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ORM\Query;
6
7
use function trim;
8
9
/**
10
 * Defines a Query Parameter.
11
 */
12
class Parameter
13
{
14
    /**
15
     * Returns the internal representation of a parameter name.
16
     *
17
     * @param string|int $name The parameter name or position.
18
     *
19
     * @return string The normalized parameter name.
20
     */
21
    public static function normalizeName($name)
22
    {
23
        return trim((string) $name, ':');
24
    }
25
26
    /**
27
     * The parameter name.
28
     *
29
     * @var string
30
     */
31
    private $name;
32
33
    /**
34
     * The parameter value.
35
     *
36
     * @var mixed
37
     */
38
    private $value;
39
40
    /**
41
     * The parameter type.
42
     *
43
     * @var mixed
44
     */
45
    private $type;
46
47 236
    /**
48
     * Whether the parameter type was explicitly specified or not
49 236
     *
50 236
     * @var bool
51
     */
52 236
    private $typeSpecified;
53 236
54
    /**
55
     * @param string $name  Parameter name
56
     * @param mixed  $value Parameter value
57
     * @param mixed  $type  Parameter type
58
     */
59
    public function __construct($name, $value, $type = null)
60 214
    {
61
        $this->name          = self::normalizeName($name);
62 214
        $this->typeSpecified = $type !== null;
63
64
        $this->setValue($value, $type);
65
    }
66
67
    /**
68
     * Retrieves the Parameter name.
69
     *
70 196
     * @return string
71
     */
72 196
    public function getName()
73
    {
74
        return $this->name;
75
    }
76
77
    /**
78
     * Retrieves the Parameter value.
79
     *
80 193
     * @return mixed
81
     */
82 193
    public function getValue()
83
    {
84
        return $this->value;
85
    }
86
87
    /**
88
     * Retrieves the Parameter type.
89
     *
90
     * @return mixed
91 238
     */
92
    public function getType()
93 238
    {
94 238
        return $this->type;
95 238
    }
96
97 165
    /**
98
     * Defines the Parameter value.
99 165
     *
100
     * @param mixed $value Parameter value.
101
     * @param mixed $type  Parameter type.
102
     */
103
    public function setValue($value, $type = null)
104
    {
105
        $this->value = $value;
106
        $this->type  = $type ?: ParameterTypeInferer::inferType($value);
107
    }
108
109
    public function typeWasSpecified() : bool
110
    {
111
        return $this->typeSpecified;
112
    }
113
}
114