From 7ce699a9601926880026c23edcde14a4a07bb762 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Thu, 10 Feb 2022 09:16:32 +0100 Subject: [PATCH] adjust baseline to reformatted error messages and fix some issues --- .github/workflows/static.yml | 3 ++ composer.json | 5 ++- phpstan-baseline.neon | 67 ++++++++++------------------------- src/Authentication/Header.php | 5 ++- src/CookieJar.php | 2 ++ src/Encoding/Filter/Chunk.php | 1 + src/Stream/BufferedStream.php | 3 ++ 7 files changed, 35 insertions(+), 51 deletions(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 6530f18..373207a 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -15,6 +15,9 @@ jobs: - name: Checkout code uses: actions/checkout@v2 + - name: Install legacy zend diactoros as we reference that as well + run: composer require "zendframework/zend-diactoros:2.2.1" --no-interaction --no-update + - name: PHPStan uses: docker://oskarstark/phpstan-ga env: diff --git a/composer.json b/composer.json index 5d24bcd..1a614df 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,10 @@ "slim/slim": "Used with Slim Framework PSR-7 implementation" }, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "ergebnis/composer-normalize": true + } }, "extra": { "branch-alias": { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 40013ca..065b358 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,20 +1,5 @@ parameters: ignoreErrors: - - - message: "#^Property Http\\\\Message\\\\Authentication\\\\Header\\:\\:\\$value type has no value type specified in iterable type array\\.$#" - count: 1 - path: src/Authentication/Header.php - - - - message: "#^Method Http\\\\Message\\\\Authentication\\\\Header\\:\\:__construct\\(\\) has parameter \\$value with no typehint specified\\.$#" - count: 1 - path: src/Authentication/Header.php - - - - message: "#The Http\\\\Message\\\\Authentication\\\\Matching class is deprecated since version 1.2 and will be removed in 2.0.#" - count: 1 - path: src/Authentication/Matching.php - - message: "#^Property Http\\\\Message\\\\Authentication\\\\QueryParam\\:\\:\\$params type has no value type specified in iterable type array\\.$#" count: 1 @@ -41,7 +26,7 @@ parameters: path: src/Builder/ResponseBuilder.php - - message: "#^Method Http\\\\Message\\\\Cookie\\:\\:createWithoutValidation\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\Cookie\\:\\:createWithoutValidation\\(\\) has no return type specified\\.$#" count: 1 path: src/Cookie.php @@ -56,17 +41,17 @@ parameters: path: src/Cookie.php - - message: "#^Method Http\\\\Message\\\\Cookie\\:\\:validateName\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\Cookie\\:\\:validateName\\(\\) has no return type specified\\.$#" count: 1 path: src/Cookie.php - - message: "#^Method Http\\\\Message\\\\Cookie\\:\\:validateValue\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\Cookie\\:\\:validateValue\\(\\) has no return type specified\\.$#" count: 1 path: src/Cookie.php - - message: "#^Method Http\\\\Message\\\\Cookie\\:\\:validateMaxAge\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\Cookie\\:\\:validateMaxAge\\(\\) has no return type specified\\.$#" count: 1 path: src/Cookie.php @@ -86,12 +71,12 @@ parameters: path: src/CookieJar.php - - message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:addCookie\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:addCookie\\(\\) has no return type specified\\.$#" count: 1 path: src/CookieJar.php - - message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:removeCookie\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:removeCookie\\(\\) has no return type specified\\.$#" count: 1 path: src/CookieJar.php @@ -101,22 +86,22 @@ parameters: path: src/CookieJar.php - - message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:setCookies\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:setCookies\\(\\) has no return type specified\\.$#" count: 1 path: src/CookieJar.php - - message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:addCookies\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:addCookies\\(\\) has no return type specified\\.$#" count: 1 path: src/CookieJar.php - - message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:removeCookies\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:removeCookies\\(\\) has no return type specified\\.$#" count: 1 path: src/CookieJar.php - - message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:removeMatchingCookies\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:removeMatchingCookies\\(\\) has no return type specified\\.$#" count: 1 path: src/CookieJar.php @@ -126,7 +111,7 @@ parameters: path: src/CookieJar.php - - message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:clear\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\CookieJar\\:\\:clear\\(\\) has no return type specified\\.$#" count: 1 path: src/CookieJar.php @@ -141,37 +126,27 @@ parameters: path: src/CookieUtil.php - - message: "#^Method Http\\\\Message\\\\Encoding\\\\ChunkStream\\:\\:fill\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\Encoding\\\\ChunkStream\\:\\:fill\\(\\) has no return type specified\\.$#" count: 1 path: src/Encoding/ChunkStream.php - - - message: "#^Method Http\\\\Message\\\\Encoding\\\\Filter\\\\Chunk\\:\\:filter\\(\\) has parameter \\$consumed with no typehint specified\\.$#" - count: 1 - path: src/Encoding/Filter/Chunk.php - - - - message: "#^Access to an undefined property Http\\\\Message\\\\Encoding\\\\Filter\\\\Chunk\\:\\:\\$stream\\.$#" - count: 2 - path: src/Encoding/Filter/Chunk.php - - message: "#^Access to an undefined property object\\:\\:\\$datalen\\.$#" count: 2 path: src/Encoding/Filter/Chunk.php - - message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:fill\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:fill\\(\\) has no return type specified\\.$#" count: 1 path: src/Encoding/FilteredStream.php - - message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:rewind\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:rewind\\(\\) has no return type specified\\.$#" count: 1 path: src/Encoding/FilteredStream.php - - message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:seek\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\Encoding\\\\FilteredStream\\:\\:seek\\(\\) has no return type specified\\.$#" count: 1 path: src/Encoding/FilteredStream.php @@ -205,11 +180,6 @@ parameters: count: 1 path: src/MessageFactory/SlimMessageFactory.php - - - message: "#The Http\\\\Message\\\\RequestMatcher\\\\RegexRequestMatcher class is deprecated since version 1.2 and will be removed in 2.0.#" - count: 1 - path: src/RequestMatcher/RegexRequestMatcher.php - - message: "#^Property Http\\\\Message\\\\RequestMatcher\\\\RequestMatcher\\:\\:\\$methods type has no value type specified in iterable type array\\.$#" count: 1 @@ -236,7 +206,7 @@ parameters: path: src/Stream/BufferedStream.php - - message: "#^Dead catch \\- Exception is already caught by Throwable above\\.$#" + message: "#^Dead catch \\- Exception is already caught#" count: 1 path: src/Stream/BufferedStream.php @@ -266,12 +236,12 @@ parameters: path: src/Stream/BufferedStream.php - - message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:seek\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:seek\\(\\) has no return type specified\\.$#" count: 1 path: src/Stream/BufferedStream.php - - message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:rewind\\(\\) has no return typehint specified\\.$#" + message: "#^Method Http\\\\Message\\\\Stream\\\\BufferedStream\\:\\:rewind\\(\\) has no return type specified\\.$#" count: 1 path: src/Stream/BufferedStream.php @@ -294,4 +264,3 @@ parameters: message: "#^Unreachable statement \\- code above always terminates\\.$#" count: 1 path: src/UriFactory/SlimUriFactory.php - diff --git a/src/Authentication/Header.php b/src/Authentication/Header.php index 97a04dd..77f6382 100644 --- a/src/Authentication/Header.php +++ b/src/Authentication/Header.php @@ -13,10 +13,13 @@ class Header implements Authentication private $name; /** - * @var string|array + * @var string|string[] */ private $value; + /** + * @param string|string[] $value + */ public function __construct(string $name, $value) { $this->name = $name; diff --git a/src/CookieJar.php b/src/CookieJar.php index 1479cc6..914ad97 100644 --- a/src/CookieJar.php +++ b/src/CookieJar.php @@ -195,6 +195,7 @@ public function clear() /** * {@inheritdoc} */ + #[\ReturnTypeWillChange] public function count() { return $this->cookies->count(); @@ -203,6 +204,7 @@ public function count() /** * {@inheritdoc} */ + #[\ReturnTypeWillChange] public function getIterator() { return clone $this->cookies; diff --git a/src/Encoding/Filter/Chunk.php b/src/Encoding/Filter/Chunk.php index 0f8f53b..538e270 100644 --- a/src/Encoding/Filter/Chunk.php +++ b/src/Encoding/Filter/Chunk.php @@ -12,6 +12,7 @@ class Chunk extends \php_user_filter /** * {@inheritdoc} */ + #[\ReturnTypeWillChange] public function filter($in, $out, &$consumed, $closing) { while ($bucket = stream_bucket_make_writeable($in)) { diff --git a/src/Stream/BufferedStream.php b/src/Stream/BufferedStream.php index 1eac974..3d38731 100644 --- a/src/Stream/BufferedStream.php +++ b/src/Stream/BufferedStream.php @@ -203,6 +203,9 @@ public function read($length) if (null === $this->resource) { throw new \RuntimeException('Cannot read on a detached stream'); } + if ($length < 0) { + throw new \InvalidArgumentException('Can not read a negative amount of bytes'); + } $read = '';