Completed
Push — master ( de5c78...60eb24 )
by Sherif
09:23
created

PushNotificationDeviceService::generateMessageData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
namespace App\Modules\PushNotificationDevices\Services;
4
5
use App\Modules\Core\BaseClasses\BaseService;
6
use LaravelFCM\Message\OptionsBuilder;
7
use LaravelFCM\Message\PayloadDataBuilder;
8
use LaravelFCM\Message\PayloadNotificationBuilder;
9
use App\Modules\PushNotificationDevices\Repositories\PushNotificationDeviceRepository;
10
11
class PushNotificationDeviceService extends BaseService
12
{
13
    /**
14
     * Init new object.
15
     *
16
     * @param   PushNotificationDeviceRepository $repo
17
     * @return  void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
18
     */
19
    public function __construct(PushNotificationDeviceRepository $repo)
20
    {
21
        parent::__construct($repo);
22
    }
23
24
    /**
25
     * Register the given device to the logged in user.
26
     *
27
     * @param  array $data
28
     * @return void
29
     */
30
    public function registerDevice($data)
31
    {
32
        $data['access_token'] = \Auth::user()->token();
33
        $data['user_id']      = \Auth::id();
34
        $device               = $this->repo->first([
35
            'and' => [
36
                'device_token' => $data['device_token'],
37
                'user_id' => $data['user_id']
38
                ]
39
            ]);
40
41
        if ($device) {
42
            $data['id'] = $device->id;
43
        }
44
45
        return $this->repo->save($data);
46
    }
47
}
48