drenso/phan-extensions
PhanExtensions provides plugins and stubs for Phan static analysis: Symfony annotation import checking, docblock @method/@throws usage, and inline var comment scanning. Includes stubs for curl, intl, ldap, pdo, radius, and sockets. Not actively maintained.
Installation:
composer require drenso/phan-extensions
Add the package to your project's composer.json dependencies.
Configure Phan:
Update your phan.config.php to include the plugins and stubs:
return [
'plugins' => [
__DIR__ . '/vendor/drenso/phan-extensions/Plugin/Annotation/SymfonyAnnotationPlugin.php',
__DIR__ . '/vendor/drenso/phan-extensions/Plugin/DocComment/InlineVarPlugin.php',
__DIR__ . '/vendor/drenso/phan-extensions/Plugin/DocComment/MethodPlugin.php',
],
'directory_list' => [
__DIR__ . '/vendor/drenso/phan-extensions/Stubs',
],
'exclude_analysis_directory_list' => [
__DIR__ . '/vendor/drenso/phan-extensions/Stubs',
],
];
Run Phan:
vendor/bin/phan
Symfony Annotations:
If your project uses Symfony-style annotations (e.g., @Route, @ParamConverter), enable SymfonyAnnotationPlugin to suppress false positives for unused annotations and ensure proper imports are detected.
SymfonyAnnotationPlugin:
phan.config.php.@Route("/path")).use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
/**
* @Route("/example")
*/
public function exampleAction() {}
DocComment Plugins:
@var string $foo).
/src directory for classes and validate inline doc comments.@method and @throws annotations are respected.
Stub Integration:
curl, intl).directory_list and exclude them from analysis.$ch = curl_init(); // No "Undefined variable" warning
vendor/bin/phan --directory=src/Controller
- name: Run Phan
run: vendor/bin/phan --allow-testing-code
Plugin Compatibility:
@Annotation, @Target, @Required, and @SuppressWarnings by default. Customize via subclassing if needed.Stub Conflicts:
directory_list order.pdo stubs exist in Stubs and a vendor package, Phan uses the first match.Performance:
InlineVarPlugin add overhead. Disable unused plugins in phan.config.php:
'plugins' => [__DIR__ . '/vendor/drenso/phan-extensions/Plugin/Annotation/SymfonyAnnotationPlugin.php'],
False Positives:
--suppress-issues to ignore specific warnings temporarily:
vendor/bin/phan --suppress-issues=UnusedPrivateMethod
@var in docblocks).Plugin Debugging:
vendor/bin/phan -vvv
--dump-autoloader or --dump-config.Custom Plugins:
SymfonyAnnotationPlugin to support additional annotation formats:
class CustomAnnotationPlugin extends SymfonyAnnotationPlugin {
protected function getIgnoredAnnotations(): array {
return array_merge(parent::getIgnoredAnnotations(), ['@CustomAnnotation']);
}
}
phan.config.php:
'plugins' => [__DIR__ . '/app/Phan/CustomAnnotationPlugin.php'],
Stub Customization:
vendor/custom-lib/Stubs).Monolog handler:
// vendor/custom-lib/Stubs/Monolog/Handler/CustomHandler.php
class CustomHandler extends \Monolog\Handler\AbstractHandler {}
Phan Configuration:
phan/phan for Laravel support):
'plugins' => [
__DIR__ . '/vendor/drenso/phan-extensions/Plugin/Annotation/SymfonyAnnotationPlugin.php',
__DIR__ . '/vendor/phan/phan/Plugin/LaravelPlugin.php',
],
phan/phan for active development.phan/phan:^3.0 for modern setups).How can I help you explore Laravel packages today?