GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( e97bb7...5f2eb5 )
by Pascal
10:40 queued 09:38
created

CheckerHasFailed   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 31.58 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 24
loc 76
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A via() 0 4 1
A data() 10 10 2
A toMail() 0 11 1
A toSlack() 14 14 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace ProtoneMedia\ApiHealth\Notifications;
4
5
use Illuminate\Notifications\Messages\MailMessage;
6
use Illuminate\Notifications\Messages\SlackMessage;
7
use Illuminate\Notifications\Notification;
8
use Illuminate\Support\Carbon;
9
use ProtoneMedia\ApiHealth\Checkers\Checker;
10
use ProtoneMedia\ApiHealth\Checkers\CheckerHasFailed as CheckerHasFailedException;
11
12
class CheckerHasFailed extends Notification
13
{
14
    public $checker;
15
    public $exception;
16
    public $failedData;
17
18
    public function __construct(Checker $checker, CheckerHasFailedException $exception, array $failedData)
19
    {
20
        $this->checker    = $checker;
21
        $this->exception  = $exception;
22
        $this->failedData = $failedData;
23
    }
24
25
    /**
26
     * Get the notification's channels from the configuration file.
27
     *
28
     * @return array|string
29
     */
30
    public function via(): array
31
    {
32
        return config('api-health.notifications.via');
33
    }
34
35
    /**
36
     * Returns an array of all relevant data for the notification.
37
     *
38
     * @return array
39
     */
40 View Code Duplication
    protected function data(): array
0 ignored issues
show
Duplication introduced by
This method 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...
41
    {
42
        return [
43
            'application_name'  => config('app.name') ?: 'Your application',
44
            'checker_type'      => get_class($this->checker),
45
            'failure_count'     => count($this->failedData['failed_at']),
46
            'failed_at'         => Carbon::createFromTimestamp($this->failedData['failed_at'][0]),
47
            'exception_message' => $this->exception->getMessage(),
48
        ];
49
    }
50
51
    /**
52
     * Build the mail representation of the notification.
53
     *
54
     * @return \Illuminate\Notifications\Messages\MailMessage
55
     */
56
    public function toMail(): MailMessage
57
    {
58
        $replace = $this->data();
59
60
        return (new MailMessage)
61
            ->error()
62
            ->subject(trans('api-health::notifications.checker_failed_subject', $replace))
63
            ->line(trans('api-health::notifications.checker_failed_type', $replace))
64
            ->line(trans('api-health::notifications.checker_failed_at', $replace))
65
            ->line(trans('api-health::notifications.checker_failed_exception', $replace));
66
    }
67
68
    /**
69
     * Build the Slack representation of the notification.
70
     *
71
     * @return \Illuminate\Notifications\Messages\SlackMessage
72
     */
73 View Code Duplication
    public function toSlack(): SlackMessage
0 ignored issues
show
Duplication introduced by
This method 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...
74
    {
75
        $replace = $this->data();
76
77
        return (new SlackMessage)
78
            ->error()
79
            ->from(config('api-health.notifications.slack.username'), config('api-health.notifications.slack.icon'))
80
            ->to(config('api-health.notifications.slack.channel'))
81
            ->content(implode(PHP_EOL, [
82
                trans('api-health::notifications.checker_failed_type', $replace),
83
                trans('api-health::notifications.checker_failed_at', $replace),
84
                trans('api-health::notifications.checker_failed_exception', $replace),
85
            ]));
86
    }
87
}
88