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

CheckWarning::getSubject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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