2019-09-01 06:56:46 +02:00
|
|
|
<?php
|
2021-12-15 04:58:32 +01:00
|
|
|
|
2020-03-15 04:54:42 +01:00
|
|
|
namespace Psalm\Internal\PhpVisitor;
|
2019-09-01 06:56:46 +02:00
|
|
|
|
|
|
|
use PhpParser;
|
|
|
|
|
2021-12-03 21:07:25 +01:00
|
|
|
use function is_string;
|
|
|
|
|
2019-09-01 06:56:46 +02:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
2020-10-15 19:23:35 +02:00
|
|
|
class ShortClosureVisitor extends PhpParser\NodeVisitorAbstract
|
2019-09-01 06:56:46 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var array<string, bool>
|
|
|
|
*/
|
2022-12-14 01:52:54 +01:00
|
|
|
protected array $used_variables = [];
|
2019-09-01 06:56:46 +02:00
|
|
|
|
2020-09-13 22:39:06 +02:00
|
|
|
public function enterNode(PhpParser\Node $node): ?int
|
2019-09-01 06:56:46 +02:00
|
|
|
{
|
2021-12-03 21:07:25 +01:00
|
|
|
if ($node instanceof PhpParser\Node\Expr\Variable && is_string($node->name)) {
|
2019-09-01 06:56:46 +02:00
|
|
|
$this->used_variables['$' . $node->name] = true;
|
2020-09-13 22:39:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2019-09-01 06:56:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array<string, bool>
|
|
|
|
*/
|
2020-09-04 22:26:33 +02:00
|
|
|
public function getUsedVariables(): array
|
2019-09-01 06:56:46 +02:00
|
|
|
{
|
|
|
|
return $this->used_variables;
|
|
|
|
}
|
|
|
|
}
|