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

CompletePurchaseRequest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 95%

Importance

Changes 4
Bugs 1 Features 1
Metric Value
eloc 17
c 4
b 1
f 1
dl 0
loc 62
ccs 19
cts 20
cp 0.95
rs 10
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A parseNotification() 0 6 1
A generateCtrl() 0 3 1
A getModelCtrl() 0 9 1
A getModelIdFromRequest() 0 7 2
A isValidNotification() 0 9 3
1
<?php
2
3
namespace ByTIC\Payments\Gateways\Providers\Payu\Message;
4
5
use ByTIC\Omnipay\Payu\Message\CompletePurchaseRequest as AbstractCompletePurchaseRequest;
6
use ByTIC\Payments\Gateways\Providers\AbstractGateway\Message\Traits\HasModelRequest;
7
use ByTIC\Payments\Gateways\Providers\Payu\Gateway;
8
use ByTIC\Payments\Models\Purchase\Traits\IsPurchasableModelTrait;
9
10
/**
11
 * Class PurchaseResponse
12
 * @package ByTIC\Omnipay\Payu\Message
13
 */
14
class CompletePurchaseRequest extends AbstractCompletePurchaseRequest
15
{
16
    use Traits\CompletePurchaseRequestTrait;
0 ignored issues
show
introduced by
The trait ByTIC\Payments\Gateways\...etePurchaseRequestTrait requires some properties which are not provided by ByTIC\Payments\Gateways\...CompletePurchaseRequest: $query, $id
Loading history...
17
18
    /**
19
     * @inheritdoc
20
     */
21 8
    public function isValidNotification()
22
    {
23 8
        if ($this->hasGet('ctrl')) {
24 2
            if ($this->validateModel()) {
25 2
                return parent::isValidNotification();
26
            }
27
        }
28
29 6
        return false;
30
    }
31
32
    /**
33
     * @return string
34
     */
35 2
    public function getModelIdFromRequest()
36
    {
37 2
        if ($this->httpRequest->query->has('hash')) {
38 2
            return $this->httpRequest->query->get('hash');
39
        }
40
41
        return $this->httpRequest->query->get('id');
42
    }
43
44
    /**
45
     * @inheritDoc
46
     */
47 2
    protected function parseNotification()
48
    {
49 2
        $model = $this->getModel();
50 2
        $this->updateParametersFromPurchase($model);
51
52 2
        return parent::parseNotification();
53
    }
54
55
56
    /**
57
     * @inheritdoc
58
     */
59 2
    protected function generateCtrl()
60
    {
61 2
        return $this->getModelCtrl();
62
    }
63
64
    /**
65
     * @return string
66
     */
67 2
    public function getModelCtrl()
68
    {
69
        /** @var IsPurchasableModelTrait $model */
70 2
        $model = $this->getModel();
71
        /** @var Gateway $gateway */
72 2
        $gateway = $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

72
        $gateway = $model->getPaymentMethod()->getType()->/** @scrutinizer ignore-call */ getGateway();
Loading history...
73 2
        $purchaseRequest = $gateway->purchaseFromModel($model);
74
75 2
        return $purchaseRequest->getCtrl();
76
    }
77
}
78