I added phpmd to my Laravel project.
Now I have a remark about static usage of "Log".
namespace App\Http\Controllers;
use Log;
class MyController extends Controller
{
/**
* Does something
*/
public function doSomething($var)
{
Log::info('Just began to to something.');
}
phpmd says:
Avoid using static access to class '\Log' in method 'doSomething'.
What is the correct way to use Log class here?
I followed the Laravel docs but have no clue how to correct it and the phpmd docs do not help me due to my limited knowledge.
Thanks!
According to PHPMD documentation regarding static access
However Laravel facades could be considered a valid case for static class access, because they can be mocked.
Personally I prefer dependency injection over the use of static classes like
Log. Doing so will result in the following codeSo depending on preference the rule can either be disabled or you could use dependency injection over facades.