1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Analyser;
4:
5: use PHPStan\AnalysedCodeException;
6: use PHPStan\Turbo\ReferencedByTurboExtension;
7: use function sprintf;
8:
9: /**
10: * @api
11: *
12: * Unchecked exception thrown from `PHPStan\Analyser\Scope::getVariableType()`
13: * in case the user doesn't check `hasVariableType()` is not `no()`.
14: */
15: #[ReferencedByTurboExtension(key: 'undefinedVariableException')]
16: final class UndefinedVariableException extends AnalysedCodeException
17: {
18:
19: public function __construct(private Scope $scope, private string $variableName)
20: {
21: parent::__construct(sprintf('Undefined variable: $%s', $variableName));
22: }
23:
24: public function getScope(): Scope
25: {
26: return $this->scope;
27: }
28:
29: public function getVariableName(): string
30: {
31: return $this->variableName;
32: }
33:
34: public function getTip(): ?string
35: {
36: return null;
37: }
38:
39: }
40: