Skip to content

Commit 9c97662

Browse files
committed
Update to PHPStan 2.1
1 parent 2bcffdd commit 9c97662

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"friendsofphp/php-cs-fixer": "^3.45",
3535
"guzzlehttp/psr7": "^2",
3636
"php-mock/php-mock-phpunit": "^2.6",
37-
"phpstan/phpstan": "^1.10",
37+
"phpstan/phpstan": "^2.1",
3838
"phpunit/phpunit": "^9.5 || ^10.5"
3939
},
4040
"autoload": {

src/Redmine/Api/AbstractApi.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ abstract class AbstractApi implements Api
4343
*/
4444
public function __construct($client)
4545
{
46-
if (! is_object($client) || (! $client instanceof Client && ! $client instanceof HttpClient)) {
46+
if (! $client instanceof Client && ! $client instanceof HttpClient) {
4747
throw new InvalidArgumentException(sprintf(
4848
'%s(): Argument #1 ($client) must be of type %s or %s, `%s` given',
4949
__METHOD__,

src/Redmine/Client/Psr18Client.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,15 @@ public function __construct(
4747
string $apikeyOrUsername,
4848
?string $password = null
4949
) {
50-
if (! $requestFactory instanceof RequestFactoryInterface && $requestFactory instanceof ServerRequestFactoryInterface) {
50+
if (! $requestFactory instanceof RequestFactoryInterface && ! $requestFactory instanceof ServerRequestFactoryInterface) {
51+
throw new Exception(sprintf(
52+
'%s(): Argument #2 ($requestFactory) must be of type %s',
53+
__METHOD__,
54+
RequestFactoryInterface::class,
55+
));
56+
}
57+
58+
if ($requestFactory instanceof ServerRequestFactoryInterface) {
5159
@trigger_error(
5260
sprintf(
5361
'%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(
6169
$requestFactory = $this->handleServerRequestFactory($requestFactory);
6270
}
6371

64-
if (! $requestFactory instanceof RequestFactoryInterface) {
65-
throw new Exception(sprintf(
66-
'%s(): Argument #2 ($requestFactory) must be of type %s',
67-
__METHOD__,
68-
RequestFactoryInterface::class,
69-
));
70-
}
71-
7272
$this->httpClient = $httpClient;
7373
$this->requestFactory = $requestFactory;
7474
$this->streamFactory = $streamFactory;

tests/Integration/Psr18ClientRequestGenerationTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testPsr18ClientCreatesCorrectRequests(
3535
): void {
3636
$response = $this->createMock(ResponseInterface::class);
3737

38-
/** @var ClientInterface|\PHPUnit\Framework\MockObject\MockObject */
38+
/** @var ClientInterface&\PHPUnit\Framework\MockObject\MockObject */
3939
$httpClient = $this->createMock(ClientInterface::class);
4040
$httpClient->method('sendRequest')->willReturnCallback(function ($request) use ($response, $expectedOutput) {
4141
// Create a text representation of the HTTP request

tests/Unit/Client/NativeCurlClient/RequestTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function testRequestReturnsCorrectResponse($method, $data, $statusCode, $
5050
'access_token',
5151
);
5252

53-
/** @var Request|\PHPUnit\Framework\MockObject\MockObject */
53+
/** @var Request&\PHPUnit\Framework\MockObject\MockObject */
5454
$request = $this->createConfiguredMock(Request::class, [
5555
'getMethod' => $method,
5656
'getPath' => '/path',
@@ -137,7 +137,7 @@ function ($errno, $errstr): bool {
137137
E_USER_DEPRECATED,
138138
);
139139

140-
/** @var Request|\PHPUnit\Framework\MockObject\MockObject */
140+
/** @var Request&\PHPUnit\Framework\MockObject\MockObject */
141141
$request = $this->createConfiguredMock(Request::class, [
142142
'getMethod' => 'POST',
143143
'getPath' => '/uploads.json',

0 commit comments

Comments
 (0)