UserSyncWebhook   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 25%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 39
rs 10
ccs 2
cts 8
cp 0.25
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 10 1
A rules() 0 12 1
1
<?php
2
3
namespace Slides\Connector\Auth\Webhooks;
4
5
use Illuminate\Support\Arr;
6
use Slides\Connector\Auth\Sync\Syncer;
7
8
/**
9
 * Class UserSyncWebhook
10
 *
11
 * @package Slides\Connector\Auth\Webhooks
12
 */
13
class UserSyncWebhook extends Webhook
14
{
15
    /**
16
     * The payload validation rules.
17
     *
18
     * @return array
19
     */
20 1
    protected function rules(): array
21
    {
22
        return [
23 1
            'user' => 'required|array',
24
            'user.id' => 'required|int',
25
            'user.name' => 'string',
26
            'user.email' => 'required|email',
27
            'user.country' => 'required|string|size:2',
28
            'user.password' => 'string',
29
            'user.created_at' => 'required|string',
30
            'user.updated_at' => 'string',
31
            'user.action' => 'required|string',
32
        ];
33
    }
34
    
35
    /**
36
     * Handle the incoming request.
37
     *
38
     * @param array $payload
39
     *
40
     * @return void
41
     */
42
    public function handle(array $payload)
43
    {
44
        $user = Arr::get($payload, 'user');
45
46
        $syncer = new Syncer(null, [Syncer::MODE_PASSWORDS]);
47
        $syncer->setForeigners(collect([
48
            $syncer->createRemoteUserFromResponse($user)
0 ignored issues
show
Bug introduced by
It seems like $user can also be of type null; however, parameter $user of Slides\Connector\Auth\Sy...emoteUserFromResponse() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

48
            $syncer->createRemoteUserFromResponse(/** @scrutinizer ignore-type */ $user)
Loading history...
49
        ]));
50
51
        $syncer->apply();
52
    }
53
}