Repository: spaze/phpstan-disallowed-calls (php)

Issue:
Add support enum dynamic constant
PHP: 8.3.1
When i use dynamic constants for enum. 
For example: 
```php
<?php declare(strict_types = 1);

enum Foo
{
	case Bar;
}

$variable = 'Bar';
$const = Foo::{$variable};
```
https://phpstan.org/r/fc74146a-7438-4cd8-ae4c-56c8db97dad5

<details>
<summary>Screenshot</summary>

![Screenshot 2024-01-21 at 4 04 15 PM](https://github.com/spaze/phpstan-disallowed-calls/assets/34651075/d73de7d4-73a8-4082-8362-8c0a14c04878)
</details>


I catch error 
```
Uncaught PHPStan\ShouldNotHappenException: $node->name should be PhpParser\Node\Identifier but is PhpParser\Node\Expr\PropertyFetch in /api/vendor/spaze/phpstan-disallowed-calls/src/Usages/ClassConstantUsages.php: 84
#0 phar:///api/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(107): Spaze\PHPStan\Rules\Disallowed\Usages\ClassConstantUsages->processNode(Object(PhpParser\Node\Expr\ClassConstFetch), Object(PHPStan\Analyser\MutatingScope))
#1 phar:///api/vendor/phpstan/phpstan/phpstan.phar/src/Node/ClassStatementsGatherer.php(108): PHPStan\Analyser\FileAnalyser->PHPStan\Analyser\{closure}(Object(PhpParser\Node\Expr\ClassConstFetch), Object(PHPStan\Analyser\MutatingScope))
#2 phar:///api/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(567): PHPStan\Node\ClassStatementsGatherer-> __ invoke(Object(PhpParser\Node\Expr\ClassConstFetch), Object(PHPStan\Analyser\MutatingScope)
#3 phar:///api/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(2653): PHPStan\Analyser\NodeScopeResolver: : PHPStan\Analyser\{closure}(Object(PhpParser\Node\Expr\ClassConstFetch), Object(PHPStan\Analyser\MutatingScope))
#4 phar:///api/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1592): PHPStan\Analyser\NodeScopeResolver->callNodeCallbackWithExpression(Object(Closure), Object(PhpParser\Node\Expr\ClassConstFetch), Object(PHPStan\Analyser\MutatingScope), ObjectPHPStan\Analyser\ExpressionContext))
#5 phar:///api/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(605): PHPStan\Analyser\NodeScopeResolver->processExprNode(Object(PhpParser\Node\Stmt\Return_), Object(PhpParser\Node\Expr\ClassConstFetch), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\ExpressionContext))
#6 phar:///api/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(401): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Return_), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#7 phar:///api/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(566): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\ClassMethod), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#8 phar:///api/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(401): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\ClassMethod), Object(PHPStan\Analyser\MutatingScope), Object(PHPStan\Node\ClassStatementsGatherer), Object(PHPStan\Analyser\StatementContext))
#9 phar:///api/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(668): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Class_), Array, Object(PHPStan\Analyser\MutatingScope), Object(PHPStan\Node\ClassStatementsGatherer), Object(PHPStan\Analyser\StatementContext))
```

<details>
<summary>Screenshot</summary>

![Screenshot 2024-01-21 at 4 02 54 PM](https://github.com/spaze/phpstan-disallowed-calls/assets/34651075/6211a05c-870c-4cb5-83fc-7f4ae7dec17b)
</details>


Pull request description:
Support all Expr nodes when in dynamic constant fetch
Because besides `Variable`, there's also
- `PropertyFetch` (`Foo::{$this->type}`)
- `StaticPropertyFetch` (`Foo::{Foo::$bar}`)
- and more.

Fix #241, again.

Patch:
diff --git a/src/Usages/ClassConstantUsages.php b/src/Usages/ClassConstantUsages.php
index 841a24d..f29826e 100644
--- a/src/Usages/ClassConstantUsages.php
+++ b/src/Usages/ClassConstantUsages.php
@@ -5,7 +5,6 @@ namespace Spaze\PHPStan\Rules\Disallowed\Usages;
 
 use PhpParser\Node;
 use PhpParser\Node\Expr\ClassConstFetch;
-use PhpParser\Node\Expr\Variable;
 use PhpParser\Node\Identifier;
 use PHPStan\Analyser\Scope;
 use PHPStan\Rules\Rule;
@@ -85,18 +84,15 @@ class ClassConstantUsages implements Rule
 		if ($node->name instanceof Identifier) {
 			return $this->getConstantRuleErrors($scope, (string)$node->name, $this->typeResolver->getType($node->class, $scope));
 		}
-		if ($node->name instanceof Variable) {
-			$type = $scope->getType($node->name);
-			$errors = [];
-			foreach ($type->getConstantStrings() as $constantString) {
-				$errors = array_merge(
-					$errors,
-					$this->getConstantRuleErrors($scope, $constantString->getValue(), $this->typeResolver->getType($node->class, $scope))
-				);
-			}
-			return $errors;
+		$type = $scope->getType($node->name);
+		$errors = [];
+		foreach ($type->getConstantStrings() as $constantString) {
+			$errors = array_merge(
+				$errors,
+				$this->getConstantRuleErrors($scope, $constantString->getValue(), $this->typeResolver->getType($node->class, $scope))
+			);
 		}
-		throw new ShouldNotHappenException(sprintf('$node->name should be %s but is %s', Identifier::class, get_class($node->name)));
+		return $errors;
 	}
 
 


Test patch:
diff --git a/tests/src/Blade.php b/tests/src/Blade.php
index 05faded..3c0f7ba 100644
--- a/tests/src/Blade.php
+++ b/tests/src/Blade.php
@@ -14,6 +14,10 @@ class Blade
 
 	public const MOVIE = Blade::WESLEY;
 
+	public static $runner = 'RUNNER';
+
+	public $deckard = 'DECKARD';
+
 
 	public function runner(int $everything = 0, bool $yes = false, string $roland = '303'): void
 	{
diff --git a/tests/src/disallowed/constantDynamicUsages.php b/tests/src/disallowed/constantDynamicUsages.php
index 45c5f4d..e617c05 100644
--- a/tests/src/disallowed/constantDynamicUsages.php
+++ b/tests/src/disallowed/constantDynamicUsages.php
@@ -8,3 +8,8 @@ $kind = 'RUNNER';
 echo Blade::{$kind};
 /** @var 'DECKARD'|'MOVIE'|'RUNNER' $kind2 */
 echo Blade::{$kind2};
+
+$blade = new Blade();
+echo Blade::{Blade::$runner};
+echo Blade::{$blade::$runner};
+echo Blade::{$blade->deckard};