Passed
Push — develop ( d32912...6dcea6 )
by Septianata
05:48
created

OrderCreated   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
c 1
b 0
f 0
dl 0
loc 52
ccs 0
cts 10
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getTelegramMessage() 0 5 1
A getTelegramChatId() 0 3 1
1
<?php
2
3
namespace App\Events;
4
5
use App\Contracts\Event\CanSendTelegramNotification;
6
use App\Models\Contracts\HasTelegramChatId;
7
use App\Models\Order;
8
use App\Support\Events\HandleRecipient;
9
use Illuminate\Broadcasting\InteractsWithSockets;
10
use Illuminate\Contracts\Queue\ShouldQueue;
11
use Illuminate\Foundation\Events\Dispatchable;
12
use Illuminate\Queue\InteractsWithQueue;
13
use Illuminate\Queue\SerializesModels;
14
15
class OrderCreated implements CanSendTelegramNotification, ShouldQueue
16
{
17
    use Dispatchable, InteractsWithSockets, SerializesModels, InteractsWithQueue,
0 ignored issues
show
introduced by
The trait Illuminate\Queue\SerializesModels requires some properties which are not provided by App\Events\OrderCreated: $id, $relations, $class, $connection, $keyBy
Loading history...
18
        HandleRecipient;
19
20
    /**
21
     * The order instance data.
22
     *
23
     * @var \App\Models\Order
24
     */
25
    protected Order $order;
26
27
    /**
28
     * The recipient data that will receive the notification.
29
     *
30
     * @var \App\Models\Contracts\HasTelegramChatId
31
     */
32
    protected HasTelegramChatId $recipient;
33
34
    /**
35
     * Create a new event instance.
36
     *
37
     * @param  \App\Models\Order  $order
38
     * @param  \App\Models\Contracts\HasTelegramChatId|null  $recipient
39
     * @return void
40
     */
41
    public function __construct(Order $order, HasTelegramChatId $recipient = null)
42
    {
43
        $this->order = $order;
44
        $this->recipient = $this->findRecipientFromUser($recipient);
45
    }
46
47
    /**
48
     * Return telegram chat id value.
49
     *
50
     * @return string|array
51
     */
52
    public function getTelegramChatId()
53
    {
54
        return $this->recipient->getTelegramChatId();
55
    }
56
57
    /**
58
     * Return telegram chat message content.
59
     *
60
     * @return string
61
     */
62
    public function getTelegramMessage(): string
63
    {
64
        return view('notifications.order-created', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('notificatio...this->order))->render() could return the type array which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
65
            'order' => $this->order,
66
        ])->render();
67
    }
68
}
69