1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-16 19:36:59 +01:00
psalm/src/Psalm/Internal/Analyzer/ClosureAnalyzer.php
2020-02-14 20:54:26 -05:00

51 lines
1.3 KiB
PHP

<?php
namespace Psalm\Internal\Analyzer;
use PhpParser;
use function strtolower;
/**
* @internal
*/
class ClosureAnalyzer extends FunctionLikeAnalyzer
{
/**
* @var PhpParser\Node\Expr\Closure|PhpParser\Node\Expr\ArrowFunction
*/
protected $function;
/**
* @param PhpParser\Node\Expr\Closure|PhpParser\Node\Expr\ArrowFunction $function
* @param SourceAnalyzer $source [description]
*/
public function __construct(PhpParser\Node\FunctionLike $function, SourceAnalyzer $source)
{
$codebase = $source->getCodebase();
$function_id = \strtolower($source->getFilePath())
. ':' . $function->getLine()
. ':' . (int)$function->getAttribute('startFilePos')
. ':-:closure';
$storage = $codebase->getClosureStorage($source->getFilePath(), $function_id);
parent::__construct($function, $source, $storage);
}
public function getTemplateTypeMap()
{
return $this->source->getTemplateTypeMap();
}
/**
* @return string
*/
public function getClosureId()
{
return strtolower($this->getFilePath())
. ':' . $this->function->getLine()
. ':' . (int)$this->function->getAttribute('startFilePos')
. ':-:closure';
}
}