@@ -66,7 +66,7 @@ public function __construct(
66
66
?int $ port ,
67
67
?string $ path ,
68
68
?string $ queryString ,
69
- array $ query
69
+ array $ query,
70
70
) {
71
71
$ this ->scheme = $ scheme ;
72
72
$ this ->schemeProtocol = $ schemeProtocol ;
@@ -140,27 +140,27 @@ public function getQuery(): array
140
140
return $ this ->queryBag ->toArray ();
141
141
}
142
142
143
- public function getString (string $ name , string $ default = null ): ?string
143
+ public function getString (string $ name , ? string $ default = null ): ?string
144
144
{
145
145
return $ this ->queryBag ->getString ($ name , $ default );
146
146
}
147
147
148
- public function getDecimal (string $ name , int $ default = null ): ?int
148
+ public function getDecimal (string $ name , ? int $ default = null ): ?int
149
149
{
150
150
return $ this ->queryBag ->getDecimal ($ name , $ default );
151
151
}
152
152
153
- public function getOctal (string $ name , int $ default = null ): ?int
153
+ public function getOctal (string $ name , ? int $ default = null ): ?int
154
154
{
155
155
return $ this ->queryBag ->getOctal ($ name , $ default );
156
156
}
157
157
158
- public function getFloat (string $ name , float $ default = null ): ?float
158
+ public function getFloat (string $ name , ? float $ default = null ): ?float
159
159
{
160
160
return $ this ->queryBag ->getFloat ($ name , $ default );
161
161
}
162
162
163
- public function getBool (string $ name , bool $ default = null ): ?bool
163
+ public function getBool (string $ name , ? bool $ default = null ): ?bool
164
164
{
165
165
return $ this ->queryBag ->getBool ($ name , $ default );
166
166
}
@@ -192,14 +192,12 @@ public static function parseFirst(string $dsn): ?self
192
192
}
193
193
194
194
/**
195
- * @param string $dsn
196
- *
197
195
* @return Dsn[]
198
196
*/
199
197
public static function parse (string $ dsn ): array
200
198
{
201
- if (false === strpos ($ dsn , ': ' )) {
202
- throw new \LogicException (sprintf ( 'The DSN is invalid. It does not have scheme separator ":". ' ) );
199
+ if (! str_contains ($ dsn , ': ' )) {
200
+ throw new \LogicException ('The DSN is invalid. It does not have scheme separator ":". ' );
203
201
}
204
202
205
203
list ($ scheme , $ dsnWithoutScheme ) = explode (': ' , $ dsn , 2 );
@@ -215,28 +213,28 @@ public static function parse(string $dsn): array
215
213
unset($ schemeParts [0 ]);
216
214
$ schemeExtensions = array_values ($ schemeParts );
217
215
218
- $ user = parse_url ($ dsn , PHP_URL_USER ) ?: null ;
216
+ $ user = parse_url ($ dsn , \ PHP_URL_USER ) ?: null ;
219
217
if (is_string ($ user )) {
220
218
$ user = rawurldecode ($ user );
221
219
}
222
220
223
- $ password = parse_url ($ dsn , PHP_URL_PASS ) ?: null ;
221
+ $ password = parse_url ($ dsn , \ PHP_URL_PASS ) ?: null ;
224
222
if (is_string ($ password )) {
225
223
$ password = rawurldecode ($ password );
226
224
}
227
225
228
- $ path = parse_url ($ dsn , PHP_URL_PATH ) ?: null ;
226
+ $ path = parse_url ($ dsn , \ PHP_URL_PATH ) ?: null ;
229
227
if ($ path ) {
230
228
$ path = rawurldecode ($ path );
231
229
}
232
230
233
231
$ query = [];
234
- $ queryString = parse_url ($ dsn , PHP_URL_QUERY ) ?: null ;
232
+ $ queryString = parse_url ($ dsn , \ PHP_URL_QUERY ) ?: null ;
235
233
if (is_string ($ queryString )) {
236
- $ query = self ::httpParseQuery ($ queryString , '& ' , PHP_QUERY_RFC3986 );
234
+ $ query = self ::httpParseQuery ($ queryString , '& ' , \ PHP_QUERY_RFC3986 );
237
235
}
238
236
$ hostsPorts = '' ;
239
- if (0 === strpos ($ dsnWithoutScheme , '// ' )) {
237
+ if (str_starts_with ($ dsnWithoutScheme , '// ' )) {
240
238
$ dsnWithoutScheme = substr ($ dsnWithoutScheme , 2 );
241
239
$ dsnWithoutUserPassword = explode ('@ ' , $ dsnWithoutScheme , 2 );
242
240
$ dsnWithoutUserPassword = 2 === count ($ dsnWithoutUserPassword ) ?
@@ -299,7 +297,7 @@ public static function parse(string $dsn): array
299
297
/**
300
298
* based on http://php.net/manual/en/function.parse-str.php#119484 with some slight modifications.
301
299
*/
302
- private static function httpParseQuery (string $ queryString , string $ argSeparator = '& ' , int $ decType = PHP_QUERY_RFC1738 ): array
300
+ private static function httpParseQuery (string $ queryString , string $ argSeparator = '& ' , int $ decType = \ PHP_QUERY_RFC1738 ): array
303
301
{
304
302
$ result = [];
305
303
$ parts = explode ($ argSeparator , $ queryString );
@@ -308,11 +306,11 @@ private static function httpParseQuery(string $queryString, string $argSeparator
308
306
list ($ paramName , $ paramValue ) = explode ('= ' , $ part , 2 );
309
307
310
308
switch ($ decType ) {
311
- case PHP_QUERY_RFC3986 :
309
+ case \ PHP_QUERY_RFC3986 :
312
310
$ paramName = rawurldecode ($ paramName );
313
311
$ paramValue = rawurldecode ($ paramValue );
314
312
break ;
315
- case PHP_QUERY_RFC1738 :
313
+ case \ PHP_QUERY_RFC1738 :
316
314
default :
317
315
$ paramName = urldecode ($ paramName );
318
316
$ paramValue = urldecode ($ paramValue );
0 commit comments