A trait providing a logger to eleven classes, each of which called a static accessor to get one.
// before
trait LogsActivity
{
protected function logger(): LoggerInterface
{
return app(LoggerInterface::class); // a locator
}
}
// after
public function __construct(
private readonly LoggerInterface $logger,
) {}
The trait was hiding a service locator behind a method call, which meant no class declared what it needed and none of them could be constructed in a test without a container. Eleven constructors got one argument each and the trait went away — more typing at eleven call sites, and every class now states its dependencies in the one place a reader looks.