Skip to content

Commit e104033

Browse files
committedSep 26, 2024
Fix PHPStan failures
1 parent 426fd7a commit e104033

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed
 

‎phpstan.neon

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ parameters:
1111
level: 8
1212
ignoreErrors:
1313
- '#^Dynamic call to static method PHPUnit\\Framework\\Assert#'
14+
-
15+
identifier: return.unusedType
16+
path: tests/*

‎src/Ast/NodeVisitor/CloningVisitor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
final class CloningVisitor extends AbstractNodeVisitor
1010
{
1111

12-
public function enterNode(Node $originalNode)
12+
public function enterNode(Node $originalNode): Node
1313
{
1414
$node = clone $originalNode;
1515
$node->setAttribute(Attribute::ORIGINAL_NODE, $originalNode);

‎src/Parser/PhpDocParser.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use PHPStan\PhpDocParser\ParserConfig;
1414
use PHPStan\ShouldNotHappenException;
1515
use function array_key_exists;
16-
use function array_values;
1716
use function count;
1817
use function rtrim;
1918
use function str_replace;
@@ -120,7 +119,7 @@ public function parse(TokenIterator $tokens): Ast\PhpDoc\PhpDocNode
120119
return $this->enrichWithAttributes($tokens, new Ast\PhpDoc\PhpDocNode([$this->enrichWithAttributes($tokens, $tag, $startLine, $startIndex)]), 1, 0);
121120
}
122121

123-
return $this->enrichWithAttributes($tokens, new Ast\PhpDoc\PhpDocNode(array_values($children)), 1, 0);
122+
return $this->enrichWithAttributes($tokens, new Ast\PhpDoc\PhpDocNode($children), 1, 0);
124123
}
125124

126125

‎src/Printer/Printer.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,11 @@ private function printArrayFormatPreserving(array $nodes, array $originalNodes,
554554
if (!$newNode instanceof Node || !$originalNode instanceof Node) {
555555
return null;
556556
}
557+
558+
/** @var int $itemStartPos */
557559
$itemStartPos = $originalNode->getAttribute(Attribute::START_INDEX);
560+
561+
/** @var int $itemEndPos */
558562
$itemEndPos = $originalNode->getAttribute(Attribute::END_INDEX);
559563
if ($itemStartPos < 0 || $itemEndPos < 0 || $itemStartPos < $tokenIndex) {
560564
throw new LogicException();
@@ -617,6 +621,7 @@ private function printArrayFormatPreserving(array $nodes, array $originalNodes,
617621
continue;
618622
}
619623

624+
/** @var int $itemEndPos */
620625
$itemEndPos = $tokenIndex - 1;
621626
if ($insertNewline) {
622627
$result .= $insertStr . sprintf('%s%s*%s', $originalTokens->getDetectedNewline() ?? "\n", $beforeAsteriskIndent, $afterAsteriskIndent);
@@ -642,7 +647,10 @@ private function printArrayFormatPreserving(array $nodes, array $originalNodes,
642647
return null;
643648
}
644649

650+
/** @var int $itemStartPos */
645651
$itemStartPos = $originalNode->getAttribute(Attribute::START_INDEX);
652+
653+
/** @var int $itemEndPos */
646654
$itemEndPos = $originalNode->getAttribute(Attribute::END_INDEX);
647655
if ($itemStartPos < 0 || $itemEndPos < 0) {
648656
throw new LogicException();
@@ -702,7 +710,7 @@ private function printArrayFormatPreserving(array $nodes, array $originalNodes,
702710
}
703711

704712
/**
705-
* @param Node[] $nodes
713+
* @param array<Node|null> $nodes
706714
* @return array{bool, string, string}
707715
*/
708716
private function isMultiline(int $initialIndex, array $nodes, TokenIterator $originalTokens): array

‎tests/PHPStan/Printer/IntegrationPrinterWithPhpParserTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPStan\PhpDocParser\Printer;
44

5+
use LogicException;
56
use PhpParser\Comment\Doc;
67
use PhpParser\Node as PhpNode;
78
use PhpParser\NodeTraverser as PhpParserNodeTraverser;
@@ -78,8 +79,10 @@ public function testPrint(string $file, string $expectedFile, NodeVisitor $visit
7879
$this->fail('Could not read ' . $file);
7980
}
8081

81-
/** @var PhpNode[] $oldStmts */
8282
$oldStmts = $phpParser->parse($fileContents);
83+
if ($oldStmts === null) {
84+
throw new LogicException();
85+
}
8386
$oldTokens = $phpParser->getTokens();
8487

8588
$phpTraverser2 = new PhpParserNodeTraverser();

0 commit comments

Comments
 (0)
Failed to load comments.