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.

Notifier   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 14 3
A getChannel() 0 10 2
1
<?php namespace RuleCom\Notifier;
2
3
use BadMethodCallException;
4
use Exception;
5
6
class Notifier
7
{
8
    /**
9
     * Dispatches notifications for all given channels specified
10
     * in the Via method on the notification object
11
     *
12
     * @param object $notification
13
     * @throws NotificationFailed
14
     */
15
    public function send($notification)
16
    {
17
        $channelNames = $notification->via();
18
19
        foreach ($channelNames as $name) {
20
            $channel = $this->getChannel($name, $notification);
21
22
            try {
23
                $channel->dispatch();
24
            } catch (Exception $e) {
25
                throw new NotificationFailed($e->getMessage());
26
            }
27
        }
28
    }
29
30
    /**
31
     * Get channel from notifications to{Channel} method
32
     *
33
     * @param string $name
34
     * @param object $notification
35
     *
36
     * @return Channel
37
     */
38
    private function getChannel($name, $notification)
39
    {
40
        $method = "to" . ucfirst($name);
41
42
        if (! method_exists($notification, $method)) {
43
            throw new BadMethodCallException("Method: {$method} does not exist");
44
        }
45
46
        return $notification->{$method}();
47
    }
48
}
49