AuditSns   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 48
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A via() 0 4 1
A toAwsSnsTopic() 0 15 1
1
<?php
2
3
namespace Andreshg112\LaravelAuditingNotifications;
4
5
use Illuminate\Support\Facades\Config;
6
use Lab123\AwsSns\Messages\AwsSnsMessage;
7
use Illuminate\Notifications\Notification;
8
use Lab123\AwsSns\Channels\AwsSnsTopicChannel;
9
use OwenIt\Auditing\Exceptions\AuditingException;
10
11
class AuditSns extends Notification
12
{
13
    /** @var array $auditData */
14
    protected $auditData = null;
15
16
    /**
17
     * Create a new notification instance.
18
     *
19
     * @param array $auditData
20
     */
21 3
    public function __construct(array $auditData)
22
    {
23 3
        $this->auditData = $auditData;
24 3
    }
25
26
    /**
27
     * Get the notification's delivery channels.
28
     *
29
     * @param  \OwenIt\Auditing\Contracts\Auditable  $notifiable
30
     * @return array
31
     */
32 1
    public function via($notifiable)
0 ignored issues
show
Unused Code introduced by Andrés Herrera García
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...
33
    {
34 1
        return [AwsSnsTopicChannel::class];
35
    }
36
37
    /**
38
     * Get the SNS representation of the notification.
39
     *
40
     * @param  \OwenIt\Auditing\Contracts\Auditable  $notifiable
41
     * @return \Lab123\AwsSns\Messages\AwsSnsMessage
42
     */
43 1
    public function toAwsSnsTopic($notifiable)
0 ignored issues
show
Unused Code introduced by Andrés Herrera García
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...
44
    {
45 1
        $config = 'audit.notification-driver.sns.topic_arn';
46
47 1
        $topicArn = Config::get($config);
48
49 1
        throw_if(
50 1
            empty($topicArn),
51 1
            new AuditingException("config $config is not set.")
52
        );
53
54 1
        return (new AwsSnsMessage())
55 1
            ->message(json_encode($this->auditData))
56 1
            ->topicArn($topicArn);
57
    }
58
}
59