composer-unused/symbol-parser
composer-unused/symbol-parser is a small toolkit that parses PHP symbols from a Composer package, helping tools like composer-unused detect what code is actually referenced. Useful for analyzing dependencies, exports, and usage across a project.
This package is a low-level utility for extracting PHP symbols (classes, interfaces, traits, functions, constants) from installed Composer packages. Begin by installing it in a project via composer require --dev composer-unused/symbol-parser. Its primary entry point is the SymbolParser class — instantiate it and call parse() with a path to a Composer vendor directory or a specific package directory. The output is a structured array of symbol definitions, grouped by file and namespace. Its first use case is often inspecting which symbols a third-party package actually exposes, especially when auditing dependencies for unused code removal.
Typical workflows involve integrating SymbolParser into build scripts or analysis tools. For example:
composer-unused/unused logic) to validate if a package's public API is actually used in code.The parser reads compiled Composer autoloader files (vendor/composer/autoload_psr4.php, autoload_classmap.php, etc.), then resolves files and extracts symbols using PHP Reflection or token parsing (e.g., token_get_all()), ensuring minimal runtime overhead.
vendor), parse results may be incomplete or inaccurate.SymbolResolver strategies to handle non-namespaced legacy code or parse polyfills and stubs. Also, consider caching parsed results to speed up iterative analysis.$parser->getStats() to catch files skipped due to syntax errors or unsupported constructs (e.g., PHP 8.1+ readonly properties may require updated token handling).How can I help you explore Laravel packages today?