Passed
Push — master ( c0f464...9c6e80 )
by Gabriel
11:21
created

TokenTrait::populateFromPaymentMethod()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
c 0
b 0
f 0
nc 2
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\HasPurchaseParent;
9
use ByTIC\Payments\Models\Methods\PaymentMethod;
10
11
/**
12
 * Trait TokenTrait
13
 * @package ByTIC\Payments\Models\Tokens
14
 *
15
 * @property int $id_method
16
 * @property string $gateway
17
 *
18
 * @property string $token_id
19
 * @property string $expiration
20
 *
21
 * @property string $modified
22
 * @property string $created
23
 *
24
 * @method TokensTrait getManager
25
 */
26
trait TokenTrait
27
{
28
    use HasPurchaseParent;
29
    use TimestampableTrait;
30
31
    /**
32
     * @var string
33
     */
34
    static protected $createTimestamps = ['created'];
35
36
    /**
37
     * @var string
38
     */
39
    static protected $updateTimestamps = ['modified'];
40
41
    /**
42
     * @param AbstractGateway $gateway
43
     */
44
    public function populateFromGateway($gateway)
45
    {
46
        $this->gateway = $gateway->getName();
47
    }
48
49
    /**
50
     * @param PaymentMethod $gateway
51
     */
52
    public function populateFromPaymentMethod($method)
53
    {
54
        $this->id_method = is_object($method) ? $method->id : $method;
55
    }
56
57
    /**
58
     * @param TokenInterface $token
59
     */
60
    public function populateFromToken(TokenInterface $token)
61
    {
62
        $this->token_id = $token->getId();
63
        $this->expiration = $token->getExpirationDate();
64
    }
65
}
66