Passed
Push — master ( 623e87...a3cc8b )
by Gabriel
03:03
created

CompletePurchaseRequest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 15
c 1
b 0
f 0
dl 0
loc 53
rs 10
ccs 0
cts 17
cp 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getModelIdFromRequest() 0 5 1
A getData() 0 9 3
A updateParametersFromModel() 0 6 1
A parseNotification() 0 8 2
1
<?php
2
3
namespace ByTIC\Payments\Gateways\Providers\Paylike\Message;
4
5
use ByTIC\Omnipay\Paylike\Message\CompletePurchaseRequest as AbstractCompletePurchaseRequest;
6
use ByTIC\Payments\Gateways\Providers\AbstractGateway\Message\Traits\HasModelRequest;
7
use ByTIC\Payments\Gateways\Providers\Paylike\Gateway;
8
use ByTIC\Payments\Models\Purchase\Traits\IsPurchasableModelTrait;
9
10
/**
11
 * Class PurchaseResponse
12
 * @package ByTIC\Payments\Gateways\Providers\Paylike\Message
13
 *
14
 * @method CompletePurchaseResponse send
15
 */
16
class CompletePurchaseRequest extends AbstractCompletePurchaseRequest
17
{
18
    use HasModelRequest;
0 ignored issues
show
introduced by
The trait ByTIC\Payments\Gateways\...\Traits\HasModelRequest requires some properties which are not provided by ByTIC\Payments\Gateways\...CompletePurchaseRequest: $query, $id
Loading history...
19
20
    /**
21
     * @inheritdoc
22
     */
23
    public function getData()
24
    {
25
        $return = parent::getData();
26
        // Add model only if has data
27
        if (count($return) && $this->validateModel()) {
28
            $return['model'] = $this->getModel();
29
        }
30
31
        return $return;
32
    }
33
34
    /**
35
     * @inheritDoc
36
     */
37
    public function getModelIdFromRequest()
38
    {
39
        $modelId = $this->httpRequest->query->get('pOrderId');
40
41
        return $modelId;
42
    }
43
44
    /**
45
     * @return bool|mixed
46
     * @throws \Exception
47
     */
48
    protected function parseNotification()
49
    {
50
        if ($this->validateModel()) {
51
            $model = $this->getModel();
52
            $this->updateParametersFromModel($model);
53
        }
54
55
        return parent::parseNotification();
56
    }
57
58
    /**
59
     * @param IsPurchasableModelTrait $model
60
     *
61
     * @throws \Exception
62
     */
63
    protected function updateParametersFromModel($model)
64
    {
65
        /** @var Gateway $modelGateway */
66
        $modelGateway = $model->getPaymentMethod()->getType()->getGateway();
0 ignored issues
show
Bug introduced by
The method getGateway() does not exist on ByTIC\Payments\Models\Methods\Types\AbstractType. It seems like you code against a sub-type of ByTIC\Payments\Models\Methods\Types\AbstractType such as ByTIC\Payments\Models\Methods\Types\CreditCards. ( Ignorable by Annotation )

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

66
        $modelGateway = $model->getPaymentMethod()->getType()->/** @scrutinizer ignore-call */ getGateway();
Loading history...
67
        $this->setPublicKey($modelGateway->getPublicKey());
68
        $this->setPrivateKey($modelGateway->getPrivateKey());
69
    }
70
}
71