GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Transaction   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 67
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A cancel() 0 22 2
A isExpired() 0 4 2
1
<?php
2
3
namespace Goodoneuz\PayUz\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Goodoneuz\PayUz\Http\Classes\DataFormat;
7
use Illuminate\Database\Eloquent\SoftDeletes;
8
9
class Transaction extends Model
10
{
11
    use SoftDeletes;
12
13
    protected $dates    = [
14
        'deleted_at'
15
    ];
16
17
    protected $fillable = [
18
        'payment_system', //varchar 191
19
        'system_transaction_id', // varchar 191
20
        'amount', // double (15,5)
21
        'currency_code', // int(11)
22
        'state', // int(11)
23
        'updated_time', //datetime
24
        'comment', // varchar 191
25
        'transactionable_type',
26
        'transactionable_id',
27
        'detail', // details
28
    ];
29
    const TIMEOUT = 43200000;
30
31
    const STATE_CREATED = 1;
32
    const STATE_COMPLETED = 2;
33
    const STATE_CANCELLED = -1;
34
    const STATE_CANCELLED_AFTER_COMPLETE = -2;
35
36
    const REASON_RECEIVERS_NOT_FOUND = 1;
37
    const REASON_PROCESSING_EXECUTION_FAILED = 2;
38
    const REASON_EXECUTION_FAILED = 3;
39
    const REASON_CANCELLED_BY_TIMEOUT = 4;
40
    const REASON_FUND_RETURNED = 5;
41
    const REASON_UNKNOWN = 10;
42
43
    const CURRENCY_CODE_UZS = 860;
44
    const CURRENCY_CODE_RUB = 643;
45
    const CURRENCY_CODE_USD = 840;
46
    const CURRENCY_CODE_EUR = 978;
47
48
    public function cancel($reason)
49
    {
50
        $this->updated_time = DataFormat::timestamp(true);
51
52
        if ($this->state == self::STATE_COMPLETED) {
53
            // Scenario: CreateTransaction -> PerformTransaction -> CancelTransaction
54
            $this->state = self::STATE_CANCELLED_AFTER_COMPLETE;
55
        } else {
56
            // Scenario: CreateTransaction -> CancelTransaction
57
            $this->state = self::STATE_CANCELLED;
58
        }
59
60
        $this->comment = $reason;
61
        $detail = json_decode($this->detail,true);
62
        $detail['cancel_time'] = $this->updated_time;
63
        $detail = json_encode($detail);
64
        $this->detail = $detail;
65
66
67
68
        $this->update();
69
    }
70
    public function isExpired()
71
    {
72
        return $this->state == self::STATE_CREATED && DataFormat::datetime2timestamp($this->updated_time) - time() > self::TIMEOUT;
73
    }
74
75
}
76