Created
April 28, 2021 18:28
-
-
Save dasl-/95ea9d3c3e7d16d923cdf87d8b5a5b0e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php declare(strict_types=1); | |
use Phan\CodeBase; | |
use Phan\Language\Context; | |
use Phan\PluginV3; | |
use Phan\PluginV3\AnalyzeFunctionCallCapability; | |
use Phan\Language\Element\FunctionInterface; | |
/** | |
* Prints out call sites of given functions or methods. | |
*/ | |
final class CallSiteFinderPlugin extends PluginV3 implements AnalyzeFunctionCallCapability { | |
public function getAnalyzeFunctionCallClosures(CodeBase $code_base): array { | |
static $function_call_closures = null; | |
if ($function_call_closures === null) { | |
$function_call_closures = [ | |
'\\Foo::bar' => | |
function (CodeBase $code_base, Context $context, FunctionInterface $function) { | |
self::callsiteFinder($code_base, $context, $function, '\\Foo::bar'); | |
}, | |
'\\Baz::bing' => | |
function (CodeBase $code_base, Context $context, FunctionInterface $function) { | |
self::callsiteFinder($code_base, $context, $function, '\\Baz::bing'); | |
}, | |
]; | |
} | |
return $function_call_closures; | |
} | |
private static function callsiteFinder(CodeBase $code_base, Context $context, FunctionInterface $function, string $func_to_analyze): void { | |
self::emitIssue( | |
$code_base, | |
$context, | |
'PhanPluginCallsiteFinder', | |
'Saw call to {FUNCTION} ({FUNC_TO_ANALYZE})', | |
[(string)$function->getFQSEN(), $func_to_analyze] | |
); | |
} | |
} | |
return new CallSiteFinderPlugin(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment