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

TransactionTrait::updateFromResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 2
rs 10
1
<?php
2
3
namespace ByTIC\Payments\Models\Transactions;
4
5
use ByTIC\DataObjects\Behaviors\Timestampable\TimestampableTrait;
6
use ByTIC\DataObjects\Casts\Metadata\AsMetadataObject;
7
use ByTIC\Payments\Models\AbstractModels\HasGateway\HasGatewayRecordTrait;
8
use ByTIC\Payments\Models\AbstractModels\HasPurchaseParent;
9
use ByTIC\Payments\Models\Subscriptions\Subscription;
10
11
/**
12
 * Trait TransactionTrait
13
 * @package ByTIC\Payments\Models\Transactions
14
 *
15
 * @property int $id_purchase
16
 * @property int $id_subscription
17
 * @property int $id_token
18
 * @property string $gateway
19
 * @property string $currency
20
 *
21
 * @property string $card
22
 * @property string $code A response code from the payment gateway
23
 * @property string $reference A reference provided by the gateway to represent this transaction
24
 * @property string $metadata
25
 *
26
 * @property string $modified
27
 * @property string $created
28
 *
29
 * @method TransactionsTrait getManager
30
 * @method Subscription getSubscription
31
 */
32
trait TransactionTrait
33
{
34
    use HasPurchaseParent;
35
    use HasGatewayRecordTrait;
36
    use TimestampableTrait;
37
38
    /**
39
     * @var string
40
     */
41
    static protected $createTimestamps = ['created'];
42
43
    /**
44
     * @var string
45
     */
46
    static protected $updateTimestamps = ['modified'];
47
48
    public function bootTransactionTrait()
49
    {
50
        $this->addCast('metadata', AsMetadataObject::class . ':json');
0 ignored issues
show
Bug introduced by
It seems like addCast() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

50
        $this->/** @scrutinizer ignore-call */ 
51
               addCast('metadata', AsMetadataObject::class . ':json');
Loading history...
51
    }
52
53
    /**
54
     * @param Subscription $method
55
     */
56
    public function populateFromSubscription($subscription)
57
    {
58
        $this->id_subscription = is_object($subscription) ? $subscription->id : $subscription;
59
    }
60
    /**
61
     * @param $key
62
     * @param $value
63
     */
64
    public function addMedata($key, $value)
65
    {
66
        $this->metadata->set($key, $value);
67
    }
68
69
    public function isSubscription(): bool
70
    {
71
        return $this->id_subscription > 0;
72
    }
73
}
74