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

TransactionTrait::getMetadata()   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\Transactions;
4
5
use ByTIC\DataObjects\Behaviors\Timestampable\TimestampableTrait;
6
use ByTIC\DataObjects\Casts\AsArrayObject;
7
use ByTIC\Payments\Gateways\Providers\AbstractGateway\Message\Traits\HasModelProcessedResponse;
8
use ByTIC\Payments\Gateways\Providers\AbstractGateway\Traits\GatewayTrait as AbstractGateway;
9
use ByTIC\Payments\Models\AbstractModels\HasPurchaseParent;
10
use Nip\MailModule\Models\EmailsTable\EmailTrait;
11
use Nip\Records\AbstractModels\RecordManager;
12
use Nip\Records\EventManager\Events\Event;
13
use Nip\Records\Record;
14
use Omnipay\Common\Message\AbstractResponse;
15
16
/**
17
 * Trait TransactionTrait
18
 * @package ByTIC\Payments\Models\Transactions
19
 *
20
 * @property int $id_purchase
21
 * @property int $id_token
22
 * @property string $gateway
23
 * @property string $currency
24
 *
25
 * @property string $card
26
 * @property string $code A response code from the payment gateway
27
 * @property string $reference A reference provided by the gateway to represent this transaction
28
 * @property string $metadata
29
 *
30
 * @property string $modified
31
 * @property string $created
32
 *
33
 * @method TransactionsTrait getManager
34
 */
35
trait TransactionTrait
36
{
37
    use HasPurchaseParent;
38
    use TimestampableTrait;
39
40
    /**
41
     * @var string
42
     */
43
    static protected $createTimestamps = ['created'];
44
45
    /**
46
     * @var string
47
     */
48
    static protected $updateTimestamps = ['modified'];
49
50
    public function bootTransactionTrait()
51
    {
52
        $this->addCast('metadata', AsArrayObject::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

52
        $this->/** @scrutinizer ignore-call */ 
53
               addCast('metadata', AsArrayObject::class . ':json');
Loading history...
53
    }
54
55
    /**
56
     * @return mixed
57
     */
58
    public function getMetadata()
59
    {
60
        return $this->getPropertyValue('metadata');
0 ignored issues
show
Bug introduced by
It seems like getPropertyValue() 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

60
        return $this->/** @scrutinizer ignore-call */ getPropertyValue('metadata');
Loading history...
61
    }
62
63
    public function setMedata($value)
64
    {
65
        return $this->setPropertyValue('metadata', $value);
0 ignored issues
show
Bug introduced by
It seems like setPropertyValue() 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

65
        return $this->/** @scrutinizer ignore-call */ setPropertyValue('metadata', $value);
Loading history...
66
    }
67
68
    /**
69
     * @param $key
70
     * @param $value
71
     */
72
    public function addMedata($key, $value)
73
    {
74
        $metadata = $this->metadata;
75
        $metadata[$key] = $value;
76
        $this->setMedata($metadata);
77
    }
78
79
    /**
80
     * @param AbstractResponse|HasModelProcessedResponse $response
81
     */
82
    public function updateFromResponse($response, $type)
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

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

82
    public function updateFromResponse($response, /** @scrutinizer ignore-unused */ $type)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $response is not used and could be removed. ( Ignorable by Annotation )

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

82
    public function updateFromResponse(/** @scrutinizer ignore-unused */ $response, $type)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
83
    {
84
    }
85
86
    /**
87
     * @param AbstractGateway $gateway
88
     */
89
    public function populateFromGateway($gateway)
90
    {
91
        $this->gateway = $gateway->getName();
92
    }
93
}
94