25
25
*/
26
26
abstract class SQLFilter
27
27
{
28
- /**
29
- * The entity manager.
30
- *
31
- * @var EntityManagerInterface
32
- */
33
- private $ em ;
34
-
35
28
/**
36
29
* Parameters for the filter.
37
30
*
38
31
* @psalm-var array<string,array{type: string, value: mixed, is_list: bool}>
39
32
*/
40
- private $ parameters = [];
33
+ private array $ parameters = [];
41
34
42
- /**
43
- * @param EntityManagerInterface $em The entity manager.
44
- */
45
- final public function __construct (EntityManagerInterface $ em )
46
- {
47
- $ this ->em = $ em ;
35
+ final public function __construct (
36
+ private EntityManagerInterface $ em
37
+ ) {
48
38
}
49
39
50
40
/**
51
41
* Sets a parameter list that can be used by the filter.
52
42
*
53
- * @param string $name Name of the parameter.
54
43
* @param array<mixed> $values List of parameter values.
55
44
* @param string $type The parameter type. If specified, the given value will be run through
56
45
* the type conversion of this type.
57
46
*
58
47
* @return $this
59
48
*/
60
- final public function setParameterList (string $ name , array $ values , string $ type = Types::STRING ): self
49
+ final public function setParameterList (string $ name , array $ values , string $ type = Types::STRING ): static
61
50
{
62
51
$ this ->parameters [$ name ] = ['value ' => $ values , 'type ' => $ type , 'is_list ' => true ];
63
52
@@ -73,15 +62,13 @@ final public function setParameterList(string $name, array $values, string $type
73
62
/**
74
63
* Sets a parameter that can be used by the filter.
75
64
*
76
- * @param string $name Name of the parameter.
77
- * @param mixed $value Value of the parameter.
78
- * @param string|null $type The parameter type. If specified, the given value will be run through
79
- * the type conversion of this type. This is usually not needed for
80
- * strings and numeric types.
65
+ * @param string|null $type The parameter type. If specified, the given value will be run through
66
+ * the type conversion of this type. This is usually not needed for
67
+ * strings and numeric types.
81
68
*
82
69
* @return $this
83
70
*/
84
- final public function setParameter ($ name , $ value , $ type = null ): self
71
+ final public function setParameter (string $ name , mixed $ value , ? string $ type = null ): static
85
72
{
86
73
if ($ type === null ) {
87
74
$ type = ParameterTypeInferer::inferType ($ value );
@@ -104,13 +91,11 @@ final public function setParameter($name, $value, $type = null): self
104
91
* The function is responsible for the right output escaping to use the
105
92
* value in a query.
106
93
*
107
- * @param string $name Name of the parameter.
108
- *
109
94
* @return string The SQL escaped parameter to use in a query.
110
95
*
111
96
* @throws InvalidArgumentException
112
97
*/
113
- final public function getParameter ($ name )
98
+ final public function getParameter (string $ name ): string
114
99
{
115
100
if (! isset ($ this ->parameters [$ name ])) {
116
101
throw new InvalidArgumentException ("Parameter ' " . $ name . "' does not exist. " );
@@ -132,10 +117,6 @@ final public function getParameter($name)
132
117
* value in a query, separating each entry by comma to inline it into
133
118
* an IN() query part.
134
119
*
135
- * @param string $name Name of the parameter.
136
- *
137
- * @return string The SQL escaped parameter to use in a query.
138
- *
139
120
* @throws InvalidArgumentException
140
121
*/
141
122
final public function getParameterList (string $ name ): string
@@ -151,31 +132,26 @@ final public function getParameterList(string $name): string
151
132
$ param = $ this ->parameters [$ name ];
152
133
$ connection = $ this ->em ->getConnection ();
153
134
154
- $ quoted = array_map (static function ($ value ) use ($ connection , $ param ) {
155
- return $ connection ->quote ($ value , $ param ['type ' ]);
156
- }, $ param ['value ' ]);
135
+ $ quoted = array_map (
136
+ static fn (mixed $ value ): string => (string ) $ connection ->quote ($ value , $ param ['type ' ]),
137
+ $ param ['value ' ]
138
+ );
157
139
158
140
return implode (', ' , $ quoted );
159
141
}
160
142
161
143
/**
162
144
* Checks if a parameter was set for the filter.
163
- *
164
- * @param string $name Name of the parameter.
165
- *
166
- * @return bool
167
145
*/
168
- final public function hasParameter ($ name )
146
+ final public function hasParameter (string $ name ): bool
169
147
{
170
148
return isset ($ this ->parameters [$ name ]);
171
149
}
172
150
173
151
/**
174
152
* Returns as string representation of the SQLFilter parameters (the state).
175
- *
176
- * @return string String representation of the SQLFilter.
177
153
*/
178
- final public function __toString ()
154
+ final public function __toString (): string
179
155
{
180
156
return serialize ($ this ->parameters );
181
157
}
@@ -191,10 +167,9 @@ final protected function getConnection(): Connection
191
167
/**
192
168
* Gets the SQL query part to add to a query.
193
169
*
194
- * @param string $targetTableAlias
195
170
* @psalm-param ClassMetadata<object> $targetEntity
196
171
*
197
172
* @return string The constraint SQL if there is available, empty string otherwise.
198
173
*/
199
- abstract public function addFilterConstraint (ClassMetadata $ targetEntity , $ targetTableAlias );
174
+ abstract public function addFilterConstraint (ClassMetadata $ targetEntity , string $ targetTableAlias ): string ;
200
175
}
0 commit comments