Skip to content

Commit

Permalink
Update PSALM config
Browse files Browse the repository at this point in the history
Fix psalm config

PSAML has problems with goto analyze. It leads to wrong issues:
vimeo/psalm#11327
  • Loading branch information
Nek- committed Feb 20, 2025
1 parent 3c581f9 commit cd99109
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 11 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"phpunit/phpunit": "^9",
"amphp/http-server": "^3",
"kelunik/link-header-rfc5988": "^1",
"psalm/phar": "~5.23",
"psalm/phar": "*",
"laminas/laminas-diactoros": "^3.5.0"
},
"suggest": {
Expand Down
2 changes: 1 addition & 1 deletion examples/pagination/1-iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

require __DIR__ . '/../.helper/functions.php';

class GitHubApi
final class GitHubApi
{
private HttpClient $httpClient;

Expand Down
4 changes: 2 additions & 2 deletions examples/pagination/2-iterator-batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

require __DIR__ . '/../.helper/functions.php';

class GitHubApi
final class GitHubApi
{
private HttpClient $httpClient;

Expand All @@ -36,7 +36,7 @@ public function getEvents(string $organization): iterable
$events = json_decode($json);
yield $events;

$links = parseLinks($response->getHeader('link'));
$links = parseLinks($response->getHeader('link') ?? '');
$next = $links->getByRel('next');

if ($next) {
Expand Down
1 change: 1 addition & 0 deletions examples/streaming/1-large-response.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function formatBytes(int $size, int $precision = 2): string
print "\n";

$path = tempnam(sys_get_temp_dir(), "artax-streaming-");
assert($path !== false);

$file = Amp\File\openFile($path, "w");

Expand Down
1 change: 1 addition & 0 deletions examples/streaming/2-http1-http2.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function fetch(string $uri, array $protocolVersions): void
print "\n";

$path = tempnam(sys_get_temp_dir(), "artax-streaming-");
assert($path !== false);

$file = Amp\File\openFile($path, "w");

Expand Down
1 change: 1 addition & 0 deletions examples/streaming/3-large-response-slow-read.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function formatBytes(int $size, int $precision = 2): string
print "\n";

$path = tempnam(sys_get_temp_dir(), "artax-streaming-");
assert($path !== false);

$file = Amp\File\openFile($path, "w");

Expand Down
29 changes: 23 additions & 6 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
phpVersion="8.1"
resolveFromConfigFile="true"
rememberPropertyAssignmentsAfterCall="false"
ensureOverrideAttribute="false"
findUnusedCode="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
xmlns:xi="http://www.w3.org/2001/XInclude"
>
<projectFiles>
<directory name="examples"/>
Expand All @@ -24,6 +27,20 @@
</errorLevel>
</StringIncrement>

<ImplicitToStringCast>
<errorLevel type="suppress">
<directory name="examples"/>
<directory name="src"/>
</errorLevel>
</ImplicitToStringCast>

<InvalidOperand>
<errorLevel type="suppress">
<directory name="examples"/>
<directory name="src"/>
</errorLevel>
</InvalidOperand>

<DuplicateClass>
<errorLevel type="suppress">
<directory name="examples"/>
Expand All @@ -42,12 +59,6 @@
</errorLevel>
</DocblockTypeContradiction>

<MissingClosureParamType>
<errorLevel type="suppress">
<directory name="src"/>
</errorLevel>
</MissingClosureParamType>

<MissingClosureReturnType>
<errorLevel type="suppress">
<directory name="src" />
Expand All @@ -59,5 +70,11 @@
<directory name="src" />
</errorLevel>
</RiskyTruthyFalsyComparison>

<InvalidReturnType>
<errorLevel type="suppress">
<file name="src/Connection/Internal/Http1Parser.php" />
</errorLevel>
</InvalidReturnType>
</issueHandlers>
</psalm>
2 changes: 2 additions & 0 deletions src/Connection/Internal/Http1Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ private function parseRawHeaders(string $rawHeaders): array
$rawHeaders = \preg_replace("/\r\n[\x20\t]++/", ' ', $rawHeaders);
}

\assert($rawHeaders !== null);

try {
$headers = Rfc7230::parseHeaderPairs($rawHeaders);
$headerMap = mapHeaderPairs($headers);
Expand Down
1 change: 1 addition & 0 deletions src/Connection/Internal/Http2ConnectionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,7 @@ public function request(Request $request, Cancellation $cancellation, Stream $st
$this->writeFrame(Http2Parser::CONTINUATION, Http2Parser::NO_FLAG, $streamId, $headerChunk)->ignore();
}

\assert($lastChunk !== null);
$this->writeFrame(Http2Parser::CONTINUATION, $flag, $streamId, $lastChunk)->await();
} else {
$this->writeFrame(Http2Parser::HEADERS, $flag, $streamId, $headers)->await();
Expand Down
2 changes: 1 addition & 1 deletion src/EventListener/LogHttpArchive.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private function writeLog(Response $response): void
$fileHandle->seek(-3, Whence::Current);
}

$json = \json_encode(self::formatEntry($response));
$json = \json_encode(self::formatEntry($response), flags: JSON_THROW_ON_ERROR);

$fileHandle->write(($firstEntry ? '' : ',') . $json . ']}}');

Expand Down
2 changes: 2 additions & 0 deletions src/Interceptor/FollowRedirects.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ private static function removeDotSegments(string $input): string
$patternE = ',(/*[^/]*),';

while ($input !== '') {
\assert($input !== null);
if (\preg_match($patternA, $input)) {
$input = \preg_replace($patternA, '', $input);
} elseif (\preg_match($patternB1, $input, $match) || \preg_match($patternB2, $input, $match)) {
Expand All @@ -80,6 +81,7 @@ private static function removeDotSegments(string $input): string
$input = \preg_replace(',^' . \preg_quote($initialSegment, ',') . ',', '', $input, 1);
$output .= $initialSegment;
}
\assert($output !== null);
}

return $output;
Expand Down
3 changes: 3 additions & 0 deletions src/Interceptor/RetryRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function request(
DelegateHttpClient $httpClient
): Response {
$attempt = 1;
$exception = null;

do {
$clonedRequest = clone $request;
Expand All @@ -43,6 +44,8 @@ public function request(
}
} while ($attempt++ <= $this->retryLimit);

\assert($exception !== null);

throw $exception;
}
}
3 changes: 3 additions & 0 deletions src/Interceptor/TooManyRedirectsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Amp\Http\Client\HttpException;
use Amp\Http\Client\Response;

/**
* @api
*/
class TooManyRedirectsException extends HttpException
{
private Response $response;
Expand Down

0 comments on commit cd99109

Please sign in to comment.