Passed
Push — master ( 19a915...d9efc8 )
by Gabriel
14:56
created

SubscriptionTrait::getChargeMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
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\HasPaymentMethodRecord;
10
use ByTIC\Payments\Models\AbstractModels\HasPaymentMethod\HasPaymentMethodRecordTrait;
0 ignored issues
show
Bug introduced by
The type ByTIC\Payments\Models\Ab...aymentMethodRecordTrait 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...
11
use ByTIC\Payments\Models\AbstractModels\HasToken\HasTokenRecord;
12
use ByTIC\Payments\Models\Tokens\Token;
13
use ByTIC\Payments\Models\Transactions\Transaction;
14
use ByTIC\Payments\Models\Transactions\TransactionTrait;
15
use ByTIC\Payments\Subscriptions\ChargeMethods\AbstractMethod;
16
use DateTime;
17
18
/**
19
 * Trait SubscriptionTrait
20
 * @package ByTIC\Payments\Models\Subscriptions
21
 *
22
 * @property int $id_method
23
 * @property int $id_token
24
 * @property int $id_last_transaction
25
 * @property int $id_billing_record
26
 *
27
 * @property string $billing_period
28
 * @property int $billing_interval
29
 * @property int $billing_count
30
 *
31
 * @property string|DateTime $start_at
32
 * @property string|DateTime $cancel_at
33
 * @property string|DateTime $ended_at
34
 * @property string|DateTime $charge_at
35
 *
36
 * @property int $charge_attempts
37
 * @property int $charge_count
38
 * @property int $charge_method
39
 *
40
 * @property string $modified
41
 * @property string $created
42
 *
43
 * @method Transaction getLastTransaction
44
 * @method SubscriptionsTrait getManager
45
 */
46
trait SubscriptionTrait
47
{
48
    use \ByTIC\Models\SmartProperties\RecordsTraits\HasStatus\RecordTrait;
49
    use HasPaymentMethodRecord;
50
    use HasCustomerRecord;
51
    use HasTokenRecord;
52
    use TimestampableTrait;
53
54
    /**
55
     * @var string
56
     */
57
    static protected $createTimestamps = ['created'];
58
59
    /**
60
     * @var string
61
     */
62
    static protected $updateTimestamps = ['modified'];
63
64
    public function bootSubscriptionTrait()
65
    {
66
        $fields = [
67
            'start_at' => 'date',
68
            'cancel_at' => 'date',
69
            'ended_at' => 'date',
70
            'charge_at' => 'datetime'
71
        ];
72
        foreach ($fields as $field => $cast) {
73
            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

73
            if ($this->/** @scrutinizer ignore-call */ hasCast($field)) {
Loading history...
74
                continue;
75
            }
76
            $this->addCast($field, $cast);
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

76
            $this->/** @scrutinizer ignore-call */ 
77
                   addCast($field, $cast);
Loading history...
77
        }
78
        $this->addCast('metadata', AsMetadataObject::class . ':json');
79
    }
80
81
    /**
82
     * @param $key
83
     * @param $value
84
     */
85
    public function addMedata($key, $value)
86
    {
87
        $this->metadata->set($key, $value);
88
    }
89
90
    /**
91
     * @return \ByTIC\Models\SmartProperties\Properties\AbstractProperty\Generic|AbstractMethod
92
     */
93
    public function getChargeMethod()
94
    {
95
        return $this->getSmartProperty('ChargeMethods');
96
    }
97
98
    /**
99
     * @param Transaction|TransactionTrait $transaction
100
     */
101
    public function populateFromLastTransaction($transaction)
102
    {
103
        $this->id_last_transaction = $transaction->id;
104
        $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

104
        $this->/** @scrutinizer ignore-call */ 
105
               getRelation('LastTransaction')->setResults($transaction);
Loading history...
105
    }
106
107
    /**
108
     * @param Token $token
109
     */
110
    public function populateFromToken($token)
111
    {
112
        $this->id_token = $token->id;
113
        $this->getRelation('Token')->setResults($token);
114
    }
115
}
116