Skip to content

Commit 9bc4ad5

Browse files
committed
Merge branch '2.x' into 3.x
* 2.x: Use short-array syntax for lists 1.x tweaks
2 parents f8eb0e8 + a2c1392 commit 9bc4ad5

File tree

10 files changed

+28
-24
lines changed

10 files changed

+28
-24
lines changed

src/HttpFactory/Factory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function createStreamFromFile(string $filename, string $mode = 'r'): Stre
130130
$resource = \fopen($filename, $mode);
131131
\restore_error_handler();
132132
if ($resource === false) {
133-
if ($mode === '' || \in_array($mode[0], array('r', 'w', 'a', 'x', 'c'), true) === false) {
133+
if ($mode === '' || \in_array($mode[0], ['r', 'w', 'a', 'x', 'c'], true) === false) {
134134
throw new InvalidArgumentException('The mode "' . $mode . '" is invalid.');
135135
}
136136
throw new RuntimeException(\sprintf(

src/HttpMessage/AbstractUri.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ abstract class AbstractUri
5959
protected function assertHost($host): void
6060
{
6161
$this->assertString($host, 'host');
62-
if (\in_array($host, array('', 'localhost'), true)) {
62+
if (\in_array($host, ['', 'localhost'], true)) {
6363
// An empty host value is equivalent to removing the host.
6464
// No validation required
6565
return;

src/HttpMessage/AssertionTrait.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,38 @@ trait AssertionTrait
2727
*
2828
* @var numeric-string[]
2929
*/
30-
protected array $validProtocolVers = array(
30+
protected $validProtocolVers = array(
3131
'0.9',
3232
'1.0',
3333
'1.1',
3434
'2',
3535
'2.0',
3636
'3',
3737
'3.0',
38-
);
38+
];
3939

4040
/**
4141
* Test that value is a string (or optionally numeric)
4242
*
4343
* @param mixed $value The value to check.
4444
* @param string $what The name of the value.
4545
* @param bool $allowNumeric Allow float or int?
46+
* @param bool $allowNull Allow null?
4647
*
4748
* @return void
4849
*
4950
* @throws InvalidArgumentException
5051
*
5152
* @psalm-assert string $value
5253
*/
53-
protected function assertString($value, string $what = '', bool $allowNumeric = false): void
54+
protected function assertString($value, string $what = '', bool $allowNumeric = false, $allowNull = false): void
5455
{
5556
if (\is_string($value)) {
5657
return;
5758
}
59+
if ($allowNull && $value === null) {
60+
return;
61+
}
5862
if ($allowNumeric && \is_numeric($value)) {
5963
return;
6064
}
@@ -126,7 +130,7 @@ private function assertHeaderName($name): void
126130
private function assertHeaderValue($value): void
127131
{
128132
if (\is_scalar($value) && \is_bool($value) === false) {
129-
$value = array((string) $value);
133+
$value = [(string) $value];
130134
}
131135
if (\is_array($value) === false) {
132136
throw new InvalidArgumentException(\sprintf(
@@ -443,7 +447,7 @@ protected function assertStatusCode($code): void
443447
*/
444448
private function iteratorPath(RecursiveIteratorIterator $iterator): string
445449
{
446-
$path = array();
450+
$path = [];
447451
for ($i = 0, $depth = $iterator->getDepth(); $i <= $depth; $i++) {
448452
$key = $iterator->getSubIterator($i)->key();
449453
$path[] = $i > 0

src/HttpMessage/Message.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function getHeader(string $name): array
127127
{
128128
$nameLower = \strtolower($name);
129129
if (!isset($this->headerNames[$nameLower])) {
130-
return array();
130+
return [];
131131
}
132132
$name = $this->headerNames[$nameLower];
133133
return $this->headers[$name];

src/HttpMessage/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,6 @@ private function filterCodePhrase($code, $phrase)
130130
$phrase = ResponseUtil::codePhrase($code);
131131
}
132132
$this->assertReasonPhrase($phrase);
133-
return array($code, $phrase);
133+
return [$code, $phrase];
134134
}
135135
}

src/HttpMessage/ServerRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ public function __construct(string $method = 'GET', $uri = '', array $serverPara
127127
? $parsed
128128
: null;
129129
});
130-
$this->registerMediaTypeParser(ContentType::XML_APP, array(__CLASS__, 'parseXml'));
131-
$this->registerMediaTypeParser(ContentType::XML, array(__CLASS__, 'parseXml'));
130+
$this->registerMediaTypeParser(ContentType::XML_APP, [__CLASS__, 'parseXml']);
131+
$this->registerMediaTypeParser(ContentType::XML, [__CLASS__, 'parseXml']);
132132
}
133133

134134
/**

src/HttpMessage/ServerRequestExtended.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function getMediaTypeParams(): array
8787
'charset' => null,
8888
);
8989

90-
if ($contentType === array()) {
90+
if ($contentType === []) {
9191
return $params;
9292
}
9393

src/HttpMessage/Uri.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,11 @@ public function withScheme(string $scheme): static
311311
*/
312312
public function withUserInfo(string $user, ?string $password = null): static
313313
{
314-
$this->assertString($user, 'user');
314+
$this->assertString($user, 'user', true);
315+
$this->assertString($password, 'password', true, true);
315316
$userInfo = (string) $user; // for versions without type hint in method signature
316317
$password = (string) $password; // for versions without type hint in method signature
317318
if ($userInfo !== '' && $password !== '') {
318-
$this->assertString($password, 'password');
319319
$userInfo .= ':' . $password;
320320
}
321321
if ($userInfo === $this->userInfo) {
@@ -417,7 +417,7 @@ public function withPath(string $path): static
417417
*/
418418
public function withQuery(string $query): static
419419
{
420-
$this->assertString($query, 'query');
420+
$this->assertString($query, 'query', true);
421421
$query = $this->filterQueryAndFragment($query);
422422
if ($query === $this->query) {
423423
return $this;

src/HttpMessage/Utility/ServerRequest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static function fromGlobals($parseStrOpts = array()): ServerRequestExtend
7777
*
7878
* @throws InvalidArgumentException
7979
*/
80-
private static function filesFromGlobals(array $phpFiles, array $path = array()): array
80+
private static function filesFromGlobals(array $phpFiles, array $path = []): array
8181
{
8282
$files = array();
8383
/** @var mixed $value */
@@ -179,15 +179,15 @@ private static function fileFromGlobalCreate(array $fileInfo)
179179
*/
180180
private static function isUploadFileInfoArray(array $array): bool
181181
{
182-
$keysMustHave = array('name', 'type', 'tmp_name', 'size', 'error');
183-
$keysMayHave = array('full_path');
182+
$keysMustHave = ['name', 'type', 'tmp_name', 'size', 'error'];
183+
$keysMayHave = ['full_path'];
184184
$keys = \array_keys($array);
185185
if (\array_intersect($keysMustHave, $keys) !== $keysMustHave) {
186186
// missing must have
187187
return false;
188188
}
189189
// return true if no unknown keys
190-
return \array_diff($keys, \array_merge($keysMustHave, $keysMayHave)) === array();
190+
return \array_diff($keys, \array_merge($keysMustHave, $keysMayHave)) === [];
191191
}
192192

193193
/**

src/HttpMessage/Utility/Uri.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ public static function fromParsed(array $parsed): BdkUri
6262
$uriKeys = ['fragment', 'host', 'path', 'port', 'query', 'scheme', 'userInfo'];
6363
$parsed = \array_intersect_key(self::parsedPartsPrep($parsed), \array_flip($uriKeys));
6464
$parsed = \array_filter($parsed, static function ($val) {
65-
return \in_array($val, array(null, ''), true) === false;
65+
return \in_array($val, [null, ''], true) === false;
6666
});
6767
$uri = new BdkUri();
6868
foreach ($parsed as $key => $value) {
6969
$method = 'with' . \ucfirst($key);
7070
/** @var BdkUri */
71-
$uri = \call_user_func_array(array($uri, $method), (array) $value);
71+
$uri = \call_user_func_array([$uri, $method], (array) $value);
7272
}
7373
return $uri;
7474
}
@@ -199,7 +199,7 @@ private static function parsedPartsPrep(array $parsed): array
199199
'user' => '',
200200
), $renamed, $parsed);
201201
if (\array_key_exists('userInfo', $parsed) === false) {
202-
$parsed['userInfo'] = array($parsed['user'], $parsed['pass']);
202+
$parsed['userInfo'] = [$parsed['user'], $parsed['pass']];
203203
}
204204
if (\is_array($parsed['userInfo']) === false) {
205205
$parsed['userInfo'] = \explode(':', (string) $parsed['userInfo'], 2);
@@ -282,7 +282,7 @@ private static function pathRemoveDots(string $path): string
282282
if ($path[0] === '/' && (!isset($pathNew[0]) || $pathNew[0] !== '/')) {
283283
// Re-add the leading slash if necessary for cases like "/.."
284284
$pathNew = '/' . $pathNew;
285-
} elseif ($pathNew !== '' && \in_array(\end($segments), array('.', '..'), true)) {
285+
} elseif ($pathNew !== '' && \in_array(\end($segments), ['.', '..'], true)) {
286286
// Add the trailing slash if necessary
287287
$pathNew .= '/';
288288
}
@@ -342,7 +342,7 @@ private static function resolveTargetPath(UriInterface $base, UriInterface $rel)
342342
*/
343343
private static function uriInterfaceToParts(UriInterface $url): array
344344
{
345-
$userInfo = \array_replace(array(null, null), \explode(':', $url->getUserInfo(), 2));
345+
$userInfo = \array_replace([null, null], \explode(':', $url->getUserInfo(), 2));
346346
$parts = array(
347347
'pass' => $userInfo[1],
348348
'user' => $userInfo[0],

0 commit comments

Comments
 (0)