Skip to content

Commit 2f9c8d4

Browse files
committed
Fixes
1 parent 151896f commit 2f9c8d4

10 files changed

+12
-24
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,8 +1556,7 @@ private function processStmtNode(
15561556
}
15571557
$throwNode = $throwPoint->getNode();
15581558
if (
1559-
!$throwNode instanceof Throw_
1560-
&& !$throwNode instanceof Expr\Throw_
1559+
!$throwNode instanceof Expr\Throw_
15611560
&& !($throwNode instanceof Node\Stmt\Expression && $throwNode->expr instanceof Expr\Throw_)
15621561
) {
15631562
$onlyExplicitIsThrow = false;
@@ -1858,9 +1857,6 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
18581857
if ($const->namespacedName !== null) {
18591858
$constantName = new Name\FullyQualified($const->namespacedName->toString());
18601859
} else {
1861-
if ($const->name->toString() === '') {
1862-
throw new ShouldNotHappenException('Constant cannot have a empty name');
1863-
}
18641860
$constantName = new Name\FullyQualified($const->name->toString());
18651861
}
18661862
$scope = $scope->assignExpression(new ConstFetch($constantName), $scope->getType($const->value), $scope->getNativeType($const->value));

src/Parser/PhpParserFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use PhpParser\ParserAbstract;
99
use PHPStan\Php\PhpVersion;
1010

11-
class PhpParserFactory
11+
final class PhpParserFactory
1212
{
1313

1414
public function __construct(private Lexer $lexer, private PhpVersion $phpVersion)

src/Parser/StandaloneThrowExprVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use PhpParser\Node;
66
use PhpParser\NodeVisitorAbstract;
77

8-
class StandaloneThrowExprVisitor extends NodeVisitorAbstract
8+
final class StandaloneThrowExprVisitor extends NodeVisitorAbstract
99
{
1010

1111
public const ATTRIBUTE_NAME = 'standaloneThrowExpr';

src/Rules/ClassForbiddenNameCheck.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function checkClassNames(array $pairs): array
7373
$projectName,
7474
$className,
7575
))
76-
->line($pair->getNode()->getLine())
76+
->line($pair->getNode()->getStartLine())
7777
->identifier('class.prefixed')
7878
->nonIgnorable();
7979

src/Rules/FunctionDefinitionCheck.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function checkAnonymousFunction(
204204
foreach ($returnType->getReferencedClasses() as $returnTypeClass) {
205205
if (!$this->reflectionProvider->hasClass($returnTypeClass)) {
206206
$errors[] = RuleErrorBuilder::message(sprintf($returnMessage, $returnTypeClass))
207-
->line($returnTypeNode->getLine())
207+
->line($returnTypeNode->getStartLine())
208208
->identifier('class.notFound')
209209
->build();
210210
continue;

src/Rules/Names/UsedNamesRule.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use PhpParser\Node\Stmt\Namespace_;
1111
use PhpParser\Node\Stmt\Trait_;
1212
use PhpParser\Node\Stmt\Use_;
13-
use PhpParser\Node\Stmt\UseUse;
1413
use PHPStan\Analyser\Scope;
1514
use PHPStan\Node\FileNode;
1615
use PHPStan\Rules\IdentifierRuleError;
@@ -100,7 +99,7 @@ private function findErrorsForNode(Node $node, string $namespace, array &$usedNa
10099
$namespace !== '' ? $namespace . '\\' . $node->name->toString() : $node->name->toString(),
101100
))
102101
->identifier(sprintf('%s.nameInUse', $type))
103-
->line($node->getLine())
102+
->line($node->getStartLine())
104103
->nonIgnorable()
105104
->build(),
106105
];
@@ -113,7 +112,7 @@ private function findErrorsForNode(Node $node, string $namespace, array &$usedNa
113112
}
114113

115114
/**
116-
* @param UseUse[] $uses
115+
* @param Node\UseItem[] $uses
117116
* @param array<string, string[]> $usedNames
118117
* @return list<IdentifierRuleError>
119118
*/
@@ -132,7 +131,7 @@ private function findErrorsInUses(array $uses, string $useGroupPrefix, string $l
132131
$use->getAlias()->toString(),
133132
))
134133
->identifier('use.nameInUse')
135-
->line($use->getLine())
134+
->line($use->getStartLine())
136135
->nonIgnorable()
137136
->build();
138137
continue;
@@ -142,7 +141,7 @@ private function findErrorsInUses(array $uses, string $useGroupPrefix, string $l
142141
return $errors;
143142
}
144143

145-
private function shouldBeIgnored(Use_|GroupUse|UseUse $use): bool
144+
private function shouldBeIgnored(Use_|GroupUse|Node\UseItem $use): bool
146145
{
147146
return in_array($use->type, [Use_::TYPE_FUNCTION, Use_::TYPE_CONSTANT], true);
148147
}

src/Rules/PhpDoc/PhpDocLineHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static function detectLine(PhpParserNode $node, PhpDocNode $phpDocNode):
1919
$phpDoc = $node->getDocComment();
2020

2121
if ($phpDocTagLine === null || $phpDoc === null) {
22-
return $node->getLine();
22+
return $node->getStartLine();
2323
}
2424

2525
return $phpDoc->getStartLine() + $phpDocTagLine - 1;

src/Rules/Variables/ParameterOutExecutionEndTypeRule.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ public function processNode(Node $node, Scope $scope): array
5757
return [];
5858
}
5959
}
60-
if ($endNode instanceof Node\Stmt\Throw_) {
61-
return [];
62-
}
6360

6461
$variant = ParametersAcceptorSelector::selectSingle($inFunction->getVariants());
6562
$parameters = $variant->getParameters();

src/Testing/TypeInferenceTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public static function gatherAssertTypes(string $file): array
178178
'Expected type must be a literal string, %s given in %s on line %d.',
179179
$expectedType->describe(VerbosityLevel::precise()),
180180
$relativePathHelper->getRelativePath($file),
181-
$node->getLine(),
181+
$node->getStartLine(),
182182
));
183183
}
184184
$actualType = $scope->getType($node->getArgs()[1]->value);
@@ -190,7 +190,7 @@ public static function gatherAssertTypes(string $file): array
190190
'Expected type must be a literal string, %s given in %s on line %d.',
191191
$expectedType->describe(VerbosityLevel::precise()),
192192
$relativePathHelper->getRelativePath($file),
193-
$node->getLine(),
193+
$node->getStartLine(),
194194
));
195195
}
196196

src/Type/FileTypeMapper.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,6 @@ function (Node $node) use ($fileName, $lookForTrait, $phpDocNodeMap, &$traitFoun
482482
$functionName = $functionStack[count($functionStack) - 1] ?? null;
483483
$nameScopeKey = $this->getNameScopeKey($originalClassFileName, $className, $lookForTrait, $functionName);
484484

485-
if ($namespace === '') {
486-
throw new ShouldNotHappenException('Namespace cannot be empty.');
487-
}
488-
489485
if ($node instanceof Node\Stmt\ClassLike || $node instanceof Node\Stmt\ClassMethod || $node instanceof Node\Stmt\Function_) {
490486
if (array_key_exists($nameScopeKey, $phpDocNodeMap)) {
491487
$phpDocNode = $phpDocNodeMap[$nameScopeKey];

0 commit comments

Comments
 (0)