Completed
Push — master ( d7e260...fc7aea )
by Artem
10:19
created

UserSyncWebhook   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 25%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 37
ccs 2
cts 8
cp 0.25
rs 10
c 0
b 0
f 0
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 Slides\Connector\Auth\Sync\Syncer;
6
7
/**
8
 * Class UserSyncWebhook
9
 *
10
 * @package Slides\Connector\Auth\Webhooks
11
 */
12
class UserSyncWebhook extends Webhook
13
{
14
    /**
15
     * The payload validation rules.
16
     *
17
     * @return array
18
     */
19 1
    protected function rules(): array
20
    {
21
        return [
22 1
            'user' => 'required|array',
23
            'user.id' => 'required|int',
24
            'user.name' => 'string',
25
            'user.email' => 'required|email',
26
            'user.country' => 'required|string|size:2',
27
            'user.password' => 'string',
28
            'user.created_at' => 'required|string',
29
            'user.updated_at' => 'string',
30
            'user.action' => 'required|string',
31
        ];
32
    }
33
    
34
    /**
35
     * Handle the incoming request.
36
     *
37
     * @return void
38
     */
39
    public function handle()
40
    {
41
        $user = array_get($this->payload, 'user');
42
43
        $syncer = new Syncer(null, [Syncer::MODE_PASSWORDS]);
44
        $syncer->setForeigners(collect([
45
            $syncer->createRemoteUserFromResponse($user)
46
        ]));
47
48
        $syncer->apply();
49
    }
50
}