Notifies   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 86
ccs 24
cts 24
cp 1
rs 10
wmc 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A report() 0 3 1
A overridesRoutes() 0 3 1
A getCustomRoutes() 0 3 1
A getRoutesToNotify() 0 9 2
A getCustomChannels() 0 3 1
A notify() 0 11 3
A getMessages() 0 3 1
1
<?php
2
3
namespace Cerbero\NotifiableException;
4
5
use Cerbero\NotifiableException\Notifications\ErrorOccurred;
6
use Illuminate\Notifications\AnonymousNotifiable;
7
8
/**
9
 * Trait to let exceptions notify their errors.
10
 *
11
 */
12
trait Notifies
13
{
14
    /**
15
     * Define how the current exception should be reported by the exception handler
16
     *
17
     * @return void
18
     */
19 3
    public function report()
20
    {
21 3
        $this->notify();
22 3
    }
23
24
    /**
25
     * Notify the current exception.
26
     *
27
     * @return void
28
     */
29 24
    public function notify()
30
    {
31
        /** @var \Cerbero\NotifiableException\Notifiable $this */
32 24
        $notification = new ErrorOccurred($this);
33 24
        $routes = $this->getRoutesToNotify();
0 ignored issues
show
Bug introduced by
The method getRoutesToNotify() does not exist on Cerbero\NotifiableException\Notifiable. Since it exists in all sub-types, consider adding an abstract or default implementation to Cerbero\NotifiableException\Notifiable. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        /** @scrutinizer ignore-call */ 
34
        $routes = $this->getRoutesToNotify();
Loading history...
34
35 24
        foreach ($routes as $channel => $channelRoutes) {
36 21
            $channelRoutes = array_unique((array) $channelRoutes);
37
38 21
            foreach ($channelRoutes as $route) {
39 21
                (new AnonymousNotifiable)->route($channel, $route)->notify($notification);
40
            }
41
        }
42 24
    }
43
44
    /**
45
     * Retrieve all the routes to send notification to.
46
     *
47
     * @return array
48
     */
49 24
    protected function getRoutesToNotify(): array
50
    {
51 24
        if ($this->overridesRoutes()) {
52 3
            return $this->getCustomRoutes();
53
        }
54
55 21
        $defaultRoutes = config('notifiable_exception.default_routes');
56
57 21
        return array_merge_recursive($defaultRoutes, $this->getCustomRoutes());
58
    }
59
60
    /**
61
     * Determine whether the current exception routes should override the default ones.
62
     *
63
     * @return bool
64
     */
65 21
    protected function overridesRoutes(): bool
66
    {
67 21
        return false;
68
    }
69
70
    /**
71
     * Retrieve the custom notification routes keyed by the channel alias
72
     *
73
     * @return array
74
     */
75 3
    protected function getCustomRoutes(): array
76
    {
77 3
        return [];
78
    }
79
80
    /**
81
     * Retrieve the message for each channel keyed by the channel alias
82
     *
83
     * @return array
84
     */
85 3
    public function getMessages(): array
86
    {
87 3
        return [];
88
    }
89
90
    /**
91
     * Retrieve the custom channel class names keyed by the channel alias
92
     *
93
     * @return array
94
     */
95 3
    public function getCustomChannels(): array
96
    {
97 3
        return [];
98
    }
99
}
100