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

CheckSucceeded   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A toMail() 0 6 1
A toSlack() 0 11 1
A setEvent() 0 6 1
A shouldSend() 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\CheckSucceeded as CheckSucceededEvent;
12
13
class CheckSucceeded 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
            ->subject($this->getSubject())
28
            ->line($this->getMessageText());
29
    }
30
31
    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...
32
    {
33
        return (new SlackMessage)
34
            ->attachment(function (SlackAttachment $attachment) {
35
                $attachment
36
                    ->title($this->getSubject())
37
                    ->content($this->getMessageText())
38
                    ->fallback($this->getMessageText())
39
                    ->timestamp(Carbon::now());
40
            });
41
    }
42
43
    public function setEvent(CheckSucceededEvent $event)
44
    {
45
        $this->event = $event;
0 ignored issues
show
Documentation Bug introduced by
It seems like $event of type object<Spatie\ServerMoni...\Events\CheckSucceeded> is incompatible with the declared type object<Spatie\ServerMonitor\Events\CheckWarning> of property $event.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
46
47
        return $this;
48
    }
49
50
    public function shouldSend(): bool
51
    {
52
        return $this->getCheck()->hasStatus(CheckStatus::SUCCESS);
53
    }
54
}
55