Passed
Push — master ( f03f32...2d9324 )
by Gabriel
10:58
created

PurchaseSessionsTrait::generateTable()   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\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
use Omnipay\Common\Message\ResponseInterface;
9
10
/**
11
 * Trait PurchaseSessionsTrait
12
 * @package ByTIC\Payments\Models\PurchaseSessions
13
 *
14
 * @method PurchaseSessionTrait getNew
15
 */
16
trait PurchaseSessionsTrait
17
{
18
    use CleanupRecordsTrait;
19
20
    /**
21
     * @param string $type
22
     * @param CompletePurchaseResponseTrait|ResponseInterface $response
23
     * @return PurchaseSessionTrait
24
     */
25
    public function createFromResponse($response, $type)
26
    {
27
        /** @var IsPurchasableModelTrait $payment */
28
        $payment = $response->getModel();
0 ignored issues
show
Bug introduced by
The method getModel() does not exist on Omnipay\Common\Message\ResponseInterface. Did you maybe mean getCode()? ( Ignorable by Annotation )

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

28
        /** @scrutinizer ignore-call */ 
29
        $payment = $response->getModel();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29
        $session = $this->generateFromPurchaseType($payment, $type);
30
        $session->populateFromResponse($response);
31
        $session->insert();
32
33
        return $session;
34
    }
35
36
    /**
37
     * @param string $type
38
     * @param IsPurchasableModelTrait $payment
39
     * @return PurchaseSessionTrait
40
     */
41
    public function createFromPurchase($payment, $type)
42
    {
43
        $session = $this->generateFromPurchaseType($payment, $type);
44
        $session->insert();
45
46
        return $session;
47
    }
48
49
    /**
50
     * @param array $params
51
     */
52
    protected function injectParams(&$params = [])
53
    {
54
        $params['order'][] = ['created', 'desc'];
55
56
        parent::injectParams($params);
57
    }
58
59
    /**
60
     * @param IsPurchasableModelTrait $payment
61
     * @param string $type
62
     * @return PurchaseSessionTrait
63
     */
64
    protected function generateFromPurchaseType($payment, $type)
65
    {
66
        $session = $this->generateFromPurchase($payment);
67
        $session->type = $type;
68
        return $session;
69
    }
70
71
    /**
72
     * @param IsPurchasableModelTrait $payment
73
     * @return PurchaseSessionTrait
74
     */
75
    protected function generateFromPurchase($payment)
76
    {
77
        $session = $this->getNew();
78
        $session->populateFromPayment($payment);
79
        $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

79
        $session->populateFromGateway($payment->getPaymentMethod()->getType()->/** @scrutinizer ignore-call */ getGateway());
Loading history...
80
        $session->populateFromRequest();
81
82
        return $session;
83
    }
84
85
    /**
86
     * @return mixed|\Nip\Config\Config
87
     * @throws \Exception
88
     */
89
    protected function generateTable()
90
    {
91
        return config('payments.tables.purchases_sessions','purchases_sessions');
92
    }
93
}
94