| Total Complexity | 5 |
| Total Lines | 69 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 26 | class Transaction extends Model |
||
| 27 | { |
||
| 28 | |||
| 29 | public const TYPE_DEPOSIT = 'deposit'; |
||
| 30 | public const TYPE_WITHDRAW = 'withdraw'; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var array |
||
| 34 | */ |
||
| 35 | protected $fillable = [ |
||
| 36 | 'payable_type', |
||
| 37 | 'payable_id', |
||
| 38 | 'wallet_id', |
||
| 39 | 'uuid', |
||
| 40 | 'type', |
||
| 41 | 'amount', |
||
| 42 | 'confirmed', |
||
| 43 | 'meta', |
||
| 44 | ]; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var array |
||
| 48 | */ |
||
| 49 | protected $casts = [ |
||
| 50 | 'wallet_id' => 'int', |
||
| 51 | 'amount' => 'int', |
||
| 52 | 'confirmed' => 'bool', |
||
| 53 | 'meta' => 'json' |
||
| 54 | ]; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @inheritDoc |
||
| 58 | */ |
||
| 59 | 92 | public function getCasts(): array |
|
| 60 | { |
||
| 61 | 92 | $this->casts = array_merge( |
|
| 62 | 92 | $this->casts, |
|
| 63 | 92 | config('wallet.transaction.casts', []) |
|
| 64 | ); |
||
| 65 | |||
| 66 | 92 | return parent::getCasts(); |
|
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @return string |
||
| 71 | */ |
||
| 72 | 132 | public function getTable(): string |
|
| 73 | { |
||
| 74 | 132 | if (!$this->table) { |
|
| 75 | 132 | $this->table = config('wallet.transaction.table', 'transactions'); |
|
| 76 | } |
||
| 77 | |||
| 78 | 132 | return parent::getTable(); |
|
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @return MorphTo |
||
| 83 | */ |
||
| 84 | 7 | public function payable(): MorphTo |
|
| 85 | { |
||
| 86 | 7 | return $this->morphTo(); |
|
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @return BelongsTo |
||
| 91 | */ |
||
| 92 | 27 | public function wallet(): BelongsTo |
|
| 95 | } |
||
| 96 | |||
| 97 | } |
||
| 98 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare 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.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/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: