Completed
Push — master ( 19e89a...11c2ec )
by Freek
08:19
created

CheckWarning   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 44
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A toMail() 0 7 1
A toSlack() 0 12 1
A setEvent() 0 6 1
A isStillRelevant() 0 4 1
1
<?php
2
3
namespace Spatie\ServerMonitor\Notifications\Notifications;
4
5
use Carbon\Carbon;
6
use Illuminate\Notifications\Messages\MailMessage;
7
use Spatie\ServerMonitor\Models\Enums\CheckStatus;
8
use Illuminate\Notifications\Messages\SlackMessage;
9
use Illuminate\Notifications\Messages\SlackAttachment;
10
use Spatie\ServerMonitor\Notifications\BaseNotification;
11
use Spatie\ServerMonitor\Events\CheckWarning as CheckWarningEvent;
12
13
class CheckWarning extends BaseNotification
14
{
15
    /** @var \Spatie\ServerMonitor\Events\CheckWarning */
16
    public $event;
17
18
    /**
19
     * Get the mail representation of the notification.
20
     *
21
     * @param  mixed $notifiable
22
     * @return \Illuminate\Notifications\Messages\MailMessage
23
     */
24
    public function toMail($notifiable)
0 ignored issues
show
Unused Code introduced by
The parameter $notifiable is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
25
    {
26
        return (new MailMessage)
27
            ->error()
28
            ->subject($this->getSubject())
29
            ->line($this->getMessageText());
30
    }
31
32
    public function toSlack($notifiable)
0 ignored issues
show
Unused Code introduced by
The parameter $notifiable is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
33
    {
34
        return (new SlackMessage)
35
            ->warning()
36
            ->attachment(function (SlackAttachment $attachment) {
37
                $attachment
38
                    ->title($this->getSubject())
39
                    ->content($this->getMessageText())
40
                    ->fallback($this->getMessageText())
41
                    ->timestamp(Carbon::now());
42
            });
43
    }
44
45
    public function setEvent(CheckWarningEvent $event)
46
    {
47
        $this->event = $event;
48
49
        return $this;
50
    }
51
52
    public function isStillRelevant(): bool
53
    {
54
        return $this->getCheck()->hasStatus(CheckStatus::WARNING);
55
    }
56
}
57