minulislam /
multicoin-api
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Multicoin\Api\Http\Controllers; |
||||
| 4 | |||||
| 5 | use Illuminate\Http\Request; |
||||
| 6 | use Illuminate\Routing\Controller; |
||||
| 7 | use Multicoin\Api\Exceptions\WebhookFailed; |
||||
| 8 | use Multicoin\Api\Http\Middlewares\VerifySignature; |
||||
| 9 | use Multicoin\Api\WebhookCall; |
||||
| 10 | |||||
| 11 | class WebhookController extends Controller |
||||
| 12 | { |
||||
| 13 | public function __construct() |
||||
| 14 | { |
||||
| 15 | $this->middleware(VerifySignature::class); |
||||
| 16 | } |
||||
| 17 | |||||
| 18 | public function __invoke(Request $request) |
||||
| 19 | { |
||||
| 20 | $eventPayload = $this->getJsonPayloadFromRequest($request); |
||||
| 21 | if (! isset($eventPayload['type'])) { |
||||
| 22 | throw WebhookFailed::missingType($request); |
||||
| 23 | } |
||||
| 24 | $type = $eventPayload['type']; |
||||
| 25 | $WebhookCall = new WebhookCall($eventPayload); |
||||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||||
| 26 | event("multicoin-webhooks::{$type}", $WebhookCall); |
||||
|
0 ignored issues
–
show
As per coding-style, please use concatenation or
sprintf for the variable $type instead of interpolation.
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings. // Instead of
$x = "foo $bar $baz";
// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
|
|||||
| 27 | $jobClass = $this->determineJobClass($type); |
||||
| 28 | if ('' === $jobClass) { |
||||
| 29 | return; |
||||
| 30 | } |
||||
| 31 | if (! class_exists($jobClass)) { |
||||
| 32 | throw WebhookFailed::jobClassDoesNotExist($jobClass, $WebhookCall); |
||||
|
0 ignored issues
–
show
The method
jobClassDoesNotExist() does not exist on Multicoin\Api\Exceptions\WebhookFailed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||
| 33 | } |
||||
| 34 | dispatch(new $jobClass($WebhookCall)); |
||||
|
0 ignored issues
–
show
|
|||||
| 35 | } |
||||
| 36 | |||||
| 37 | protected function determineJobClass(string $type) |
||||
| 38 | { |
||||
| 39 | return config("multicoin.jobs.{$type}", ''); |
||||
|
0 ignored issues
–
show
As per coding-style, please use concatenation or
sprintf for the variable $type instead of interpolation.
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings. // Instead of
$x = "foo $bar $baz";
// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
|
|||||
| 40 | } |
||||
| 41 | |||||
| 42 | private function getJsonPayloadFromRequest($request) |
||||
| 43 | { |
||||
| 44 | return (array) json_decode($request->getContent(), true); |
||||
| 45 | } |
||||
| 46 | } |
||||
| 47 |