LinkTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 14
c 1
b 0
f 0
dl 0
loc 26
ccs 0
cts 14
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A incrementQueryFromSendGrid() 0 18 2
1
<?php
2
3
namespace Nip\MailModule\Models\LinksTable;
4
5
use Nip\Database\Query\Insert;
6
use Nip\Records\Traits\AbstractTrait\RecordTrait as AbstractRecordTrait;
7
8
/**
9
 * Trait LinkTrait
10
 * @package Nip\MailModule\Models\LinksTable
11
 */
12
trait LinkTrait
13
{
14
    use AbstractRecordTrait;
15
16
    /**
17
     * @param $notification
18
     * @return Insert
19
     */
20
    public function incrementQueryFromSendGrid($notification)
21
    {
22
        $cols = ['hash', 'id_email', 'email', 'smtp-id', 'category', 'url', 'ip', 'useragent', 'clicks'];
23
        /** @var Insert $query */
24
        $query = $this->newQuery('insert');
0 ignored issues
show
Bug introduced by
It seems like newQuery() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

24
        /** @scrutinizer ignore-call */ 
25
        $query = $this->newQuery('insert');
Loading history...
25
        $query->setCols($cols);
26
27
        $notification['hash'] = sha1($notification['id_email'] . $notification['email'] . $notification['url']);
28
        $values = [];
29
        foreach ($cols as $col) {
30
            $values[$col] = $notification[$col];
31
        }
32
        $values['clicks'] = 1;
33
        $query->data($values);
34
        $onDuplicate = ['clicks' => ['`clicks`+1', false]];
35
        $query->onDuplicate($onDuplicate);
36
37
        return $query;
38
    }
39
}
40