Passed
Push — master ( 96d33b...43186b )
by Gabriel
13:27
created

IsPurchasableModelTrait::newSubscription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
ccs 0
cts 0
cp 0
crap 2
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 ByTIC\Payments\Models\PurchaseSessions\PurchaseSessionTrait;
10
use ByTIC\Payments\Subscriptions\SubscriptionBuilder;
11
use Exception;
12
use Nip\Records\Collections\Associated;
13
use Omnipay\Common\Message\RequestInterface;
14
15
/**
16
 * Trait IsPurchasableModelTrait
17
 * @package ByTIC\Payments\Models\Purchase\Traits
18
 *
19
 * @property int $id
20
 * @property string $status
21
 * @property string $status_notes
22
 * @property string $received
23
 * @property string $created
24
 *
25
 * @method string getConfirmURL()
26
 * @method string getIpnURL()
27
 * @method update()
28
 * @method string getClassName()
29
 * @method string getStatus()
30
 *
31
 * @method Records getManager()
32
 * @method PurchaseSessionTrait[]|Associated getPurchasesSessions()
33
 */
34
trait IsPurchasableModelTrait
35
{
36
    use IsPurchasableTrait;
37
38
    /**
39
     * @return RequestInterface
40
     */
41
    public function getPurchaseRequest()
42
    {
43
        return $this->getPaymentGateway()->purchaseFromModel($this);
44
    }
45
46
    /**
47
     * @return bool|\ByTIC\Payments\Gateways\Providers\AbstractGateway\Traits\GatewayTrait|null
48
     */
49
    public function getPaymentGateway()
50
    {
51
        return $this->getPaymentMethod()->getGateway();
52
    }
53
54
    /**
55
     * @return RecordTrait
56
     */
57
    abstract public function getPaymentMethod();
58
59
    /**
60
     * @param $note
61
     */
62
    public function saveGatewayNote($note)
63
    {
64
        $this->setGatewayNotes($note);
65
        $this->update();
66
    }
67
68
    /**
69
     * @param $note
70
     */
71
    public function setGatewayNotes($note)
72
    {
73
        $this->status_notes = $note;
74
    }
75 6
76
    /**
77 6
     * @return array
78 6
     * @throws Exception
79 6
     */
80
    public function getPurchaseParametersCard()
81
    {
82
        $params = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $params is dead and can be removed.
Loading history...
83
        $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...
84
        if (!is_object($billing)) {
85
            throw new Exception(
86
                sprintf(
87 6
                    'PurchaseBillingRecord is not an object in [%s]',
88
                    $this->getClassName()
89
                )
90
            );
91
        }
92
        if (!in_array(BillingRecordTrait::class, class_uses($billing))) {
93
            throw new Exception(
94
                sprintf(
95
                    'Billing record in %s must use BillingRecordTrait %s',
96 6
                    $this->getClassName(),
97 6
                    BillingRecordTrait::class
98 6
                )
99 6
            );
100 6
        }
101 6
        $params = [];
102 6
        $params['firstName'] = $billing->getFirstName();
103
        $params['lastName'] = $billing->getLastName();
104 6
        $params['email'] = $billing->getEmail();
105
        $params['phone'] = $billing->getPurchasePhone();
106
        $params['city'] = $billing->getPurchaseCity();
107
        $params['country'] = $billing->getPurchaseCountry();
108
109
        return $params;
110
    }
111
112
    /**
113
     * @return BillingRecord|null
114
     */
115
    public function getPurchaseBillingRecord()
116
    {
117
        return null;
118
    }
119
120
    /**
121
     * @return SubscriptionBuilder
122
     */
123
    public function newSubscription()
124
    {
125
        return SubscriptionBuilder::fromPurchase($this);
126
    }
127
128
    /**
129
     * @return mixed
130
     */
131
    public function getConfirmStatusTitle()
132
    {
133
        return $this->getManager()->getMessage('confirm.' . $this->getStatus()->getName());
134
    }
135
}
136