EmailClicked::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Listeners;
4
5
use App\Models\Email;
6
use jdavidbakr\MailTracker\Events\LinkClickedEvent;
7
8
class EmailClicked
9
{
10
    /**
11
     * Create the event listener.
12
     *
13
     * @return void
14
     */
15
    public function __construct()
16
    {
17
        //
18
    }
19
20
    /**
21
     * Handle the event.
22
     *
23
     * @param  LinkClickedEvent  $event
24
     * @return void
25
     */
26
    public function handle(LinkClickedEvent $event)
27
    {
28
        $campaign_id = $event->sent_email->getHeader('X-Campaign-ID');
29
30
        if ($campaign_id) {
31
            $email = Email::where('message_id', $event->sent_email->message_id)->first();
32
            $email->clicks = $email->clicks + 1;
33
            $email->save();
34
        }
35
    }
36
}
37