Test Failed
Pull Request — master (#40)
by Бабичев
03:32
created

Transaction::payable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Bavix\Wallet\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Relations\BelongsTo;
7
use Illuminate\Database\Eloquent\Relations\MorphTo;
8
use Bavix\Wallet\Models\Wallet as WalletModel;
9
use Bavix\Wallet\Interfaces\Wallet;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Bavix\Wallet\Models\Wallet. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
10
11
/**
12
 * Class Transaction
13
 * @package Bavix\Wallet\Models
14
 *
15
 * @property string $payable_type
16
 * @property int $payable_id
17
 * @property string $uuid
18
 * @property string $type
19
 * @property int $amount
20
 * @property bool $confirmed
21
 * @property array $meta
22
 * @property Wallet $payable
23
 * @property WalletModel $wallet
24
 */
25
class Transaction extends Model
26
{
27
28
    public const TYPE_DEPOSIT = 'deposit';
29
    public const TYPE_WITHDRAW = 'withdraw';
30
31
    /**
32
     * @var array
33
     */
34
    protected $fillable = [
35
        'payable_type',
36
        'payable_id',
37
        'wallet_id',
38
        'uuid',
39
        'type',
40
        'amount',
41
        'confirmed',
42
        'meta',
43
    ];
44
45
    /**
46
     * @var array
47
     */
48
    protected $casts = [
49
        'amount' => 'int',
50
        'confirmed' => 'bool',
51
        'meta' => 'json'
52
    ];
53 39
54
    /**
55 39
     * @return string
56 39
     */
57
    public function getTable(): string
58
    {
59 39
        if (!$this->table) {
60
            $this->table = \config('wallet.transaction.table');
61
        }
62
63
        return parent::getTable();
64
    }
65 6
66
    /**
67 6
     * @return MorphTo
68
     */
69
    public function payable(): MorphTo
70
    {
71
        return $this->morphTo();
72
    }
73
74
    /**
75
     * @return BelongsTo
76
     */
77
    public function wallet(): BelongsTo
78
    {
79
        return $this->belongsTo(\config('wallet.wallet.model'));
80
    }
81
82
}
83