imanghafoori/php-token-analyzer
Analyzes PHP code tokens without execution—like reflection but pure PHP. Framework-agnostic, lightweight dependency extracted from Laravel-Microscope. Supports PHP 7.4+ with automated tests for accuracy. Extract class/method details, token types, and structure effortlessly. Ideal for static analysis...
Install the package with composer require imanghafoori/token-analyzer. Start by analyzing a simple PHP file using TokenAnalyzer::analyzeFile($path), which returns structured information about functions, classes, traits, namespaces, and use statements — all extracted from tokens without runtime execution. For example:
$analyzer = new \Imanghafoori\TokenAnalyzer\TokenAnalyzer();
$tokens = $analyzer->analyzeFile('app/Services/MyService.php');
// $tokens contains parsed metadata like classes, methods, docblocks, etc.
This is ideal for static code analysis tasks like validating conventions, generating documentation scaffolds, or enforcing internal project standards — without bootstrapping a full framework.
@method annotations, forbidden function calls, or incorrect return types).@property annotations).php-analyzer CLI that scans codebases for deprecated constructs across multiple projects.token_get_all() under the hood, so complex edge cases (e.g., nested heredoc/nowdoc, PHP 8.1+ named arguments, or polyfill quirks) may behave differently than PHP’s internal engine. Always validate against your target PHP version.phpdocumentor/reflection-docblock; ensure compatible versions are installed (it supports both v4 and v5), and test with complex PHPDoc patterns (e.g., generics, union types in @param).TokenStream processing. Check src/Analyzers/ for hooks into method/class traversal logic.phpdocumentor/reflection-docblock conflicts (e.g., with newer PHPStan or Psalm deps), use --with-all-dependencies during install or pin to ^4.1 or ^5.3 explicitly.How can I help you explore Laravel packages today?