Skip to content

Commit

Permalink
Merge pull request #881 from ergebnis/fix/should-not-happen
Browse files Browse the repository at this point in the history
Fix: Remove conditions that should never evaluate to true
  • Loading branch information
localheinz authored Dec 1, 2024
2 parents 38fa87c + 3f886f2 commit b103a80
Show file tree
Hide file tree
Showing 19 changed files with 0 additions and 163 deletions.
1 change: 0 additions & 1 deletion composer-require-checker.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"PHPStan\\Rules\\Rule",
"PHPStan\\Rules\\RuleError",
"PHPStan\\Rules\\RuleErrorBuilder",
"PHPStan\\ShouldNotHappenException",
"self",
"string",
"true"
Expand Down
9 changes: 0 additions & 9 deletions src/Classes/FinalRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Rules;
use PHPStan\ShouldNotHappenException;

/**
* @implements Rules\Rule<Node\Stmt\Class_>
Expand Down Expand Up @@ -74,14 +73,6 @@ public function processNode(
Node $node,
Analyser\Scope $scope
): array {
if (!$node instanceof Node\Stmt\Class_) {
throw new ShouldNotHappenException(\sprintf(
'Expected node to be instance of "%s", but got instance of "%s" instead.',
Node\Stmt\Class_::class,
\get_class($node),
));
}

if (!isset($node->namespacedName)) {
return [];
}
Expand Down
9 changes: 0 additions & 9 deletions src/Classes/NoExtendsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Rules;
use PHPStan\ShouldNotHappenException;

/**
* @implements Rules\Rule<Node\Stmt\Class_>
Expand Down Expand Up @@ -59,14 +58,6 @@ public function processNode(
Node $node,
Analyser\Scope $scope
): array {
if (!$node instanceof Node\Stmt\Class_) {
throw new ShouldNotHappenException(\sprintf(
'Expected node to be instance of "%s", but got instance of "%s" instead.',
Node\Stmt\Class_::class,
\get_class($node),
));
}

if (!$node->extends instanceof Node\Name) {
return [];
}
Expand Down
9 changes: 0 additions & 9 deletions src/Classes/PHPUnit/Framework/TestCaseWithSuffixRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use PHPStan\Analyser;
use PHPStan\Reflection;
use PHPStan\Rules;
use PHPStan\ShouldNotHappenException;

/**
* @implements Rules\Rule<Node\Stmt\Class_>
Expand Down Expand Up @@ -47,14 +46,6 @@ public function processNode(
Node $node,
Analyser\Scope $scope
): array {
if (!$node instanceof Node\Stmt\Class_) {
throw new ShouldNotHappenException(\sprintf(
'Expected node to be instance of "%s", but got instance of "%s" instead.',
Node\Stmt\Class_::class,
\get_class($node),
));
}

if ($node->isAbstract()) {
return [];
}
Expand Down
9 changes: 0 additions & 9 deletions src/Closures/NoNullableReturnTypeDeclarationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Rules;
use PHPStan\ShouldNotHappenException;

/**
* @implements Rules\Rule<Node\Expr\Closure>
Expand All @@ -33,14 +32,6 @@ public function processNode(
Node $node,
Analyser\Scope $scope
): array {
if (!$node instanceof Node\Expr\Closure) {
throw new ShouldNotHappenException(\sprintf(
'Expected node to be instance of "%s", but got instance of "%s" instead.',
Node\Expr\Closure::class,
\get_class($node),
));
}

if (!self::hasNullableReturnType($node)) {
return [];
}
Expand Down
9 changes: 0 additions & 9 deletions src/Closures/NoParameterWithNullDefaultValueRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Rules;
use PHPStan\ShouldNotHappenException;

/**
* @implements Rules\Rule<Node\Expr\Closure>
Expand All @@ -33,14 +32,6 @@ public function processNode(
Node $node,
Analyser\Scope $scope
): array {
if (!$node instanceof Node\Expr\Closure) {
throw new ShouldNotHappenException(\sprintf(
'Expected node to be instance of "%s", but got instance of "%s" instead.',
Node\Expr\Closure::class,
\get_class($node),
));
}

if (0 === \count($node->params)) {
return [];
}
Expand Down
9 changes: 0 additions & 9 deletions src/Closures/NoParameterWithNullableTypeDeclarationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Rules;
use PHPStan\ShouldNotHappenException;

/**
* @implements Rules\Rule<Node\Expr\Closure>
Expand All @@ -33,14 +32,6 @@ public function processNode(
Node $node,
Analyser\Scope $scope
): array {
if (!$node instanceof Node\Expr\Closure) {
throw new ShouldNotHappenException(\sprintf(
'Expected node to be instance of "%s", but got instance of "%s" instead.',
Node\Expr\Closure::class,
\get_class($node),
));
}

if (0 === \count($node->params)) {
return [];
}
Expand Down
9 changes: 0 additions & 9 deletions src/Expressions/NoCompactRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Rules;
use PHPStan\ShouldNotHappenException;

/**
* @implements Rules\Rule<Node\Expr\FuncCall>
Expand All @@ -33,14 +32,6 @@ public function processNode(
Node $node,
Analyser\Scope $scope
): array {
if (!$node instanceof Node\Expr\FuncCall) {
throw new ShouldNotHappenException(\sprintf(
'Expected node to be instance of "%s", but got instance of "%s" instead.',
Node\Expr\FuncCall::class,
\get_class($node),
));
}

if (!$node->name instanceof Node\Name) {
return [];
}
Expand Down
9 changes: 0 additions & 9 deletions src/Files/DeclareStrictTypesRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use PHPStan\Analyser;
use PHPStan\Node\FileNode;
use PHPStan\Rules;
use PHPStan\ShouldNotHappenException;

/**
* @implements Rules\Rule<FileNode>
Expand All @@ -34,14 +33,6 @@ public function processNode(
Node $node,
Analyser\Scope $scope
): array {
if (!$node instanceof FileNode) {
throw new ShouldNotHappenException(\sprintf(
'Expected node to be instance of "%s", but got instance of "%s" instead.',
FileNode::class,
\get_class($node),
));
}

$nodes = $node->getNodes();

if (0 === \count($nodes)) {
Expand Down
9 changes: 0 additions & 9 deletions src/Functions/NoNullableReturnTypeDeclarationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Rules;
use PHPStan\ShouldNotHappenException;

/**
* @implements Rules\Rule<Node\Stmt\Function_>
Expand All @@ -33,14 +32,6 @@ public function processNode(
Node $node,
Analyser\Scope $scope
): array {
if (!$node instanceof Node\Stmt\Function_) {
throw new ShouldNotHappenException(\sprintf(
'Expected node to be instance of "%s", but got instance of "%s" instead.',
Node\Stmt\Function_::class,
\get_class($node),
));
}

if (!isset($node->namespacedName)) {
return [];
}
Expand Down
9 changes: 0 additions & 9 deletions src/Functions/NoParameterWithNullDefaultValueRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Rules;
use PHPStan\ShouldNotHappenException;

/**
* @implements Rules\Rule<Node\Stmt\Function_>
Expand All @@ -33,14 +32,6 @@ public function processNode(
Node $node,
Analyser\Scope $scope
): array {
if (!$node instanceof Node\Stmt\Function_) {
throw new ShouldNotHappenException(\sprintf(
'Expected node to be instance of "%s", but got instance of "%s" instead.',
Node\Stmt\Function_::class,
\get_class($node),
));
}

if (0 === \count($node->params)) {
return [];
}
Expand Down
9 changes: 0 additions & 9 deletions src/Functions/NoParameterWithNullableTypeDeclarationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use PhpParser\Node;
use PHPStan\Analyser;
use PHPStan\Rules;
use PHPStan\ShouldNotHappenException;

/**
* @implements Rules\Rule<Node\Stmt\Function_>
Expand All @@ -33,14 +32,6 @@ public function processNode(
Node $node,
Analyser\Scope $scope
): array {
if (!$node instanceof Node\Stmt\Function_) {
throw new ShouldNotHappenException(\sprintf(
'Expected node to be instance of "%s", but got instance of "%s" instead.',
Node\Stmt\Function_::class,
\get_class($node),
));
}

if (0 === \count($node->params)) {
return [];
}
Expand Down
9 changes: 0 additions & 9 deletions src/Methods/FinalInAbstractClassRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use PHPStan\Analyser;
use PHPStan\Reflection;
use PHPStan\Rules;
use PHPStan\ShouldNotHappenException;

/**
* @implements Rules\Rule<Node\Stmt\ClassMethod>
Expand All @@ -34,14 +33,6 @@ public function processNode(
Node $node,
Analyser\Scope $scope
): array {
if (!$node instanceof Node\Stmt\ClassMethod) {
throw new ShouldNotHappenException(\sprintf(
'Expected node to be instance of "%s", but got instance of "%s" instead.',
Node\Stmt\ClassMethod::class,
\get_class($node),
));
}

/** @var Reflection\ClassReflection $containingClass */
$containingClass = $scope->getClassReflection();

Expand Down
9 changes: 0 additions & 9 deletions src/Methods/NoConstructorParameterWithDefaultValueRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use PHPStan\Analyser;
use PHPStan\Reflection;
use PHPStan\Rules;
use PHPStan\ShouldNotHappenException;

/**
* @implements Rules\Rule<Node\Stmt\ClassMethod>
Expand All @@ -34,14 +33,6 @@ public function processNode(
Node $node,
Analyser\Scope $scope
): array {
if (!$node instanceof Node\Stmt\ClassMethod) {
throw new ShouldNotHappenException(\sprintf(
'Expected node to be instance of "%s", but got instance of "%s" instead.',
Node\Stmt\ClassMethod::class,
\get_class($node),
));
}

if ('__construct' !== $node->name->toLowerString()) {
return [];
}
Expand Down
9 changes: 0 additions & 9 deletions src/Methods/NoNullableReturnTypeDeclarationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use PHPStan\Analyser;
use PHPStan\Reflection;
use PHPStan\Rules;
use PHPStan\ShouldNotHappenException;

/**
* @implements Rules\Rule<Node\Stmt\ClassMethod>
Expand All @@ -34,14 +33,6 @@ public function processNode(
Node $node,
Analyser\Scope $scope
): array {
if (!$node instanceof Node\Stmt\ClassMethod) {
throw new ShouldNotHappenException(\sprintf(
'Expected node to be instance of "%s", but got instance of "%s" instead.',
Node\Stmt\ClassMethod::class,
\get_class($node),
));
}

if (!self::hasNullableReturnType($node)) {
return [];
}
Expand Down
9 changes: 0 additions & 9 deletions src/Methods/NoParameterWithContainerTypeDeclarationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use PHPStan\Analyser;
use PHPStan\Reflection;
use PHPStan\Rules;
use PHPStan\ShouldNotHappenException;

/**
* @implements Rules\Rule<Node\Stmt\ClassMethod>
Expand Down Expand Up @@ -67,14 +66,6 @@ public function processNode(
Node $node,
Analyser\Scope $scope
): array {
if (!$node instanceof Node\Stmt\ClassMethod) {
throw new ShouldNotHappenException(\sprintf(
'Expected node to be instance of "%s", but got instance of "%s" instead.',
Node\Stmt\ClassMethod::class,
\get_class($node),
));
}

if (0 === \count($this->interfacesImplementedByContainers)) {
return [];
}
Expand Down
9 changes: 0 additions & 9 deletions src/Methods/NoParameterWithNullDefaultValueRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use PHPStan\Analyser;
use PHPStan\Reflection;
use PHPStan\Rules;
use PHPStan\ShouldNotHappenException;

/**
* @implements Rules\Rule<Node\Stmt\ClassMethod>
Expand All @@ -34,14 +33,6 @@ public function processNode(
Node $node,
Analyser\Scope $scope
): array {
if (!$node instanceof Node\Stmt\ClassMethod) {
throw new ShouldNotHappenException(\sprintf(
'Expected node to be instance of "%s", but got instance of "%s" instead.',
Node\Stmt\ClassMethod::class,
\get_class($node),
));
}

if (0 === \count($node->params)) {
return [];
}
Expand Down
9 changes: 0 additions & 9 deletions src/Methods/NoParameterWithNullableTypeDeclarationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use PHPStan\Analyser;
use PHPStan\Reflection;
use PHPStan\Rules;
use PHPStan\ShouldNotHappenException;

/**
* @implements Rules\Rule<Node\Stmt\ClassMethod>
Expand All @@ -34,14 +33,6 @@ public function processNode(
Node $node,
Analyser\Scope $scope
): array {
if (!$node instanceof Node\Stmt\ClassMethod) {
throw new ShouldNotHappenException(\sprintf(
'Expected node to be instance of "%s", but got instance of "%s" instead.',
Node\Stmt\ClassMethod::class,
\get_class($node),
));
}

if (0 === \count($node->params)) {
return [];
}
Expand Down
Loading

0 comments on commit b103a80

Please sign in to comment.