Passed
Push — master ( 8c743d...154964 )
by Eudald
10:11
created

GocardlessWebhookController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 21 3
A __construct() 0 3 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: eudaldarranztresserra
5
 * Date: 2019-03-01
6
 * Time: 13:07
7
 */
8
9
namespace Nestednet\Gocardless\Controllers;
10
11
use Exception;
12
use Illuminate\Http\Request;
0 ignored issues
show
Bug introduced by
The type Illuminate\Http\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Illuminate\Routing\Controller;
0 ignored issues
show
Bug introduced by
The type Illuminate\Routing\Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Nestednet\Gocardless\Middlewares\VerifySignature;
15
16
class GocardlessWebhookController extends Controller
17
{
18
    public function __construct()
19
    {
20
        $this->middleware(VerifySignature::class);
21
    }
22
23
    public function __invoke(Request $request)
24
    {
25
        $payload = $request->input();
26
        $modelClass = config('gocardless.webhooks.model');
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
        $modelClass = /** @scrutinizer ignore-call */ config('gocardless.webhooks.model');
Loading history...
27
28
        foreach ($payload['events'] as $event) {
29
            $gocardlessWebhookCall = $modelClass::create([
30
                'resource_type' => $event['resource_type'] ?? '',
31
                'action' => $event['action'] ?? '',
32
                'payload' => $event,
33
            ]);
34
35
            try {
36
                $gocardlessWebhookCall->process();
37
            } catch (Exception $exception) {
38
                $gocardlessWebhookCall->saveException($exception);
39
                //Improve the way we handle the exceptions here, add the option to notify the exceptions.
40
            }
41
        }
42
43
        return response()->json(['message' => 'ok']);
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
        return /** @scrutinizer ignore-call */ response()->json(['message' => 'ok']);
Loading history...
44
    }
45
}