Passed
Push — master ( 133129...87687b )
by Gabriel
12:43
created

TransactionTrait::populateFromGateway()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
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\Models\AbstractModels\HasGateway\HasGatewayRecordTrait;
9
use ByTIC\Payments\Models\AbstractModels\HasPurchaseParent;
10
use Omnipay\Common\Message\AbstractResponse;
11
12
/**
13
 * Trait TransactionTrait
14
 * @package ByTIC\Payments\Models\Transactions
15
 *
16
 * @property int $id_purchase
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
 */
31
trait TransactionTrait
32
{
33
    use HasPurchaseParent;
34
    use HasGatewayRecordTrait;
35
    use TimestampableTrait;
36
37
    /**
38
     * @var string
39
     */
40
    static protected $createTimestamps = ['created'];
41
42
    /**
43
     * @var string
44
     */
45
    static protected $updateTimestamps = ['modified'];
46
47
    public function bootTransactionTrait()
48
    {
49
        $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

49
        $this->/** @scrutinizer ignore-call */ 
50
               addCast('metadata', AsArrayObject::class . ':json');
Loading history...
50
    }
51
52
    /**
53
     * @return mixed
54
     */
55
    public function getMetadata()
56
    {
57
        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

57
        return $this->/** @scrutinizer ignore-call */ getPropertyValue('metadata');
Loading history...
58
    }
59
60
    public function setMedata($value)
61
    {
62
        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

62
        return $this->/** @scrutinizer ignore-call */ setPropertyValue('metadata', $value);
Loading history...
63
    }
64
65
    /**
66
     * @param $key
67
     * @param $value
68
     */
69
    public function addMedata($key, $value)
70
    {
71
        $metadata = $this->metadata;
72
        $metadata[$key] = $value;
73
        $this->setMedata($metadata);
74
    }
75
76
    /**
77
     * @param AbstractResponse|HasModelProcessedResponse $response
78
     */
79
    public function updateFromResponse($response, $type)
0 ignored issues
show
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

79
    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...
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

79
    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...
80
    {
81
    }
82
}
83