EmailViewed::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\ViewEmailEvent;
7
8
class EmailViewed
9
{
10
    public function __construct()
11
    {
12
        //
13
    }
14
15
    public function handle(ViewEmailEvent $event)
16
    {
17
        $campaign_id = $event->sent_email->getHeader('X-Campaign-ID');
18
19
        if ($campaign_id) {
20
            $email = Email::where('message_id', $event->sent_email->message_id)->first();
21
            $email->opens = $email->opens + 1;
22
            $email->save();
23
        }
24
    }
25
}
26