php-extension-check/src/Parser/Visitors/FunctionCollector.php

36 lines
771 B
PHP
Raw Permalink Normal View History

2021-05-08 21:09:48 +00:00
<?php
2021-05-08 22:50:26 +00:00
2021-05-08 21:09:48 +00:00
declare(strict_types=1);
2021-05-08 22:50:26 +00:00
2021-05-08 21:09:48 +00:00
namespace Fbrinker\ExtensionCheck\Parser\Visitors;
use PhpParser\Node;
use PhpParser\NodeVisitorAbstract;
2021-05-08 22:50:26 +00:00
class FunctionCollector extends NodeVisitorAbstract implements CollectorInferface
{
/**
* @var array<string,bool> $functions
*/
2021-05-08 21:09:48 +00:00
private $functions = [];
2021-05-08 22:50:26 +00:00
public function getCollected(): array
{
2021-05-08 21:09:48 +00:00
$list = array_keys($this->functions);
natcasesort($list);
return array_values($list);
}
2021-05-08 22:50:26 +00:00
public function enterNode(Node $node)
{
2021-05-08 21:09:48 +00:00
if ($node instanceof Node\Expr\FuncCall) {
if (!empty($node->name) && $node->name instanceof Node\Name) {
$this->functions[$node->name->toString()] = true;
}
}
2021-05-08 22:50:26 +00:00
return null;
2021-05-08 21:09:48 +00:00
}
2021-05-08 22:50:26 +00:00
}