Skip to content

Commit 076a9f1

Browse files
committed
linting + stanning
1 parent 1fe4cd4 commit 076a9f1

File tree

7 files changed

+2190
-2196
lines changed

7 files changed

+2190
-2196
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"phpstan/phpstan-phpunit": "^1.1",
1515
"phpstan/phpstan-strict-rules": "^1.0",
1616
"phpunit/phpunit": "^9.5",
17-
"symfony/process": "^5.2"
17+
"symfony/process": "^5.2",
1818
},
1919
"config": {
2020
"platform": {

src/Ast/Type/ArrayShapeNode.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
namespace PHPStan\PhpDocParser\Ast\Type;
44

55
use PHPStan\PhpDocParser\Ast\NodeAttributes;
6-
use function implode;
6+
use function array_filter;
7+
use function count;
78

89
class ArrayShapeNode implements TypeNode
910
{
@@ -13,7 +14,7 @@ class ArrayShapeNode implements TypeNode
1314

1415
use NodeAttributes;
1516

16-
/** @var ArrayShapeItemNode[] */
17+
/** @var array<ArrayShapeItemNode|CommentNode|IdentifierTypeNode> */
1718
public $items;
1819

1920
/** @var bool */
@@ -23,7 +24,7 @@ class ArrayShapeNode implements TypeNode
2324
public $kind;
2425

2526
/**
26-
* @param ArrayShapeItemNode[] $items
27+
* @param array<ArrayShapeItemNode|CommentNode|IdentifierTypeNode> $items
2728
* @param self::KIND_* $kind
2829
*/
2930
public function __construct(array $items, bool $sealed = true, string $kind = self::KIND_ARRAY)
@@ -36,8 +37,11 @@ public function __construct(array $items, bool $sealed = true, string $kind = se
3637
/**
3738
* @return array<ArrayShapeItemNode>
3839
*/
39-
public function items(): array {
40-
return array_filter($this->items, function ($item) { return $item instanceof ArrayShapeItemNode; });
40+
public function items(): array
41+
{
42+
return array_filter($this->items, static function ($item) {
43+
return $item instanceof ArrayShapeItemNode;
44+
});
4145
}
4246

4347
public function __toString(): string
@@ -49,17 +53,17 @@ public function __toString(): string
4953
}
5054

5155
$res = $this->kind . '{';
52-
foreach($items as $idx => $item) {
56+
foreach ($items as $idx => $item) {
5357
$res .= $item;
5458

55-
if($item instanceof ArrayShapeItemNode && $idx < count($items) - 1) {
56-
$res .= ', ';
59+
if (!($item instanceof ArrayShapeItemNode) || $idx >= count($items) - 1) {
60+
continue;
5761
}
5862

59-
}
60-
$res .= '}';
63+
$res .= ', ';
6164

62-
return $res;
65+
}
66+
return $res . '}';
6367
}
6468

6569
}

src/Parser/TokenIterator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,11 @@ public function joinUntil(int ...$tokenType): string
242242
public function next(bool $skipIrrelevant = true): void
243243
{
244244
$this->index++;
245-
$skipIrrelevant && $this->skipIrrelevantTokens();
245+
if (!$skipIrrelevant) {
246+
return;
247+
}
248+
249+
$this->skipIrrelevantTokens();
246250
}
247251

248252

src/Parser/TypeParser.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -752,11 +752,11 @@ private function parseArrayShape(TokenIterator $tokens, Ast\Type\TypeNode $type,
752752
$tokens->pushSavePoint();
753753
$tokens->next();
754754
$tab = "\t";
755-
if($tokens->currentTokenType() == Lexer::TOKEN_CLOSE_CURLY_BRACKET) {
755+
if ($tokens->currentTokenType() === Lexer::TOKEN_CLOSE_CURLY_BRACKET) {
756756
$tab = '';
757757
}
758758
$tokens->rollback();
759-
if($tokens->currentTokenType() == Lexer::TOKEN_PHPDOC_EOL) {
759+
if ($tokens->currentTokenType() === Lexer::TOKEN_PHPDOC_EOL) {
760760
$startLine = $tokens->currentTokenLine();
761761
$startIndex = $tokens->currentTokenIndex();
762762
$items[] = $this->enrichWithAttributes(
@@ -782,7 +782,7 @@ private function parseArrayShape(TokenIterator $tokens, Ast\Type\TypeNode $type,
782782
$items[] = $this->parseSimpleComment($tokens);
783783
}
784784

785-
if($tokens->currentTokenType() == Lexer::TOKEN_PHPDOC_EOL) {
785+
if ($tokens->currentTokenType() === Lexer::TOKEN_PHPDOC_EOL) {
786786
$startLine = $tokens->currentTokenLine();
787787
$startIndex = $tokens->currentTokenIndex();
788788
$items[] = $this->enrichWithAttributes(
@@ -812,7 +812,7 @@ private function parseSimpleComment(TokenIterator $tokens): Ast\Type\CommentNode
812812

813813
$text = '';
814814

815-
while($tokens->currentTokenType() != Lexer::TOKEN_PHPDOC_EOL) {
815+
while ($tokens->currentTokenType() !== Lexer::TOKEN_PHPDOC_EOL) {
816816
$text .= $tokens->currentTokenValue();
817817
$tokens->next(false);
818818
}

src/Printer/Printer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ private function printTagValue(PhpDocTagValueNode $node): string
339339
private function printType(TypeNode $node): string
340340
{
341341
if ($node instanceof ArrayShapeNode) {
342-
return (string)$node;
342+
return (string) $node;
343343
}
344344
if ($node instanceof ArrayShapeItemNode) {
345345
if ($node->keyName !== null) {

0 commit comments

Comments
 (0)