Passed
Push — master ( 8049c5...c740e0 )
by Andrés
03:39
created

AuditSns::via()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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
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
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