Passed
Push — master ( b2ca99...77b7f1 )
by Gabriel
05:51 queued 13s
created

PurchaseSessionsTrait::injectParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 2
c 1
b 0
f 1
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace ByTIC\Payments\Models\PurchaseSessions;
4
5
use ByTIC\Payments\Gateways\Providers\AbstractGateway\Message\Traits\CompletePurchaseResponseTrait;
6
use ByTIC\Payments\Models\Purchase\Traits\IsPurchasableModelTrait;
7
use ByTIC\Payments\Models\PurchaseSessions\Traits\Cleanup\RecordsTrait as CleanupRecordsTrait;
8
9
/**
10
 * Trait PurchaseSessionsTrait
11
 * @package ByTIC\Payments\Models\PurchaseSessions
12
 *
13
 * @method PurchaseSessionTrait getNew
14
 */
15
trait PurchaseSessionsTrait
16
{
17
    use CleanupRecordsTrait;
18
19
    /**
20
     * @param string $type
21
     * @param CompletePurchaseResponseTrait $response
22
     * @return PurchaseSessionTrait
23
     */
24
    public function createFromResponse($response, $type)
25
    {
26
        /** @var IsPurchasableModelTrait $payment */
27
        $payment = $response->getModel();
28
        $session = $this->generateFromPurchaseType($payment, $type);
29
        $session->populateFromResponse($response);
30
        $session->insert();
31
32
        return $session;
33
    }
34
35
    /**
36
     * @param string $type
37
     * @param IsPurchasableModelTrait $payment
38
     * @return PurchaseSessionTrait
39
     */
40
    public function createFromPurchase($payment, $type)
41
    {
42
        $session = $this->generateFromPurchaseType($payment, $type);
43
        $session->insert();
44
45
        return $session;
46
    }
47
48
    /**
49
     * @param array $params
50
     */
51
    protected function injectParams(&$params = [])
52
    {
53
        $params['order'][] = ['created', 'desc'];
54
55
        parent::injectParams($params);
56
    }
57
58
    /**
59
     * @param IsPurchasableModelTrait $payment
60
     * @param string $type
61
     * @return PurchaseSessionTrait
62
     */
63
    protected function generateFromPurchaseType($payment, $type)
64
    {
65
        $session = $this->generateFromPurchase($payment);
66
        $session->type = $type;
67
        return $session;
68
    }
69
70
    /**
71
     * @param IsPurchasableModelTrait $payment
72
     * @return PurchaseSessionTrait
73
     */
74
    protected function generateFromPurchase($payment)
75
    {
76
        $session = $this->getNew();
77
        $session->populateFromPayment($payment);
78
        $session->populateFromGateway($payment->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

78
        $session->populateFromGateway($payment->getPaymentMethod()->getType()->/** @scrutinizer ignore-call */ getGateway());
Loading history...
79
        $session->populateFromRequest();
80
81
        return $session;
82
    }
83
}
84