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

PurchaseSessionTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 14
c 1
b 0
f 1
dl 0
loc 44
rs 10
ccs 0
cts 17
cp 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A populateFromResponse() 0 4 2
A populateFromPayment() 0 6 1
A populateFromRequest() 0 4 1
1
<?php
2
3
namespace ByTIC\Payments\Models\PurchaseSessions;
4
5
use ByTIC\DataObjects\Behaviors\Timestampable\TimestampableTrait;
6
use ByTIC\Payments\Models\AbstractModels\HasGateway\HasGatewayRecordTrait;
7
use ByTIC\Payments\Models\AbstractModels\HasPurchaseParent;
8
9
/**
10
 * Trait PurchaseSessionTrait
11
 * @package ByTIC\Payments\Models\PurchaseSessions
12
 *
13
 * @property string $type
14
 * @property string $new_status
15
 * @property string $gateway
16
 * @property string $post
17
 * @property string $get
18
 * @property string $debug
19
 * @property string $created
20
 *
21
 * @method PurchaseSessionsTrait getManager
22
 */
23
trait PurchaseSessionTrait
24
{
25
    use HasPurchaseParent {
26
        populateFromPayment as populateFromPaymentTrait;
27
    }
28
    use HasGatewayRecordTrait;
29
    use TimestampableTrait;
30
31
    /**
32
     * @var string
33
     */
34
    static protected $createTimestamps = ['created'];
35
36
    /**
37
     * @var string
38
     */
39
    static protected $updateTimestamps = [];
40
41
    /**
42
     * @param $payment
43
     * @return $this
44
     */
45
    public function populateFromPayment($payment)
46
    {
47
        $this->populateFromPaymentTrait($payment);
48
        $this->new_status = (string) $payment->status;
49
50
        return $this;
51
    }
52
53
    /**
54
     * @param $response
55
     */
56
    public function populateFromResponse($response)
57
    {
58
        if (method_exists($response, 'getSessionDebug')) {
59
            $this->debug = $this->getManager()::encodeParams($response->getSessionDebug());
60
        }
61
    }
62
63
    public function populateFromRequest()
64
    {
65
        $this->post = $this->getManager()::encodeParams($_POST);
66
        $this->get = $this->getManager()::encodeParams($_GET);
67
    }
68
}
69