UserSyncWebhook::rules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 12
ccs 2
cts 2
cp 1
crap 1
rs 9.9332
c 0
b 0
f 0
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
}