Skip to content

Commit

Permalink
Merge pull request #113 from gsteel/psr-static-return
Browse files Browse the repository at this point in the history
Fix static return type in RequestTrait
  • Loading branch information
Ocramius committed Jul 28, 2022
2 parents 480fee1 + 50d766a commit 6cb35f6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
13 changes: 0 additions & 13 deletions psalm-baseline.xml
Expand Up @@ -69,7 +69,6 @@
</PossiblyNullOperand>
</file>
<file src="src/Request/ArraySerializer.php">
<LessSpecificReturnStatement occurrences="1"/>
<MixedArgument occurrences="6">
<code>$headers</code>
<code>$method</code>
Expand All @@ -85,12 +84,8 @@
<code>$requestTarget</code>
<code>$uri</code>
</MixedAssignment>
<MoreSpecificReturnType occurrences="1">
<code>Request</code>
</MoreSpecificReturnType>
</file>
<file src="src/Request/Serializer.php">
<LessSpecificReturnStatement occurrences="1"/>
<MixedArgument occurrences="5">
<code>$body</code>
<code>$headers</code>
Expand All @@ -101,19 +96,11 @@
<MixedArgumentTypeCoercion occurrences="1">
<code>$request-&gt;getHeaders()</code>
</MixedArgumentTypeCoercion>
<MoreSpecificReturnType occurrences="1">
<code>Request</code>
</MoreSpecificReturnType>
</file>
<file src="src/RequestTrait.php">
<DocblockTypeContradiction occurrences="1">
<code>is_string($method)</code>
</DocblockTypeContradiction>
<LessSpecificImplementedReturnType occurrences="3">
<code>RequestInterface</code>
<code>RequestInterface</code>
<code>RequestInterface</code>
</LessSpecificImplementedReturnType>
<MoreSpecificImplementedParamType occurrences="1">
<code>$requestTarget</code>
</MoreSpecificImplementedParamType>
Expand Down
3 changes: 3 additions & 0 deletions src/RequestTrait.php
Expand Up @@ -158,6 +158,7 @@ public function getRequestTarget(): string
*
* @param string $requestTarget
* @throws Exception\InvalidArgumentException If the request target is invalid.
* @return static
*/
public function withRequestTarget($requestTarget): RequestInterface
{
Expand Down Expand Up @@ -195,6 +196,7 @@ public function getMethod(): string
*
* @param string $method Case-insensitive method.
* @throws Exception\InvalidArgumentException For invalid HTTP methods.
* @return static
*/
public function withMethod($method): RequestInterface
{
Expand Down Expand Up @@ -242,6 +244,7 @@ public function getUri(): UriInterface
*
* @param UriInterface $uri New request URI to use.
* @param bool $preserveHost Preserve the original state of the Host header.
* @return static
*/
public function withUri(UriInterface $uri, $preserveHost = false): RequestInterface
{
Expand Down
44 changes: 44 additions & 0 deletions test/StaticAnalysis/RequestInterfaceStaticReturnTypes.php
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace LaminasTest\Diactoros\StaticAnalysis;

use Laminas\Diactoros\Request;
use Laminas\Diactoros\ServerRequest;
use Laminas\Diactoros\Uri;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ServerRequestInterface;

final class RequestInterfaceStaticReturnTypes
{
public function changeMethodOfServerRequest(ServerRequest $request): ServerRequestInterface
{
return $request->withMethod('GET');
}

public function changeRequestTargetOfServerRequest(ServerRequest $request): ServerRequestInterface
{
return $request->withRequestTarget('foo');
}

public function changeUriOfServerRequest(ServerRequest $request): ServerRequestInterface
{
return $request->withUri(new Uri('/there'));
}

public function changeMethodOfRequest(Request $request): RequestInterface
{
return $request->withMethod('GET');
}

public function changeRequestTargetOfRequest(Request $request): RequestInterface
{
return $request->withRequestTarget('foo');
}

public function changeUriOfRequest(Request $request): RequestInterface
{
return $request->withUri(new Uri('/there'));
}
}

0 comments on commit 6cb35f6

Please sign in to comment.