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

SubscriptionTrait::bootSubscriptionTrait()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
c 0
b 0
f 0
nc 3
nop 0
dl 0
loc 10
rs 10
1
<?php
2
3
namespace ByTIC\Payments\Models\Subscriptions;
4
5
use ByTIC\DataObjects\Behaviors\Timestampable\TimestampableTrait;
6
use ByTIC\DataObjects\Casts\Metadata\AsMetadataObject;
7
use ByTIC\Omnipay\Common\Models\SubscriptionInterface;
0 ignored issues
show
Bug introduced by
The type ByTIC\Omnipay\Common\Models\SubscriptionInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use ByTIC\Payments\Models\AbstractModels\HasCustomer\HasCustomerRecord;
9
use ByTIC\Payments\Models\AbstractModels\HasPaymentMethod\HasPaymentMethodRecordTrait;
10
use ByTIC\Payments\Models\Tokens\Token;
11
use ByTIC\Payments\Models\Transactions\Transaction;
12
use ByTIC\Payments\Models\Transactions\TransactionTrait;
13
14
/**
15
 * Trait SubscriptionTrait
16
 * @package ByTIC\Payments\Models\Subscriptions
17
 *
18
 * @property int $id_method
19
 * @property int $id_token
20
 * @property int $id_last_transaction
21
 * @property int $id_billing_record
22
 *
23
 * @property string $billing_period
24
 * @property int $billing_interval
25
 * @property int $billing_count
26
 *
27
 * @property string $start_at
28
 * @property string $cancel_at
29
 * @property string $ended_at
30
 * @property string $charge_at
31
 *
32
 * @property string $modified
33
 * @property string $created
34
 *
35
 * @method SubscriptionsTrait getManager
36
 */
37
trait SubscriptionTrait
38
{
39
    use \ByTIC\Models\SmartProperties\RecordsTraits\HasStatus\RecordTrait;
40
    use HasPaymentMethodRecordTrait;
41
    use HasCustomerRecord;
42
    use TimestampableTrait;
43
44
    /**
45
     * @var string
46
     */
47
    static protected $createTimestamps = ['created'];
48
49
    /**
50
     * @var string
51
     */
52
    static protected $updateTimestamps = ['modified'];
53
54
    public function bootSubscriptionTrait()
55
    {
56
        $fields = ['start_at', 'cancel_at', 'ended_at', 'charge_at'];
57
        foreach ($fields as $field) {
58
            if ($this->hasCast($field)) {
0 ignored issues
show
Bug introduced by
It seems like hasCast() 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

58
            if ($this->/** @scrutinizer ignore-call */ hasCast($field)) {
Loading history...
59
                continue;
60
            }
61
            $this->addCast($field, 'datetime');
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

61
            $this->/** @scrutinizer ignore-call */ 
62
                   addCast($field, 'datetime');
Loading history...
62
        }
63
        $this->addCast('metadata', AsMetadataObject::class . ':json');
64
    }
65
66
    /**
67
     * @param $key
68
     * @param $value
69
     */
70
    public function addMedata($key, $value)
71
    {
72
        $this->metadata->set($key, $value);
73
    }
74
75
    /**
76
     * @param Transaction|TransactionTrait $transaction
77
     */
78
    public function populateFromLastTransaction($transaction)
79
    {
80
        $this->id_last_transaction = $transaction->id;
81
        $this->getRelation('LastTransaction')->setResults($transaction);
0 ignored issues
show
Bug introduced by
It seems like getRelation() 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

81
        $this->/** @scrutinizer ignore-call */ 
82
               getRelation('LastTransaction')->setResults($transaction);
Loading history...
82
    }
83
84
    /**
85
     * @param Token $token
86
     */
87
    public function populateFromToken($token)
88
    {
89
        $this->id_token = $token->id;
90
        $this->getRelation('Token')->setResults($token);
91
    }
92
}
93