PHP Mess Detector 避免使用静态访问

PHP Mess Detector avoid using static access

我在我的 Laravel 控制器可调用 class 上使用 PHP Mess Detector class 我收到了这样的消息

Avoid using static access to class 'Illuminate\Support\Facades\Cache' in method '__invoke'

谁能解释为什么我必须避免在调用方法上使用静态访问?

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

参考:https://phpmd.org/rules/cleancode.html#staticaccess