Skip to content

Commit d2125bb

Browse files
authored
Merge pull request #3395 from odan/4.x-phpstan2
Add PHPStan 2
2 parents 56acabc + b8ea00e commit d2125bb

15 files changed

+40
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.DS_Store
22
.idea
33
.phpunit.result.cache
4+
.phpunit.cache/
45
composer.lock
56
phpunit.xml
67
clover.xml

Slim/Exception/HttpSpecializedException.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ abstract class HttpSpecializedException extends HttpException
1717
{
1818
/**
1919
* @param ServerRequestInterface $request
20-
* @param string|null $message
21-
* @param Throwable|null $previous
20+
* @param string|null $message
21+
* @param Throwable|null $previous
2222
*/
2323
public function __construct(ServerRequestInterface $request, ?string $message = null, ?Throwable $previous = null)
2424
{
2525
if ($message !== null) {
2626
$this->message = $message;
2727
}
2828

29+
// @phpstan-ignore-next-line
2930
parent::__construct($request, $this->message, $this->code, $previous);
3031
}
3132
}

Slim/Factory/Psr17/ServerRequestCreator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public function createServerRequestFromGlobals(): ServerRequestInterface
3939
{
4040
/** @var callable $callable */
4141
$callable = [$this->serverRequestCreator, $this->serverRequestCreatorMethod];
42+
43+
/** @var ServerRequestInterface */
4244
return (Closure::fromCallable($callable))();
4345
}
4446
}

Slim/Handlers/ErrorHandler.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ protected function determineContentType(ServerRequestInterface $request): ?strin
189189
}
190190
}
191191

192+
// @phpstan-ignore-next-line
192193
if (is_string($current)) {
193194
return $current;
194195
}
@@ -259,11 +260,15 @@ public function setLogErrorRenderer($logErrorRenderer): void
259260
protected function writeToErrorLog(): void
260261
{
261262
$renderer = $this->callableResolver->resolve($this->logErrorRenderer);
263+
264+
/** @var string $error */
262265
$error = $renderer($this->exception, $this->logErrorDetails);
266+
263267
if ($this->logErrorRenderer === PlainTextErrorRenderer::class && !$this->displayErrorDetails) {
264268
$error .= "\nTips: To display error details in HTTP response ";
265269
$error .= 'set "displayErrorDetails" to true in the ErrorHandler constructor.';
266270
}
271+
267272
$this->logError($error);
268273
}
269274

Slim/Handlers/Strategies/RequestHandler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function __invoke(
4343
}
4444
}
4545

46+
/** @var ResponseInterface */
4647
return $callable($request);
4748
}
4849
}

Slim/Handlers/Strategies/RequestResponse.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function __invoke(
3535
$request = $request->withAttribute($k, $v);
3636
}
3737

38+
/** @var ResponseInterface */
3839
return $callable($request, $response, $routeArguments);
3940
}
4041
}

Slim/Handlers/Strategies/RequestResponseArgs.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function __invoke(
3434
ResponseInterface $response,
3535
array $routeArguments
3636
): ResponseInterface {
37+
/** @var ResponseInterface */
3738
return $callable($request, $response, ...array_values($routeArguments));
3839
}
3940
}

Slim/Handlers/Strategies/RequestResponseNamedArgs.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function __invoke(
3333
ResponseInterface $response,
3434
array $routeArguments
3535
): ResponseInterface {
36+
/** @var ResponseInterface */
3637
return $callable($request, $response, ...$routeArguments);
3738
}
3839
}

Slim/Middleware/BodyParsingMiddleware.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use function count;
2020
use function explode;
2121
use function is_array;
22-
use function is_null;
2322
use function is_object;
2423
use function is_string;
2524
use function json_decode;
@@ -66,8 +65,8 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
6665
}
6766

6867
/**
69-
* @param string $mediaType A HTTP media type (excluding content-type params).
70-
* @param callable $callable A callable that returns parsed contents for media type.
68+
* @param string $mediaType A HTTP media type (excluding content-type params).
69+
* @param callable $callable A callable that returns parsed contents for media type.
7170
*/
7271
public function registerBodyParser(string $mediaType, callable $callable): self
7372
{
@@ -76,15 +75,15 @@ public function registerBodyParser(string $mediaType, callable $callable): self
7675
}
7776

7877
/**
79-
* @param string $mediaType A HTTP media type (excluding content-type params).
78+
* @param string $mediaType A HTTP media type (excluding content-type params).
8079
*/
8180
public function hasBodyParser(string $mediaType): bool
8281
{
8382
return isset($this->bodyParsers[$mediaType]);
8483
}
8584

8685
/**
87-
* @param string $mediaType A HTTP media type (excluding content-type params).
86+
* @param string $mediaType A HTTP media type (excluding content-type params).
8887
* @throws RuntimeException
8988
*/
9089
public function getBodyParser(string $mediaType): callable
@@ -98,6 +97,7 @@ public function getBodyParser(string $mediaType): callable
9897
protected function registerDefaultBodyParsers(): void
9998
{
10099
$this->registerBodyParser('application/json', static function ($input) {
100+
/** @var string $input */
101101
$result = json_decode($input, true);
102102

103103
if (!is_array($result)) {
@@ -108,11 +108,15 @@ protected function registerDefaultBodyParsers(): void
108108
});
109109

110110
$this->registerBodyParser('application/x-www-form-urlencoded', static function ($input) {
111+
/** @var string $input */
111112
parse_str($input, $data);
113+
112114
return $data;
113115
});
114116

115117
$xmlCallable = static function ($input) {
118+
/** @var string $input */
119+
116120
$backup = self::disableXmlEntityLoader(true);
117121
$backup_errors = libxml_use_internal_errors(true);
118122
$result = simplexml_load_string($input);

Slim/Middleware/ErrorMiddleware.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public function handleException(ServerRequestInterface $request, Throwable $exce
8989
$exceptionType = get_class($exception);
9090
$handler = $this->getErrorHandler($exceptionType);
9191

92+
/** @var ResponseInterface */
9293
return $handler($request, $exception, $this->displayErrorDetails, $this->logErrors, $this->logErrorDetails);
9394
}
9495

@@ -141,7 +142,8 @@ public function getDefaultErrorHandler()
141142
*
142143
* The callable signature MUST match the ErrorHandlerInterface
143144
*
144-
* @see \Slim\Interfaces\ErrorHandlerInterface
145+
* @param string|callable|ErrorHandler $handler
146+
* @see ErrorHandlerInterface
145147
*
146148
* 1. Instance of \Psr\Http\Message\ServerRequestInterface
147149
* 2. Instance of \Throwable
@@ -152,7 +154,6 @@ public function getDefaultErrorHandler()
152154
* The callable MUST return an instance of
153155
* \Psr\Http\Message\ResponseInterface.
154156
*
155-
* @param string|callable|ErrorHandler $handler
156157
*/
157158
public function setDefaultErrorHandler($handler): self
158159
{
@@ -169,7 +170,12 @@ public function setDefaultErrorHandler($handler): self
169170
* Pass true to $handleSubclasses to make the handler handle all subclasses of
170171
* the type as well. Pass an array of classes to make the same function handle multiple exceptions.
171172
*
172-
* @see \Slim\Interfaces\ErrorHandlerInterface
173+
* @param string|string[] $typeOrTypes Exception/Throwable name.
174+
* ie: RuntimeException::class or an array of classes
175+
* ie: [HttpNotFoundException::class, HttpMethodNotAllowedException::class]
176+
* @param string|callable|ErrorHandlerInterface $handler
177+
*
178+
* @see ErrorHandlerInterface
173179
*
174180
* 1. Instance of \Psr\Http\Message\ServerRequestInterface
175181
* 2. Instance of \Throwable
@@ -180,10 +186,6 @@ public function setDefaultErrorHandler($handler): self
180186
* The callable MUST return an instance of
181187
* \Psr\Http\Message\ResponseInterface.
182188
*
183-
* @param string|string[] $typeOrTypes Exception/Throwable name.
184-
* ie: RuntimeException::class or an array of classes
185-
* ie: [HttpNotFoundException::class, HttpMethodNotAllowedException::class]
186-
* @param string|callable|ErrorHandlerInterface $handler
187189
*/
188190
public function setErrorHandler($typeOrTypes, $handler, bool $handleSubclasses = false): self
189191
{

0 commit comments

Comments
 (0)