-
Notifications
You must be signed in to change notification settings - Fork 17
Description
Take the following code as an example:
<?php
namespace Whatever;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
final class LumenExceptionHandler extends ExceptionHandler {
public function render($request, \Exception $e) {
$status = 500;
if ($e instanceof HttpExceptionInterface) {
$status = $e->getStatusCode();
}
return response()->json(['message' => $e->getMessage()], $status);
}
}
The render
function takes 2 arguments. A request and an exception. We have to accept these two arguments because we're overwriting a method and we want to match it's signature.
In our implementation, we don't actually care about the $request
param. PHPCS gives me a warning because $request
is unused.
I want to be able to tell PHPCS that this argument is unused and that this is OK.
With Rubocop (a ruby linter), I can prefix an argument with _
to mark it as unused and to let the linter know that this is OK. Here's the relevant doc: https://rubocop.readthedocs.io/en/latest/cops_lint/#lintunusedmethodargument
We could have something like this:
public function render($_request, \Exception $e) {
// ...
}
This would not generate any warnings since we've explicitly said that the argument should be unused.