use TheCodingMachine\PHPStan\Utils\PrefixGenerator;
13
14
/**
15
* A switch statement must always contain a "default" statement.
16
*/
17
class SwitchMustContainDefaultRule implements Rule
18
{
19
public function getNodeType(): string
20
{
21
return Switch_::class;
22
}
23
24
/**
25
* @param Switch_ $switch
26
* @param \PHPStan\Analyser\Scope $scope
27
* @return string[]
28
*/
29
public function processNode(Node $switch, Scope $scope): array
30
{
31
$errors = [];
32
$defaultFound = false;
33
foreach ($switch->cases as $case) {
34
if ($case->cond === null) {
35
$defaultFound = true;
36
break;
37
}
38
}
39
40
if (!$defaultFound) {
41
$errors[] = sprintf(PrefixGenerator::generatePrefix($scope).'switch statement does not have a "default" case. If your code is supposed to enter at least one "case" or another, consider adding a "default" case that throws an exception.');