Skip to content

Commit

Permalink
qa: introduce psalm stub for psr/http-message UriInterface
Browse files Browse the repository at this point in the history
This also requires `Uri` to be `psalm-immutable`.

Signed-off-by: Maximilian Bösing <[email protected]>
  • Loading branch information
boesing committed Apr 6, 2023
1 parent 441cd05 commit 36e7e71
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
/psalm.xml.dist export-ignore
/renovate.json export-ignore
/test/ export-ignore
/psalm/ export-ignore
4 changes: 4 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
</ignoreFiles>
</projectFiles>

<stubs>
<file name="psalm/http-message-stubs/UriInterface.phpstub"/>
</stubs>

<issueHandlers>
<DeprecatedFunction>
<errorLevel type="suppress">
Expand Down
18 changes: 18 additions & 0 deletions psalm/http-message-stubs/UriInterface.phpstub
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);

namespace Psr\Http\Message;

/**
* [...]
* Instances of this interface are considered immutable; all methods that
* might change state MUST be implemented such that they retain the internal
* state of the current instance and return an instance that contains the
* changed state.
* [...]
* @psalm-immutable
*/
interface UriInterface
{

}
5 changes: 3 additions & 2 deletions src/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
* might change state are implemented such that they retain the internal
* state of the current instance and return a new instance that contains the
* changed state.
*
* @psalm-immutable
*/
class Uri implements UriInterface, Stringable
{
Expand Down Expand Up @@ -67,8 +69,7 @@ class Uri implements UriInterface, Stringable

private string $host = '';

/** @var int|null */
private $port;
private ?int $port = null;

private string $path = '';

Expand Down

0 comments on commit 36e7e71

Please sign in to comment.