Passed
Push — master ( 1803d2...fbfbcb )
by Gabriel
06:19
created

IsPurchasableModelTrait   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Test Coverage

Coverage 35.14%

Importance

Changes 4
Bugs 1 Features 2
Metric Value
wmc 9
eloc 30
c 4
b 1
f 2
dl 0
loc 92
ccs 13
cts 37
cp 0.3514
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getPurchaseBillingRecord() 0 3 1
A setGatewayNotes() 0 3 1
A getPurchaseParametersCard() 0 30 3
A getPaymentGateway() 0 3 1
A saveGatewayNote() 0 4 1
A getPurchaseRequest() 0 3 1
A getConfirmStatusTitle() 0 3 1
1
<?php
2
3
namespace ByTIC\Payments\Models\Purchase\Traits;
4
5
use ByTIC\Common\Records\Records;
6
use ByTIC\Payments\Models\BillingRecord\Traits\RecordTrait as BillingRecord;
7
use ByTIC\Payments\Models\BillingRecord\Traits\RecordTrait as BillingRecordTrait;
8
use ByTIC\Payments\Models\Methods\Traits\RecordTrait;
9
use Exception;
10
use Omnipay\Common\Message\RequestInterface;
11
12
/**
13
 * Class MethodTrait
14
 * @package ByTIC\Payments\Traits
15
 *
16
 * @property int $id
17
 * @property string $status
18
 * @property string $status_notes
19
 * @property string $received
20
 * @property string $created
21
 *
22
 * @method string getConfirmURL()
23
 * @method string getIpnURL()
24
 * @method Records getManager()
25
 * @method update()
26
 * @method string getClassName()
27
 * @method string getStatus()
28
 */
29
trait IsPurchasableModelTrait
30
{
31
    use IsPurchasableTrait;
32
33
    /**
34
     * @return RequestInterface
35
     */
36
    public function getPurchaseRequest()
37
    {
38
        return $this->getPaymentGateway()->purchaseFromModel($this);
39
    }
40
41
    /**
42
     * @return bool|\ByTIC\Payments\Gateways\Providers\AbstractGateway\Traits\GatewayTrait|null
43
     */
44
    public function getPaymentGateway()
45
    {
46
        return $this->getPaymentMethod()->getGateway();
47
    }
48
49
    /**
50
     * @return RecordTrait
51
     */
52
    abstract public function getPaymentMethod();
53
54
    /**
55
     * @param $note
56
     */
57
    public function saveGatewayNote($note)
58
    {
59
        $this->setGatewayNotes($note);
60
        $this->update();
61
    }
62
63
    /**
64
     * @param $note
65
     */
66
    public function setGatewayNotes($note)
67
    {
68
        $this->status_notes = $note;
69
    }
70
71
    /**
72
     * @return array
73
     * @throws Exception
74
     */
75 7
    public function getPurchaseParametersCard()
76
    {
77 7
        $params = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $params is dead and can be removed.
Loading history...
78 7
        $billing = $this->getPurchaseBillingRecord();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $billing is correct as $this->getPurchaseBillingRecord() targeting ByTIC\Payments\Models\Pu...PurchaseBillingRecord() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
79 7
        if (!is_object($billing)) {
80
            throw new Exception(
81
                sprintf(
82
                    'PurchaseBillingRecord is not an object in [%s]',
83
                    $this->getClassName()
84
                )
85
            );
86
        }
87 7
        if (!in_array(BillingRecordTrait::class, class_uses($billing))) {
88
            throw new Exception(
89
                sprintf(
90
                    'Billing record in %s must use BillingRecordTrait %s',
91
                    $this->getClassName(),
92
                    BillingRecordTrait::class
93
                )
94
            );
95
        }
96 7
        $params = [];
97 7
        $params['firstName'] = $billing->getFirstName();
98 7
        $params['lastName'] = $billing->getLastName();
99 7
        $params['email'] = $billing->getEmail();
100 7
        $params['phone'] = $billing->getPurchasePhone();
101 7
        $params['city'] = $billing->getPurchaseCity();
102 7
        $params['country'] = $billing->getPurchaseCountry();
103
104 7
        return $params;
105
    }
106
107
    /**
108
     * @return BillingRecord|null
109
     */
110
    public function getPurchaseBillingRecord()
111
    {
112
        return null;
113
    }
114
115
    /**
116
     * @return mixed
117
     */
118
    public function getConfirmStatusTitle()
119
    {
120
        return $this->getManager()->getMessage('confirm.'.$this->getStatus()->getName());
121
    }
122
}
123