diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 88a2f002..88d45941 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -125,7 +125,7 @@ jobs: - name: Upload coverage reports to Codecov if: ${{ matrix.tool == 'code-coverage' }} - uses: codecov/codecov-action@v4 + uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} files: ./.phpunit.cache/clover.xml diff --git a/composer.json b/composer.json index abfc01db..b519ce25 100644 --- a/composer.json +++ b/composer.json @@ -31,10 +31,10 @@ }, "require-dev": { "behat/behat": "^3.14", - "friendsofphp/php-cs-fixer": "^3.45", + "friendsofphp/php-cs-fixer": "^3.68", "guzzlehttp/psr7": "^2", "php-mock/php-mock-phpunit": "^2.6", - "phpstan/phpstan": "^1.10", + "phpstan/phpstan": "^2.1", "phpunit/phpunit": "^9.5 || ^10.5" }, "autoload": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 15583ee9..650f9ea8 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -7,6 +7,7 @@ beStrictAboutCoverageMetadata="false" beStrictAboutOutputDuringTests="true" displayDetailsOnIncompleteTests="true" + displayDetailsOnPhpunitDeprecations="true" displayDetailsOnSkippedTests="true" displayDetailsOnTestsThatTriggerDeprecations="true" displayDetailsOnTestsThatTriggerErrors="true" diff --git a/src/Redmine/Api/AbstractApi.php b/src/Redmine/Api/AbstractApi.php index db6a086e..57068976 100644 --- a/src/Redmine/Api/AbstractApi.php +++ b/src/Redmine/Api/AbstractApi.php @@ -43,7 +43,7 @@ abstract class AbstractApi implements Api */ public function __construct($client) { - if (! is_object($client) || (! $client instanceof Client && ! $client instanceof HttpClient)) { + if (! $client instanceof Client && ! $client instanceof HttpClient) { throw new InvalidArgumentException(sprintf( '%s(): Argument #1 ($client) must be of type %s or %s, `%s` given', __METHOD__, diff --git a/src/Redmine/Client/Psr18Client.php b/src/Redmine/Client/Psr18Client.php index d0c0da17..454c807c 100644 --- a/src/Redmine/Client/Psr18Client.php +++ b/src/Redmine/Client/Psr18Client.php @@ -47,7 +47,15 @@ public function __construct( string $apikeyOrUsername, ?string $password = null ) { - if (! $requestFactory instanceof RequestFactoryInterface && $requestFactory instanceof ServerRequestFactoryInterface) { + if (! $requestFactory instanceof RequestFactoryInterface && ! $requestFactory instanceof ServerRequestFactoryInterface) { + throw new Exception(sprintf( + '%s(): Argument #2 ($requestFactory) must be of type %s', + __METHOD__, + RequestFactoryInterface::class, + )); + } + + if ($requestFactory instanceof ServerRequestFactoryInterface) { @trigger_error( sprintf( '%s(): Providing Argument #2 ($requestFactory) as %s is deprecated since v2.3.0, please provide as %s instead.', @@ -61,14 +69,6 @@ public function __construct( $requestFactory = $this->handleServerRequestFactory($requestFactory); } - if (! $requestFactory instanceof RequestFactoryInterface) { - throw new Exception(sprintf( - '%s(): Argument #2 ($requestFactory) must be of type %s', - __METHOD__, - RequestFactoryInterface::class, - )); - } - $this->httpClient = $httpClient; $this->requestFactory = $requestFactory; $this->streamFactory = $streamFactory; diff --git a/tests/Integration/Psr18ClientRequestGenerationTest.php b/tests/Integration/Psr18ClientRequestGenerationTest.php index 1d98fe5a..36008986 100644 --- a/tests/Integration/Psr18ClientRequestGenerationTest.php +++ b/tests/Integration/Psr18ClientRequestGenerationTest.php @@ -35,7 +35,7 @@ public function testPsr18ClientCreatesCorrectRequests( ): void { $response = $this->createMock(ResponseInterface::class); - /** @var ClientInterface|\PHPUnit\Framework\MockObject\MockObject */ + /** @var ClientInterface&\PHPUnit\Framework\MockObject\MockObject */ $httpClient = $this->createMock(ClientInterface::class); $httpClient->method('sendRequest')->willReturnCallback(function ($request) use ($response, $expectedOutput) { // Create a text representation of the HTTP request diff --git a/tests/Unit/Client/NativeCurlClient/RequestTest.php b/tests/Unit/Client/NativeCurlClient/RequestTest.php index 001b4cdf..05c25177 100644 --- a/tests/Unit/Client/NativeCurlClient/RequestTest.php +++ b/tests/Unit/Client/NativeCurlClient/RequestTest.php @@ -50,7 +50,7 @@ public function testRequestReturnsCorrectResponse($method, $data, $statusCode, $ 'access_token', ); - /** @var Request|\PHPUnit\Framework\MockObject\MockObject */ + /** @var Request&\PHPUnit\Framework\MockObject\MockObject */ $request = $this->createConfiguredMock(Request::class, [ 'getMethod' => $method, 'getPath' => '/path', @@ -137,7 +137,7 @@ function ($errno, $errstr): bool { E_USER_DEPRECATED, ); - /** @var Request|\PHPUnit\Framework\MockObject\MockObject */ + /** @var Request&\PHPUnit\Framework\MockObject\MockObject */ $request = $this->createConfiguredMock(Request::class, [ 'getMethod' => 'POST', 'getPath' => '/uploads.json',