From 69cd602d1d8358513b9b178ca5dcca8032c0fa87 Mon Sep 17 00:00:00 2001 From: devanych Date: Tue, 25 Aug 2020 12:03:09 +0300 Subject: [PATCH] Fix psalm config move from psalm.xml to docBlock --- psalm.xml | 11 ----------- src/MessageTrait.php | 10 ++++++++-- src/RequestTrait.php | 3 +++ src/ResponseTrait.php | 7 ++++++- src/ServerRequest.php | 3 +++ src/StreamFactory.php | 2 ++ src/StreamTrait.php | 4 ++++ src/UploadedFile.php | 6 ++++++ src/Uri.php | 3 +++ 9 files changed, 35 insertions(+), 14 deletions(-) diff --git a/psalm.xml b/psalm.xml index a685c85..a70a5b6 100644 --- a/psalm.xml +++ b/psalm.xml @@ -14,17 +14,6 @@ - - - - - - - - - - - diff --git a/src/MessageTrait.php b/src/MessageTrait.php index 2ba4c50..d5851b3 100644 --- a/src/MessageTrait.php +++ b/src/MessageTrait.php @@ -128,6 +128,7 @@ public function getHeaders(): array * @return bool Returns true if any header names match the given header * name using a case-insensitive string comparison. Returns false if * no matching header name is found in the message. + * @psalm-suppress RedundantConditionGivenDocblockType */ public function hasHeader($name): bool { @@ -199,6 +200,7 @@ public function getHeaderLine($name): string * @param string|string[] $value Header value(s). * @return static * @throws InvalidArgumentException for invalid header names or values. + * @psalm-suppress MixedPropertyTypeCoercion */ public function withHeader($name, $value): MessageInterface { @@ -233,6 +235,7 @@ public function withHeader($name, $value): MessageInterface * @param string|string[] $value Header value(s). * @return static * @throws InvalidArgumentException for invalid header names or values. + * @psalm-suppress MixedPropertyTypeCoercion */ public function withAddedHeader($name, $value): MessageInterface { @@ -308,6 +311,7 @@ public function withBody(StreamInterface $body): MessageInterface /** * @param StreamInterface|string|resource $stream * @param string $mode + * @psalm-suppress RedundantConditionGivenDocblockType */ private function registerStream($stream, string $mode = 'wb+'): void { @@ -329,8 +333,9 @@ private function registerStream($stream, string $mode = 'wb+'): void } /** - * @param array $originalHeaders + * @param array $originalHeaders * @throws InvalidArgumentException When the header name or header value is not valid. + * @psalm-suppress MixedPropertyTypeCoercion */ private function registerHeaders(array $originalHeaders = []): void { @@ -393,6 +398,7 @@ private function validateHeaderName($name): void /** * @param mixed $value * @throws InvalidArgumentException for invalid header value. + * @psalm-suppress MixedAssignment */ private function validateHeaderValue($value): void { @@ -415,7 +421,7 @@ private function validateHeaderValue($value): void } /** - * @param string $protocol + * @param mixed $protocol * @throws InvalidArgumentException for invalid HTTP protocol version. */ private function validateProtocolVersion($protocol): void diff --git a/src/RequestTrait.php b/src/RequestTrait.php index 21e7688..1e13285 100644 --- a/src/RequestTrait.php +++ b/src/RequestTrait.php @@ -130,6 +130,7 @@ public function getMethod(): string * @param string $method Case-sensitive method. * @return static * @throws InvalidArgumentException for invalid HTTP methods. + * @psalm-suppress DocblockTypeContradiction */ public function withMethod($method): RequestInterface { @@ -216,6 +217,7 @@ public function withUri(UriInterface $uri, $preserveHost = false): RequestInterf * @param array $headers * @param StreamInterface|string|resource $body * @param string $protocol + * @psalm-suppress MixedArgumentTypeCoercion */ private function init( string $method = 'GET', @@ -239,6 +241,7 @@ private function init( /** * @param UriInterface|string $uri * @throws InvalidArgumentException for invalid URI. + * @psalm-suppress RedundantConditionGivenDocblockType */ private function setUri($uri): void { diff --git a/src/ResponseTrait.php b/src/ResponseTrait.php index 4435cca..ef66375 100644 --- a/src/ResponseTrait.php +++ b/src/ResponseTrait.php @@ -30,7 +30,7 @@ trait ResponseTrait * Map of standard HTTP status code and reason phrases. * * @link https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml - * @var array + * @var array */ private static array $phrases = [ // Informational 1xx @@ -144,6 +144,9 @@ public function getStatusCode(): int * use the defaults as suggested in the HTTP specification. * @return static * @throws InvalidArgumentException for invalid status code arguments. + * @psalm-suppress DocblockTypeContradiction + * @psalm-suppress TypeDoesNotContainType + * @psalm-suppress RedundantCondition */ public function withStatus($code, $reasonPhrase = ''): ResponseInterface { @@ -181,6 +184,7 @@ public function withStatus($code, $reasonPhrase = ''): ResponseInterface * @link http://tools.ietf.org/html/rfc7231#section-6 * @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml * @return string Reason phrase; must return an empty string if none present. + * @psalm-suppress RedundantCondition */ public function getReasonPhrase(): string { @@ -193,6 +197,7 @@ public function getReasonPhrase(): string * @param StreamInterface|string|resource $body * @param array $headers * @param string $protocol + * @psalm-suppress MixedArgumentTypeCoercion */ private function init( int $statusCode = 200, diff --git a/src/ServerRequest.php b/src/ServerRequest.php index 5dd8606..fc46c3f 100644 --- a/src/ServerRequest.php +++ b/src/ServerRequest.php @@ -157,6 +157,8 @@ public function getParsedBody() /** * {@inheritDoc} + * + * @psalm-suppress DocblockTypeContradiction */ public function withParsedBody($data): self { @@ -223,6 +225,7 @@ public function withoutAttribute($name): self /** * @param array $uploadedFiles * @throws InvalidArgumentException + * @psalm-suppress MixedAssignment */ private function validateUploadedFiles(array $uploadedFiles): void { diff --git a/src/StreamFactory.php b/src/StreamFactory.php index 5f2c4d2..3c7061c 100644 --- a/src/StreamFactory.php +++ b/src/StreamFactory.php @@ -33,6 +33,8 @@ public function createStreamFromFile(string $filename, string $mode = 'r'): Stre /** * {@inheritdoc} + * + * @psalm-suppress DocblockTypeContradiction */ public function createStreamFromResource($resource): StreamInterface { diff --git a/src/StreamTrait.php b/src/StreamTrait.php index 8eaa841..a021fa0 100644 --- a/src/StreamTrait.php +++ b/src/StreamTrait.php @@ -73,6 +73,7 @@ public function __toString(): string * Closes the stream and any underlying resources. * * @return void + * @psalm-suppress PossiblyNullArgument */ public function close(): void { @@ -196,6 +197,7 @@ public function rewind(): void * Returns whether or not the stream is writable. * * @return bool + * @psalm-suppress MixedAssignment */ public function isWritable(): bool { @@ -240,6 +242,7 @@ public function write($string): int * Returns whether or not the stream is readable. * * @return bool + * @psalm-suppress MixedAssignment */ public function isReadable(): bool { @@ -282,6 +285,7 @@ public function read($length): string * * @return string * @throws RuntimeException if unable to read or an error occurs while reading. + * @psalm-suppress PossiblyNullArgument */ public function getContents(): string { diff --git a/src/UploadedFile.php b/src/UploadedFile.php index 4774794..4e9edf9 100644 --- a/src/UploadedFile.php +++ b/src/UploadedFile.php @@ -97,6 +97,7 @@ final class UploadedFile implements UploadedFileInterface * @param int $error * @param string|null $clientFilename * @param string|null $clientMediaType + * @psalm-suppress RedundantConditionGivenDocblockType */ public function __construct( $streamOrFile, @@ -145,6 +146,8 @@ public function __construct( /** * {@inheritdoc} + * + * @psalm-suppress PossiblyNullArgument */ public function getStream(): StreamInterface { @@ -165,6 +168,8 @@ public function getStream(): StreamInterface /** * {@inheritdoc} + * + * @psalm-suppress DocblockTypeContradiction */ public function moveTo($targetPath): void { @@ -237,6 +242,7 @@ public function getClientMediaType(): ?string * files via is_uploaded_file() and move_uploaded_file() or writes If SAPI is not used. * * @param string $targetPath + * @psalm-suppress PossiblyNullReference */ private function moveOrWriteFile(string $targetPath): void { diff --git a/src/Uri.php b/src/Uri.php index 70da5d5..a4de43d 100644 --- a/src/Uri.php +++ b/src/Uri.php @@ -144,6 +144,8 @@ public function getScheme(): string /** * {@inheritDoc} + * + * @psalm-suppress PossiblyNullOperand */ public function getAuthority(): string { @@ -480,6 +482,7 @@ private function normalizeFragment(string $fragment): string * @param string $string * @param string $pattern * @return string + * @psalm-suppress MixedArgument */ private function encode(string $string, string $pattern): string {