PHP Mess Detector avoid using static access

1.7k views Asked by At

i use PHP Mess Detector on my Laravel controller invokable class and i got message like this

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

Can anyone explain it why i must avoid using static access on invoke method?

1

There are 1 answers

1
Akshay Khale On BEST ANSWER

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.

Reference: https://phpmd.org/rules/cleancode.html#staticaccess