Completed
Push — master ( 434343...7ded52 )
by Freek
02:04
created

CheckWarning::isStillRelevant()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
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 View Code Duplication
class CheckWarning extends BaseNotification
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 shouldSend(): bool
53
    {
54
         if (! $this->getCheck()->hasStatus(CheckStatus::WARNING)) {
55
             return false;
56
         }
57
58
         return ! $this->getCheck()->isThrottlingFailedNotifications();
59
    }
60
}
61