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

CheckerHasRecovered   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 72
Duplicated Lines 31.94 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A via() 0 4 1
A data() 9 9 2
A toMail() 0 10 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
11
class CheckerHasRecovered extends Notification
12
{
13
    public $checker;
14
    public $failedData;
15
16
    public function __construct(Checker $checker, array $failedData)
17
    {
18
        $this->checker    = $checker;
19
        $this->failedData = $failedData;
20
    }
21
22
    /**
23
     * Get the notification's channels from the configuration file.
24
     *
25
     * @return array|string
26
     */
27
    public function via(): array
28
    {
29
        return config('api-health.notifications.via');
30
    }
31
32
    /**
33
     * Returns an array of all relevant data for the notification.
34
     *
35
     * @return array
36
     */
37 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...
38
    {
39
        return [
40
            'application_name'  => config('app.name') ?: 'Your application',
41
            'checker_type'      => get_class($this->checker),
42
            'failed_at'         => Carbon::createFromTimestamp($this->failedData['failed_at'][0]),
43
            'exception_message' => $this->failedData['exception_message'],
44
        ];
45
    }
46
47
    /**
48
     * Build the mail representation of the notification.
49
     *
50
     * @return \Illuminate\Notifications\Messages\MailMessage
51
     */
52
    public function toMail(): MailMessage
53
    {
54
        $replace = $this->data();
55
56
        return (new MailMessage)
57
            ->subject(trans('api-health::notifications.checker_recovered_subject', $replace))
58
            ->line(trans('api-health::notifications.checker_recovered_type', $replace))
59
            ->line(trans('api-health::notifications.checker_recovered_failed_at', $replace))
60
            ->line(trans('api-health::notifications.checker_recovered_exception', $replace));
61
    }
62
63
    /**
64
     * Build the Slack representation of the notification.
65
     *
66
     * @return \Illuminate\Notifications\Messages\SlackMessage
67
     */
68 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...
69
    {
70
        $replace = $this->data();
71
72
        return (new SlackMessage)
73
            ->success()
74
            ->from(config('api-health.notifications.slack.username'), config('api-health.notifications.slack.icon'))
75
            ->to(config('api-health.notifications.slack.channel'))
76
            ->content(implode(PHP_EOL, [
77
                trans('api-health::notifications.checker_recovered_type', $replace),
78
                trans('api-health::notifications.checker_recovered_failed_at', $replace),
79
                trans('api-health::notifications.checker_recovered_exception', $replace),
80
            ]));
81
    }
82
}
83