CheckSucceeded::toSlack()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 11
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\ServerMonitor\Notifications\Notifications;
4
5
use Carbon\Carbon;
6
use Illuminate\Notifications\Messages\MailMessage;
7
use Illuminate\Notifications\Messages\SlackAttachment;
8
use Illuminate\Notifications\Messages\SlackMessage;
9
use Spatie\ServerMonitor\Events\CheckSucceeded as CheckSucceededEvent;
10
use Spatie\ServerMonitor\Models\Enums\CheckStatus;
11
use Spatie\ServerMonitor\Notifications\BaseNotification;
12
13 View Code Duplication
class CheckSucceeded 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
            ->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