sebastian/code-unit-reverse-lookup
Looks up which function or method a given line of code belongs to, a small utility from the PHPUnit ecosystem by Sebastian Bergmann. Install it via Composer as a project or dev dependency. Now a low maintenance project.
Architecture fit
Wizard::lookup($file, $line)) that maps a source line to the enclosing function/method. It has no service provider, no config, no facades, and no Laravel integration surface — by design.require-dev only. Its real role is as a transitive dependency of phpunit/phpunit → php-code-coverage, where it attributes covered lines to methods for per-function coverage reporting.composer why sebastian/code-unit-reverse-lookup before assuming it is absent.Integration feasibility
composer require --dev), zero configuration, no bootstrapping, no Laravel version coupling. Composer resolution risk is minimal because it is a leaf package with a very small dependency surface.composer.json versus the project runtime (Laravel 10/11 target PHP 8.1–8.3). Confirm the constraint rather than assuming; that is the one thing that can block adoption on older pinned runtimes.Technical risk
Wizard ties internal tooling to a class that upstream may rename or drop when PHPUnit restructures coverage internals. Mitigate with a thin adapter of our own.Key questions
nikic/php-parser or the token_get_all API a better-owned foundation, given it gives us closures, traits, and anonymous classes properly?Stack fit
require-dev only. Add it explicitly solely if our own code references SebastianBergmann\CodeUnitReverseLookup\Wizard; otherwise leave it transitive and never rely on an undeclared package.App\Support\Source\MethodLocator) so the vendor class appears in exactly one place. That adapter is where we would swap in a php-parser implementation later.lookup() reads and tokenizes the target file per call.Migration path
token_get_all-based implementation is roughly a day of work and removes the dependency entirely; nikic/php-parser is the upgrade path if we need accurate handling of closures, arrow functions, traits, and anonymous classes.Compatibility
storage/framework/ from any analysis.Sequencing
composer why / composer show.require-dev pin and land the adapter with a contract test.Maintenance
composer.json plus periodic constraint checks on PHP upgrades. Budget a fork only if we need behaviour upstream will not accept.Support
Class::method strings, null outside a function) to avoid repeated rediscovery.Scaling
lookup() in a loop over thousands of lines.Failure modes
class@anonymous, {closure}) — sanitize before surfacing in reports or PR annotations.Ramp-up
How can I help you explore Laravel packages today?