Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix static return type in RequestTrait #113

Merged
merged 1 commit into from Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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'));
}
}