Skip to content

Commit 52887ca

Browse files
authored
[CS] native_function_invocation (#235)
* [CS] native_function_invocation * fixed psalm baseline
1 parent 8793ff5 commit 52887ca

13 files changed

+102
-103
lines changed

.php-cs-fixer.dist.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
return $config->setRules([
1212
'@Symfony' => true,
1313
'@Symfony:risky' => true,
14-
'array_syntax' => array('syntax' => 'short'),
15-
'native_function_invocation' => true,
14+
'native_function_invocation' => ['include'=> ['@all']],
1615
'native_constant_invocation' => true,
1716
'ordered_imports' => true,
1817
'declare_strict_types' => false,

psalm.baseline.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<files psalm-version="4.30.0@d0bc6e25d89f649e4f36a534f330f8bb4643dd69">
33
<file src="src/Stream.php">
44
<NoValue occurrences="1">
5-
<code>return trigger_error((string) $e, \E_USER_ERROR);</code>
5+
<code>return \trigger_error((string) $e, \E_USER_ERROR);</code>
66
</NoValue>
77
</file>
88
</files>

src/Factory/Psr17Factory.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ public function createStreamFromFile(string $filename, string $mode = 'r'): Stre
4141
throw new \RuntimeException('Path cannot be empty');
4242
}
4343

44-
if (false === $resource = @fopen($filename, $mode)) {
44+
if (false === $resource = @\fopen($filename, $mode)) {
4545
if ('' === $mode || false === \in_array($mode[0], ['r', 'w', 'a', 'x', 'c'], true)) {
46-
throw new \InvalidArgumentException(sprintf('The mode "%s" is invalid.', $mode));
46+
throw new \InvalidArgumentException(\sprintf('The mode "%s" is invalid.', $mode));
4747
}
4848

49-
throw new \RuntimeException(sprintf('The file "%s" cannot be opened: %s', $filename, error_get_last()['message'] ?? ''));
49+
throw new \RuntimeException(\sprintf('The file "%s" cannot be opened: %s', $filename, \error_get_last()['message'] ?? ''));
5050
}
5151

5252
return Stream::create($resource);

src/MessageTrait.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function getHeaders(): array
5757

5858
public function hasHeader($header): bool
5959
{
60-
return isset($this->headerNames[strtr($header, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')]);
60+
return isset($this->headerNames[\strtr($header, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')]);
6161
}
6262

6363
public function getHeader($header): array
@@ -66,7 +66,7 @@ public function getHeader($header): array
6666
throw new \InvalidArgumentException('Header name must be an RFC 7230 compatible string');
6767
}
6868

69-
$header = strtr($header, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz');
69+
$header = \strtr($header, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz');
7070
if (!isset($this->headerNames[$header])) {
7171
return [];
7272
}
@@ -78,13 +78,13 @@ public function getHeader($header): array
7878

7979
public function getHeaderLine($header): string
8080
{
81-
return implode(', ', $this->getHeader($header));
81+
return \implode(', ', $this->getHeader($header));
8282
}
8383

8484
public function withHeader($header, $value): self
8585
{
8686
$value = $this->validateAndTrimHeader($header, $value);
87-
$normalized = strtr($header, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz');
87+
$normalized = \strtr($header, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz');
8888

8989
$new = clone $this;
9090
if (isset($new->headerNames[$normalized])) {
@@ -114,7 +114,7 @@ public function withoutHeader($header): self
114114
throw new \InvalidArgumentException('Header name must be an RFC 7230 compatible string');
115115
}
116116

117-
$normalized = strtr($header, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz');
117+
$normalized = \strtr($header, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz');
118118
if (!isset($this->headerNames[$normalized])) {
119119
return $this;
120120
}
@@ -156,10 +156,10 @@ private function setHeaders(array $headers): void
156156
$header = (string) $header;
157157
}
158158
$value = $this->validateAndTrimHeader($header, $value);
159-
$normalized = strtr($header, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz');
159+
$normalized = \strtr($header, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz');
160160
if (isset($this->headerNames[$normalized])) {
161161
$header = $this->headerNames[$normalized];
162-
$this->headers[$header] = array_merge($this->headers[$header], $value);
162+
$this->headers[$header] = \array_merge($this->headers[$header], $value);
163163
} else {
164164
$this->headerNames[$normalized] = $header;
165165
$this->headers[$header] = $value;
@@ -187,17 +187,17 @@ private function setHeaders(array $headers): void
187187
*/
188188
private function validateAndTrimHeader($header, $values): array
189189
{
190-
if (!\is_string($header) || 1 !== preg_match("@^[!#$%&'*+.^_`|~0-9A-Za-z-]+$@", $header)) {
190+
if (!\is_string($header) || 1 !== \preg_match("@^[!#$%&'*+.^_`|~0-9A-Za-z-]+$@", $header)) {
191191
throw new \InvalidArgumentException('Header name must be an RFC 7230 compatible string');
192192
}
193193

194194
if (!\is_array($values)) {
195195
// This is simple, just one value.
196-
if ((!is_numeric($values) && !\is_string($values)) || 1 !== preg_match("@^[ \t\x21-\x7E\x80-\xFF]*$@", (string) $values)) {
196+
if ((!\is_numeric($values) && !\is_string($values)) || 1 !== \preg_match("@^[ \t\x21-\x7E\x80-\xFF]*$@", (string) $values)) {
197197
throw new \InvalidArgumentException('Header values must be RFC 7230 compatible strings');
198198
}
199199

200-
return [trim((string) $values, " \t")];
200+
return [\trim((string) $values, " \t")];
201201
}
202202

203203
if (empty($values)) {
@@ -207,11 +207,11 @@ private function validateAndTrimHeader($header, $values): array
207207
// Assert Non empty array
208208
$returnValues = [];
209209
foreach ($values as $v) {
210-
if ((!is_numeric($v) && !\is_string($v)) || 1 !== preg_match("@^[ \t\x21-\x7E\x80-\xFF]*$@", (string) $v)) {
210+
if ((!\is_numeric($v) && !\is_string($v)) || 1 !== \preg_match("@^[ \t\x21-\x7E\x80-\xFF]*$@", (string) $v)) {
211211
throw new \InvalidArgumentException('Header values must be RFC 7230 compatible strings');
212212
}
213213

214-
$returnValues[] = trim((string) $v, " \t");
214+
$returnValues[] = \trim((string) $v, " \t");
215215
}
216216

217217
return $returnValues;

src/RequestTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function withRequestTarget($requestTarget): self
4646
throw new \InvalidArgumentException('Request target must be a string');
4747
}
4848

49-
if (preg_match('#\s#', $requestTarget)) {
49+
if (\preg_match('#\s#', $requestTarget)) {
5050
throw new \InvalidArgumentException('Invalid request target provided; cannot contain whitespace');
5151
}
5252

src/Response.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function withStatus($code, $reasonPhrase = ''): self
7575

7676
$code = (int) $code;
7777
if ($code < 100 || $code > 599) {
78-
throw new \InvalidArgumentException(sprintf('Status code has to be an integer between 100 and 599. A status code of %d was given', $code));
78+
throw new \InvalidArgumentException(\sprintf('Status code has to be an integer between 100 and 599. A status code of %d was given', $code));
7979
}
8080

8181
$new = clone $this;

src/ServerRequest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function __construct(string $method, $uri, array $headers = [], $body = n
5656
$this->uri = $uri;
5757
$this->setHeaders($headers);
5858
$this->protocol = $version;
59-
parse_str($uri->getQuery(), $this->queryParams);
59+
\parse_str($uri->getQuery(), $this->queryParams);
6060

6161
if (!$this->hasHeader('Host')) {
6262
$this->updateHostFromUri();

src/Stream.php

+23-23
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public function __construct($body)
6161
}
6262

6363
$this->stream = $body;
64-
$meta = stream_get_meta_data($this->stream);
65-
$this->seekable = $meta['seekable'] && 0 === fseek($this->stream, 0, \SEEK_CUR);
64+
$meta = \stream_get_meta_data($this->stream);
65+
$this->seekable = $meta['seekable'] && 0 === \fseek($this->stream, 0, \SEEK_CUR);
6666
$this->readable = isset(self::READ_WRITE_HASH['read'][$meta['mode']]);
6767
$this->writable = isset(self::READ_WRITE_HASH['write'][$meta['mode']]);
6868
}
@@ -81,9 +81,9 @@ public static function create($body = ''): StreamInterface
8181
}
8282

8383
if (\is_string($body)) {
84-
$resource = fopen('php://temp', 'rw+');
85-
fwrite($resource, $body);
86-
fseek($resource, 0);
84+
$resource = \fopen('php://temp', 'rw+');
85+
\fwrite($resource, $body);
86+
\fseek($resource, 0);
8787
$body = $resource;
8888
}
8989

@@ -118,13 +118,13 @@ public function __toString()
118118
throw $e;
119119
}
120120

121-
if (\is_array($errorHandler = set_error_handler('var_dump'))) {
121+
if (\is_array($errorHandler = \set_error_handler('var_dump'))) {
122122
$errorHandler = $errorHandler[0] ?? null;
123123
}
124-
restore_error_handler();
124+
\restore_error_handler();
125125

126126
if ($e instanceof \Error || $errorHandler instanceof SymfonyErrorHandler || $errorHandler instanceof SymfonyLegacyErrorHandler) {
127-
return trigger_error((string) $e, \E_USER_ERROR);
127+
return \trigger_error((string) $e, \E_USER_ERROR);
128128
}
129129

130130
return '';
@@ -135,7 +135,7 @@ public function close(): void
135135
{
136136
if (isset($this->stream)) {
137137
if (\is_resource($this->stream)) {
138-
fclose($this->stream);
138+
\fclose($this->stream);
139139
}
140140
$this->detach();
141141
}
@@ -176,10 +176,10 @@ public function getSize(): ?int
176176

177177
// Clear the stat cache if the stream has a URI
178178
if ($uri = $this->getUri()) {
179-
clearstatcache(true, $uri);
179+
\clearstatcache(true, $uri);
180180
}
181181

182-
$stats = fstat($this->stream);
182+
$stats = \fstat($this->stream);
183183
if (isset($stats['size'])) {
184184
$this->size = $stats['size'];
185185

@@ -195,16 +195,16 @@ public function tell(): int
195195
throw new \RuntimeException('Stream is detached');
196196
}
197197

198-
if (false === $result = @ftell($this->stream)) {
199-
throw new \RuntimeException('Unable to determine stream position: ' . (error_get_last()['message'] ?? ''));
198+
if (false === $result = @\ftell($this->stream)) {
199+
throw new \RuntimeException('Unable to determine stream position: ' . (\error_get_last()['message'] ?? ''));
200200
}
201201

202202
return $result;
203203
}
204204

205205
public function eof(): bool
206206
{
207-
return !isset($this->stream) || feof($this->stream);
207+
return !isset($this->stream) || \feof($this->stream);
208208
}
209209

210210
public function isSeekable(): bool
@@ -222,8 +222,8 @@ public function seek($offset, $whence = \SEEK_SET): void
222222
throw new \RuntimeException('Stream is not seekable');
223223
}
224224

225-
if (-1 === fseek($this->stream, $offset, $whence)) {
226-
throw new \RuntimeException('Unable to seek to stream position "' . $offset . '" with whence ' . var_export($whence, true));
225+
if (-1 === \fseek($this->stream, $offset, $whence)) {
226+
throw new \RuntimeException('Unable to seek to stream position "' . $offset . '" with whence ' . \var_export($whence, true));
227227
}
228228
}
229229

@@ -250,8 +250,8 @@ public function write($string): int
250250
// We can't know the size after writing anything
251251
$this->size = null;
252252

253-
if (false === $result = @fwrite($this->stream, $string)) {
254-
throw new \RuntimeException('Unable to write to stream: ' . (error_get_last()['message'] ?? ''));
253+
if (false === $result = @\fwrite($this->stream, $string)) {
254+
throw new \RuntimeException('Unable to write to stream: ' . (\error_get_last()['message'] ?? ''));
255255
}
256256

257257
return $result;
@@ -272,8 +272,8 @@ public function read($length): string
272272
throw new \RuntimeException('Cannot read from non-readable stream');
273273
}
274274

275-
if (false === $result = @fread($this->stream, $length)) {
276-
throw new \RuntimeException('Unable to read from stream: ' . (error_get_last()['message'] ?? ''));
275+
if (false === $result = @\fread($this->stream, $length)) {
276+
throw new \RuntimeException('Unable to read from stream: ' . (\error_get_last()['message'] ?? ''));
277277
}
278278

279279
return $result;
@@ -285,8 +285,8 @@ public function getContents(): string
285285
throw new \RuntimeException('Stream is detached');
286286
}
287287

288-
if (false === $contents = @stream_get_contents($this->stream)) {
289-
throw new \RuntimeException('Unable to read stream contents: ' . (error_get_last()['message'] ?? ''));
288+
if (false === $contents = @\stream_get_contents($this->stream)) {
289+
throw new \RuntimeException('Unable to read stream contents: ' . (\error_get_last()['message'] ?? ''));
290290
}
291291

292292
return $contents;
@@ -305,7 +305,7 @@ public function getMetadata($key = null)
305305
return $key ? null : [];
306306
}
307307

308-
$meta = stream_get_meta_data($this->stream);
308+
$meta = \stream_get_meta_data($this->stream);
309309

310310
if (null === $key) {
311311
return $meta;

src/UploadedFile.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ public function getStream(): StreamInterface
114114
return $this->stream;
115115
}
116116

117-
if (false === $resource = @fopen($this->file, 'r')) {
118-
throw new \RuntimeException(sprintf('The file "%s" cannot be opened: %s', $this->file, error_get_last()['message'] ?? ''));
117+
if (false === $resource = @\fopen($this->file, 'r')) {
118+
throw new \RuntimeException(\sprintf('The file "%s" cannot be opened: %s', $this->file, \error_get_last()['message'] ?? ''));
119119
}
120120

121121
return Stream::create($resource);
@@ -130,19 +130,19 @@ public function moveTo($targetPath): void
130130
}
131131

132132
if (null !== $this->file) {
133-
$this->moved = 'cli' === \PHP_SAPI ? @rename($this->file, $targetPath) : @move_uploaded_file($this->file, $targetPath);
133+
$this->moved = 'cli' === \PHP_SAPI ? @\rename($this->file, $targetPath) : @\move_uploaded_file($this->file, $targetPath);
134134

135135
if (false === $this->moved) {
136-
throw new \RuntimeException(sprintf('Uploaded file could not be moved to "%s": %s', $targetPath, error_get_last()['message'] ?? ''));
136+
throw new \RuntimeException(\sprintf('Uploaded file could not be moved to "%s": %s', $targetPath, \error_get_last()['message'] ?? ''));
137137
}
138138
} else {
139139
$stream = $this->getStream();
140140
if ($stream->isSeekable()) {
141141
$stream->rewind();
142142
}
143143

144-
if (false === $resource = @fopen($targetPath, 'w')) {
145-
throw new \RuntimeException(sprintf('The file "%s" cannot be opened: %s', $targetPath, error_get_last()['message'] ?? ''));
144+
if (false === $resource = @\fopen($targetPath, 'w')) {
145+
throw new \RuntimeException(\sprintf('The file "%s" cannot be opened: %s', $targetPath, \error_get_last()['message'] ?? ''));
146146
}
147147

148148
$dest = Stream::create($resource);

0 commit comments

Comments
 (0)