Passed
Push — master ( ba21e2...5468d0 )
by Gabriel
15:15
created

SubscriptionTrait::getName()   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
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
    public function getName()
55
    {
56
        return $this->getManager()->getLabel('title.singurlar') . ' #' . $this->id;
0 ignored issues
show
Bug introduced by
The method getLabel() does not exist on ByTIC\Payments\Models\Su...ions\SubscriptionsTrait. Did you maybe mean getTable()? ( Ignorable by Annotation )

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

56
        return $this->getManager()->/** @scrutinizer ignore-call */ getLabel('title.singurlar') . ' #' . $this->id;

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
57
    }
58
59
    /**
60
     * @var string
61
     */
62
    protected static $createTimestamps = ['created'];
63
64
    /**
65
     * @var string
66
     */
67
    protected static $updateTimestamps = ['modified'];
68
69
    public function bootSubscriptionTrait()
70
    {
71
        $fields = [
72
            'start_at' => 'date',
73
            'cancel_at' => 'date',
74
            'ended_at' => 'date',
75
            'charge_at' => 'datetime'
76
        ];
77
        foreach ($fields as $field => $cast) {
78
            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

78
            if ($this->/** @scrutinizer ignore-call */ hasCast($field)) {
Loading history...
79
                continue;
80
            }
81
            $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

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

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