Passed
Push — master ( 133129...87687b )
by Gabriel
12:43
created

TokenTrait::populateFromGateway()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace ByTIC\Payments\Models\Tokens;
4
5
use ByTIC\DataObjects\Behaviors\Timestampable\TimestampableTrait;
6
use ByTIC\Omnipay\Common\Models\TokenInterface;
7
use ByTIC\Payments\Gateways\Providers\AbstractGateway\Traits\GatewayTrait as AbstractGateway;
8
use ByTIC\Payments\Models\AbstractModels\HasGateway\HasGatewayRecordTrait;
9
use ByTIC\Payments\Models\AbstractModels\HasPurchaseParent;
10
use ByTIC\Payments\Models\Methods\PaymentMethod;
11
12
/**
13
 * Trait TokenTrait
14
 * @package ByTIC\Payments\Models\Tokens
15
 *
16
 * @property int $id_method
17
 * @property string $gateway
18
 *
19
 * @property string $token_id
20
 * @property string $expiration
21
 *
22
 * @property string $modified
23
 * @property string $created
24
 *
25
 * @method TokensTrait getManager
26
 */
27
trait TokenTrait
28
{
29
    use HasPurchaseParent;
30
    use HasGatewayRecordTrait;
31
    use TimestampableTrait;
32
33
    /**
34
     * @var string
35
     */
36
    static protected $createTimestamps = ['created'];
37
38
    /**
39
     * @var string
40
     */
41
    static protected $updateTimestamps = ['modified'];
42
43
    /**
44
     * @param PaymentMethod $gateway
45
     */
46
    public function populateFromPaymentMethod($method)
47
    {
48
        $this->id_method = is_object($method) ? $method->id : $method;
49
    }
50
51
    /**
52
     * @param TokenInterface $token
53
     */
54
    public function populateFromToken(TokenInterface $token)
55
    {
56
        $this->token_id = $token->getId();
57
        $this->expiration = $token->getExpirationDate();
58
    }
59
}
60