Skip to content

Commit d052288

Browse files
committed
Fix or suppress Psalm 6 issues
1 parent fa3c342 commit d052288

6 files changed

Lines changed: 32 additions & 14 deletions

File tree

psalm.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,22 @@
2727
</errorLevel>
2828
</MissingClosureReturnType>
2929

30+
<PossiblyUnusedMethod>
31+
<errorLevel type="suppress">
32+
<directory name="src"/>
33+
</errorLevel>
34+
</PossiblyUnusedMethod>
35+
3036
<RedundantCastGivenDocblockType>
3137
<errorLevel type="suppress">
3238
<directory name="src" />
3339
</errorLevel>
3440
</RedundantCastGivenDocblockType>
3541

36-
<RedundantConditionGivenDocblockType>
42+
<UnusedClass>
3743
<errorLevel type="suppress">
38-
<directory name="src" />
44+
<directory name="src"/>
3945
</errorLevel>
40-
</RedundantConditionGivenDocblockType>
46+
</UnusedClass>
4147
</issueHandlers>
4248
</psalm>

src/Cookie/CookieAttributes.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,20 +328,19 @@ public function toString(): string
328328
{
329329
$string = '';
330330

331-
if ($this->expiry) {
331+
if ($this->expiry !== null) {
332332
$string .= '; Expires=' . \gmdate('D, j M Y G:i:s T', $this->expiry->getTimestamp());
333333
}
334334

335-
/** @psalm-suppress RiskyTruthyFalsyComparison */
336-
if ($this->maxAge) {
335+
if ($this->maxAge !== null) {
337336
$string .= '; Max-Age=' . $this->maxAge;
338337
}
339338

340-
if ('' !== $this->path) {
339+
if ($this->path !== '') {
341340
$string .= '; Path=' . $this->path;
342341
}
343342

344-
if ('' !== $this->domain) {
343+
if ($this->domain !== '') {
345344
$string .= '; Domain=' . $this->domain;
346345
}
347346

src/Cookie/ResponseCookie.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ public function withAttributes(CookieAttributes $attributes): self
368368
public function toString(): string
369369
{
370370
$line = $this->name . '=' . $this->value;
371-
$line .= $this->attributes;
371+
$line .= (string) $this->attributes;
372372

373373
$unknownAttributes = \implode('; ', $this->unknownAttributes);
374374
if ($unknownAttributes !== '') {

src/Http1/Rfc7230.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,12 @@ public static function formatHeaderPairs(array $headers): string
176176
return $bytes;
177177
}
178178

179-
// @codeCoverageIgnoreStart
179+
/**
180+
* @codeCoverageIgnore
181+
* @psalm-suppress UnusedConstructor
182+
*/
180183
private function __construct()
181184
{
182185
// forbid instances
183186
}
184-
// @codeCoverageIgnoreEnd
185187
}

src/Http2/Http2Parser.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ private function parse(?string $settings = null): \Generator
185185
$frameHeader = yield 9;
186186
$this->receivedByteCount += 9;
187187

188+
/** @psalm-suppress PossiblyInvalidArrayAccess */
188189
[
189190
'length' => $frameLength,
190191
'flags' => $frameFlags,
@@ -282,6 +283,7 @@ private function parsePushPromise(string $frameBuffer, int $frameLength, int $fr
282283

283284
$padding = $isPadded ? \ord($header[0]) : 0;
284285

286+
/** @psalm-suppress PossiblyInvalidArrayAccess */
285287
$pushId = \unpack("N", $header)[1] & 0x7fffffff;
286288

287289
if ($frameLength - $headerLength - $padding < 0) {
@@ -418,6 +420,7 @@ private function parseHeaders(string $frameBuffer, int $frameLength, int $frameF
418420
$padding = $isPadded ? \ord($header[0]) : 0;
419421

420422
if ($isPriority) {
423+
/** @psalm-suppress PossiblyInvalidArrayAccess */
421424
['parent' => $parent, 'weight' => $weight] = \unpack("Nparent/cweight", $header, $isPadded ? 1 : 0);
422425

423426
$parent &= 0x7fffffff;
@@ -475,9 +478,11 @@ private function parsePriorityFrame(string $frameBuffer, int $frameLength, int $
475478
$this->throwInvalidFrameSizeError();
476479
}
477480

481+
/** @psalm-suppress PossiblyInvalidArrayAccess */
478482
['parent' => $parent, 'weight' => $weight] = \unpack("Nparent/cweight", $frameBuffer);
479483

480-
if ($exclusive = ($parent & 0x80000000)) {
484+
$exclusive = $parent & 0x80000000;
485+
if ($exclusive) {
481486
$parent &= 0x7fffffff;
482487
}
483488

@@ -502,6 +507,7 @@ private function parseStreamReset(string $frameBuffer, int $frameLength, int $st
502507
$this->throwInvalidZeroStreamIdError();
503508
}
504509

510+
/** @psalm-suppress PossiblyInvalidArrayAccess */
505511
$errorCode = \unpack('N', $frameBuffer)[1];
506512

507513
$this->handler->handleStreamReset($streamId, $errorCode);
@@ -534,6 +540,7 @@ private function parseSettings(string $frameBuffer, int $frameLength, int $frame
534540
$settings = [];
535541

536542
while ($frameLength > 0) {
543+
/** @psalm-suppress PossiblyInvalidArrayAccess */
537544
['key' => $key, 'value' => $value] = \unpack("nkey/Nvalue", $frameBuffer);
538545

539546
if ($value < 0) {
@@ -581,6 +588,7 @@ private function parseGoAway(string $frameBuffer, int $frameLength, int $streamI
581588
$this->throwInvalidNonZeroStreamIdError();
582589
}
583590

591+
/** @psalm-suppress PossiblyInvalidArrayAccess */
584592
['last' => $lastId, 'error' => $error] = \unpack("Nlast/Nerror", $frameBuffer);
585593

586594
$this->handler->handleShutdown($lastId & 0x7fffffff, $error, \substr($frameBuffer, 8));
@@ -593,6 +601,7 @@ private function parseWindowUpdate(string $frameBuffer, int $frameLength, int $s
593601
$this->throwInvalidFrameSizeError();
594602
}
595603

604+
/** @psalm-suppress PossiblyInvalidArrayAccess */
596605
$windowSize = \unpack('N', $frameBuffer)[1];
597606

598607
if ($windowSize === 0) {

src/HttpStatus.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,12 @@ public static function isServerError(int $code): bool
178178
return $code >= 500 && $code < 600;
179179
}
180180

181-
// @codeCoverageIgnoreStart
181+
/**
182+
* @codeCoverageIgnore
183+
* @psalm-suppress UnusedConstructor
184+
*/
182185
private function __construct()
183186
{
184187
// forbid instances
185188
}
186-
// @codeCoverageIgnoreEnd
187189
}

0 commit comments

Comments
 (0)