Skip to content

Commit

Permalink
Merge pull request #54 from gsteel/general-qa
Browse files Browse the repository at this point in the history
Type inference improvements, baseline reduction
  • Loading branch information
Ocramius authored Jul 16, 2024
2 parents d063c77 + 537b489 commit c8d802a
Show file tree
Hide file tree
Showing 15 changed files with 295 additions and 355 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
},
"require-dev": {
"laminas/laminas-coding-standard": "~2.5.0",
"laminas/laminas-diactoros": "^2.25 || ^3.3",
"phpunit/phpunit": "^10.4.2",
"psalm/plugin-phpunit": "^0.18.4",
"vimeo/psalm": "^5.15.0"
"laminas/laminas-diactoros": "^2.25 || ^3.3.1",
"phpunit/phpunit": "^10.5.27",
"psalm/plugin-phpunit": "^0.19.0",
"vimeo/psalm": "^5.25.0"
},
"conflict": {
"zendframework/zend-stratigility": "*"
Expand Down
370 changes: 187 additions & 183 deletions composer.lock

Large diffs are not rendered by default.

203 changes: 60 additions & 143 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,246 +1,163 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.11.0@c9b192ab8400fdaf04b2b13d110575adc879aa90">
<file src="src/Handler/NotFoundHandler.php">
<MixedInferredReturnType>
<code>ResponseInterface</code>
</MixedInferredReturnType>
<MixedMethodCall>
<code>withStatus</code>
</MixedMethodCall>
<MixedReturnStatement>
<code>$responseFactory()</code>
</MixedReturnStatement>
</file>
<files psalm-version="5.25.0@01a8eb06b9e9cc6cfb6a320bf9fb14331919d505">
<file src="src/Middleware/DoublePassMiddlewareDecorator.php">
<MissingClosureParamType>
<code>$request</code>
<code>$response</code>
<code><![CDATA[$request]]></code>
<code><![CDATA[$response]]></code>
</MissingClosureParamType>
<MixedArgument>
<code>$request</code>
<code><![CDATA[$request]]></code>
</MixedArgument>
<UnusedClosureParam>
<code>$response</code>
<code><![CDATA[$response]]></code>
</UnusedClosureParam>
</file>
<file src="src/Middleware/ErrorHandler.php">
<MixedArgument>
<code>$response</code>
<code><![CDATA[$response]]></code>
</MixedArgument>
<MixedArgumentTypeCoercion>
<code><![CDATA[$this->createErrorHandler()]]></code>
</MixedArgumentTypeCoercion>
<MixedAssignment>
<code>$response</code>
<code><![CDATA[$response]]></code>
</MixedAssignment>
<MixedInferredReturnType>
<code>ResponseInterface</code>
<code><![CDATA[ResponseInterface]]></code>
</MixedInferredReturnType>
<MixedReturnStatement>
<code>$responseFactory()</code>
<code><![CDATA[$responseFactory()]]></code>
</MixedReturnStatement>
</file>
<file src="src/Middleware/ErrorResponseGenerator.php">
<UnusedParam>
<code>$request</code>
<code><![CDATA[$request]]></code>
</UnusedParam>
</file>
<file src="src/Middleware/HostMiddlewareDecorator.php">
<PossiblyUnusedReturnValue>
<code>ResponseInterface</code>
<code><![CDATA[ResponseInterface]]></code>
</PossiblyUnusedReturnValue>
</file>
<file src="src/Next.php">
<MixedAssignment>
<code>$middleware</code>
</MixedAssignment>
<MixedInferredReturnType>
<code>ResponseInterface</code>
</MixedInferredReturnType>
<MixedMethodCall>
<code>process</code>
</MixedMethodCall>
<MixedReturnStatement>
<code><![CDATA[$middleware->process($request, $next)]]></code>
</MixedReturnStatement>
</file>
<file src="src/functions/double-pass-middleware.legacy.php">
<InvalidReturnStatement>
<code>laminas_doublePassMiddleware(...func_get_args())</code>
<code><![CDATA[laminas_doublePassMiddleware(...func_get_args())]]></code>
</InvalidReturnStatement>
<InvalidReturnType>
<code>Middleware\DoublePassMiddlewareDecorator</code>
<code><![CDATA[Middleware\DoublePassMiddlewareDecorator]]></code>
</InvalidReturnType>
<MixedArgument>
<code>func_get_args()</code>
<code>func_get_args()</code>
<code><![CDATA[func_get_args()]]></code>
<code><![CDATA[func_get_args()]]></code>
</MixedArgument>
<UndefinedClass>
<code>Middleware\DoublePassMiddlewareDecorator</code>
<code><![CDATA[Middleware\DoublePassMiddlewareDecorator]]></code>
</UndefinedClass>
</file>
<file src="src/functions/host.legacy.php">
<InvalidReturnStatement>
<code>laminas_host(...func_get_args())</code>
<code><![CDATA[laminas_host(...func_get_args())]]></code>
</InvalidReturnStatement>
<InvalidReturnType>
<code>Middleware\HostMiddlewareDecorator</code>
<code><![CDATA[Middleware\HostMiddlewareDecorator]]></code>
</InvalidReturnType>
<MixedArgument>
<code>func_get_args()</code>
<code>func_get_args()</code>
<code><![CDATA[func_get_args()]]></code>
<code><![CDATA[func_get_args()]]></code>
</MixedArgument>
<UndefinedClass>
<code>Middleware\HostMiddlewareDecorator</code>
<code><![CDATA[Middleware\HostMiddlewareDecorator]]></code>
</UndefinedClass>
</file>
<file src="src/functions/middleware.legacy.php">
<InvalidReturnStatement>
<code>laminas_middleware(...func_get_args())</code>
<code><![CDATA[laminas_middleware(...func_get_args())]]></code>
</InvalidReturnStatement>
<InvalidReturnType>
<code>Middleware\CallableMiddlewareDecorator</code>
<code><![CDATA[Middleware\CallableMiddlewareDecorator]]></code>
</InvalidReturnType>
<MixedArgument>
<code>func_get_args()</code>
<code><![CDATA[func_get_args()]]></code>
</MixedArgument>
<UndefinedClass>
<code>Middleware\CallableMiddlewareDecorator</code>
<code><![CDATA[Middleware\CallableMiddlewareDecorator]]></code>
</UndefinedClass>
</file>
<file src="src/functions/path.legacy.php">
<InvalidReturnStatement>
<code>laminas_path(...func_get_args())</code>
<code><![CDATA[laminas_path(...func_get_args())]]></code>
</InvalidReturnStatement>
<InvalidReturnType>
<code>Middleware\PathMiddlewareDecorator</code>
<code><![CDATA[Middleware\PathMiddlewareDecorator]]></code>
</InvalidReturnType>
<MixedArgument>
<code>func_get_args()</code>
<code>func_get_args()</code>
<code><![CDATA[func_get_args()]]></code>
<code><![CDATA[func_get_args()]]></code>
</MixedArgument>
<UndefinedClass>
<code>Middleware\PathMiddlewareDecorator</code>
<code><![CDATA[Middleware\PathMiddlewareDecorator]]></code>
</UndefinedClass>
</file>
<file src="test/Exception/ExceptionTest.php">
<MixedInferredReturnType>
<code>Generator</code>
</MixedInferredReturnType>
<PossiblyFalseOperand>
<code>strrpos(ExceptionInterface::class, '\\')</code>
</PossiblyFalseOperand>
</file>
<file src="test/Middleware/CallableMiddlewareDecoratorTest.php">
<MissingClosureParamType>
<code>$handler</code>
<code>$request</code>
<code><![CDATA[$handler]]></code>
<code><![CDATA[$request]]></code>
</MissingClosureParamType>
<UnusedClosureParam>
<code>$handler</code>
<code>$request</code>
<code><![CDATA[$handler]]></code>
<code><![CDATA[$request]]></code>
</UnusedClosureParam>
</file>
<file src="test/Middleware/DoublePassMiddlewareDecoratorExceptionTest.php">
<MissingClosureParamType>
<code>$next</code>
<code>$request</code>
<code><![CDATA[$next]]></code>
<code><![CDATA[$request]]></code>
</MissingClosureParamType>
<MixedArgument>
<code>$autoloader</code>
<code><![CDATA[$autoloader]]></code>
</MixedArgument>
<MixedAssignment>
<code>$autoloader</code>
<code><![CDATA[$autoloader]]></code>
</MixedAssignment>
<UnusedClosureParam>
<code>$next</code>
<code><![CDATA[$next]]></code>
</UnusedClosureParam>
</file>
<file src="test/Middleware/DoublePassMiddlewareDecoratorTest.php">
<MissingClosureParamType>
<code>$next</code>
<code>$next</code>
<code>$next</code>
<code>$next</code>
<code>$request</code>
<code>$request</code>
<code>$request</code>
<code>$request</code>
<code>$response</code>
<code>$response</code>
<code><![CDATA[$next]]></code>
<code><![CDATA[$next]]></code>
<code><![CDATA[$next]]></code>
<code><![CDATA[$next]]></code>
<code><![CDATA[$request]]></code>
<code><![CDATA[$request]]></code>
<code><![CDATA[$request]]></code>
<code><![CDATA[$request]]></code>
<code><![CDATA[$response]]></code>
<code><![CDATA[$response]]></code>
</MissingClosureParamType>
<UnusedClosureParam>
<code>$next</code>
<code>$next</code>
<code>$next</code>
<code>$next</code>
<code>$request</code>
<code>$request</code>
<code>$response</code>
<code>$response</code>
<code><![CDATA[$next]]></code>
<code><![CDATA[$next]]></code>
<code><![CDATA[$next]]></code>
<code><![CDATA[$next]]></code>
<code><![CDATA[$request]]></code>
<code><![CDATA[$request]]></code>
<code><![CDATA[$response]]></code>
<code><![CDATA[$response]]></code>
</UnusedClosureParam>
</file>
<file src="test/Middleware/ErrorHandlerTest.php">
<MixedArgument>
<code>$listeners</code>
<code><![CDATA[$listeners]]></code>
</MixedArgument>
<MixedAssignment>
<code>$listeners</code>
<code><![CDATA[$listeners]]></code>
</MixedAssignment>
</file>
<file src="test/Middleware/HostMiddlewareDecoratorTest.php">
<MixedInferredReturnType>
<code>Generator</code>
</MixedInferredReturnType>
</file>
<file src="test/Middleware/NotFoundHandlerTest.php">
<DeprecatedClass>
<code>new NotFoundHandler($responseFactory)</code>
<code><![CDATA[new NotFoundHandler($responseFactory)]]></code>
</DeprecatedClass>
</file>
<file src="test/Middleware/PathMiddlewareDecoratorIntegrationTest.php">
<MixedAssignment>
<code>$receivedUri</code>
</MixedAssignment>
<MixedMethodCall>
<code>getPath</code>
<code>getPath</code>
<code>getUri</code>
<code>getUri</code>
</MixedMethodCall>
<MixedOperand>
<code>$path</code>
</MixedOperand>
</file>
<file src="test/Middleware/PathMiddlewareDecoratorTest.php">
<MixedMethodCall>
<code>getPath</code>
<code>getUri</code>
</MixedMethodCall>
<ParamNameMismatch>
<code>$req</code>
</ParamNameMismatch>
</file>
<file src="test/MiddlewarePipeTest.php">
<ParamNameMismatch>
<code>$req</code>
<code>$req</code>
</ParamNameMismatch>
</file>
<file src="test/NextTest.php">
<ParamNameMismatch>
<code>$req</code>
<code>$req</code>
</ParamNameMismatch>
</file>
<file src="test/TestAsset/DelegatingMiddleware.php">
<ParamNameMismatch>
<code>$req</code>
</ParamNameMismatch>
</file>
<file src="test/TestAsset/ShortCircuitingMiddleware.php">
<ParamNameMismatch>
<code>$req</code>
</ParamNameMismatch>
</file>
</files>
7 changes: 4 additions & 3 deletions src/Handler/NotFoundHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Laminas\Stratigility\Handler;

use Closure;
use Fig\Http\Message\StatusCodeInterface as StatusCode;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -13,11 +14,11 @@

final class NotFoundHandler implements RequestHandlerInterface
{
/** @var callable */
private $responseFactory;
/** @var Closure(): ResponseInterface */
private Closure $responseFactory;

/**
* @param callable $responseFactory A factory capable of returning an
* @param callable(): ResponseInterface $responseFactory A factory capable of returning an
* empty ResponseInterface instance to update and return when returning
* an 404 response.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/NotFoundHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class NotFoundHandler implements MiddlewareInterface
private NotFoundRequestHandler $notFoundHandler;

/**
* @param callable $responseFactory A factory capable of returning an
* @param callable(): ResponseInterface $responseFactory A factory capable of returning an
* empty ResponseInterface instance to update and return when returning
* an 404 response.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/MiddlewarePipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
*/
final class MiddlewarePipe implements MiddlewarePipeInterface
{
/** @var SplQueue<MiddlewareInterface> */
private SplQueue $pipeline;

/**
* Initializes the queue.
*/
public function __construct()
{
/** @psalm-var SplQueue<MiddlewareInterface> */
$this->pipeline = new SplQueue();
}

Expand Down
3 changes: 3 additions & 0 deletions src/Next.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Laminas\Stratigility\Exception\MiddlewarePipeNextHandlerAlreadyCalledException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use SplQueue;

Expand All @@ -17,11 +18,13 @@ final class Next implements RequestHandlerInterface
{
private RequestHandlerInterface $fallbackHandler;

/** @var SplQueue<MiddlewareInterface> */
private ?SplQueue $queue;

/**
* Clones the queue provided to allow re-use.
*
* @param SplQueue<MiddlewareInterface> $queue
* @param RequestHandlerInterface $fallbackHandler Fallback handler to
* invoke when the queue is exhausted.
*/
Expand Down
Loading

0 comments on commit c8d802a

Please sign in to comment.