PolarChannel::send()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace PolarAdmin\Polar\Notifications\Channels;
4
5
use Illuminate\Notifications\Notification;
6
use PolarAdmin\Polar\Notifications\Messages\PolarMessage;
7
use PolarAdmin\Polar\Contracts\Repositories\PolarNotificationRepository;
8
9
class PolarChannel
10
{
11
    protected $polarNotificationRepository;
12
13
    public function __construct(PolarNotificationRepository $polarNotificationRepository)
14
    {
15
        $this->polarNotificationRepository = $polarNotificationRepository;
16
    }
17
18
    public function send($notifiable, Notification $notification)
19
    {
20
        $message = $notification->toPolar($notifiable);
0 ignored issues
show
Bug introduced by
The method toPolar() does not seem to exist on object<Illuminate\Notifications\Notification>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
21
22
        $this->polarNotificationRepository->create($this->buildPayload($notifiable, $message));
23
    }
24
25
    /**
26
     * Build an array payload for the Notification Model.
27
     */
28
    protected function buildPayload($notifiable, PolarMessage $message) : array
29
    {
30
        return [
31
            'user_id' => $notifiable->getKey(),
32
            'body' => $message->body,
33
            'status' => $message->status,
34
            'from' => $message->from,
35
            'url' => $message->url,
36
            'extra' => $message->extra,
37
        ];
38
    }
39
}
40