Passed
Push — master ( ff7474...c002dd )
by Gabriel
05:50
created

CompletePurchaseTrait::parseNotification()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 7
ccs 0
cts 5
cp 0
crap 6
rs 10
1
<?php
2
3
namespace ByTIC\Payments\Gateways\Providers\Twispay\Message\Traits;
4
5
use ByTIC\Payments\Gateways\Providers\AbstractGateway\Message\Traits\HasGatewayRequestTrait;
6
use ByTIC\Payments\Gateways\Providers\AbstractGateway\Message\Traits\HasModelRequest;
7
use ByTIC\Payments\Gateways\Providers\Twispay\Gateway;
8
use ByTIC\Payments\Models\Purchase\Traits\IsPurchasableModelTrait;
9
10
/**
11
 * Trait CompletePurchaseTrait
12
 * @package ByTIC\Payments\Gateways\Providers\Twispay\Message\Traits
13
 */
14
trait CompletePurchaseTrait
15
{
16
    use HasModelRequest;
17
    use HasGatewayRequestTrait;
18
19
    /**
20
     * @inheritdoc
21
     */
22
    public function getData()
23
    {
24
        $return = parent::getData();
25
        // Add model only if has data
26
        if (count($return)) {
27
            $return['model'] = $this->getModel();
28
        }
29
        return $return;
30
    }
31
32
    /**
33
     * @return bool|mixed
34
     */
35
    protected function parseNotification()
36
    {
37
        if ($this->validateModel()) {
38
            $model = $this->getModel();
39
            $this->updateParametersFromPurchase($model);
40
        }
41
        return parent::parseNotification();
42
    }
43
44
    /**
45
     * @param Gateway $gateway
46
     */
47
    protected function updateParametersFromGateway($gateway)
48
    {
49
        $this->setApiKey($gateway->getParameter('apiKey'));
0 ignored issues
show
Bug introduced by
It seems like setApiKey() 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

49
        $this->/** @scrutinizer ignore-call */ 
50
               setApiKey($gateway->getParameter('apiKey'));
Loading history...
50
    }
51
}
52