소스 검색

remove unused casts

3.x
Andrew Wallo 4 달 전
부모
커밋
bd8111c0eb

+ 0
- 44
app/Casts/DocumentMoneyCast.php 파일 보기

@@ -1,44 +0,0 @@
1
-<?php
2
-
3
-namespace App\Casts;
4
-
5
-use App\Utilities\Currency\CurrencyAccessor;
6
-use App\Utilities\Currency\CurrencyConverter;
7
-use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
8
-use Illuminate\Database\Eloquent\Model;
9
-use UnexpectedValueException;
10
-
11
-class DocumentMoneyCast implements CastsAttributes
12
-{
13
-    /**
14
-     * Cast the given value.
15
-     *
16
-     * @param  array<string, mixed>  $attributes
17
-     */
18
-    public function get(Model $model, string $key, mixed $value, array $attributes): mixed
19
-    {
20
-        $currency_code = $attributes['currency_code'] ?? CurrencyAccessor::getDefaultCurrency();
21
-
22
-        if ($value !== null) {
23
-            return CurrencyConverter::convertCentsToFloat($value, $currency_code);
24
-        }
25
-
26
-        return 0.0;
27
-    }
28
-
29
-    /**
30
-     * Prepare the given value for storage.
31
-     *
32
-     * @param  array<string, mixed>  $attributes
33
-     */
34
-    public function set(Model $model, string $key, mixed $value, array $attributes): mixed
35
-    {
36
-        if (is_numeric($value)) {
37
-            $value = (string) $value;
38
-        } elseif (! is_string($value)) {
39
-            throw new UnexpectedValueException('Expected string or numeric value for money cast');
40
-        }
41
-
42
-        return CurrencyConverter::prepareForAccessor($value, 'USD');
43
-    }
44
-}

+ 0
- 23
app/Casts/JournalEntryCast.php 파일 보기

@@ -1,23 +0,0 @@
1
-<?php
2
-
3
-namespace App\Casts;
4
-
5
-use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
6
-use Illuminate\Database\Eloquent\Model;
7
-use UnexpectedValueException;
8
-
9
-class JournalEntryCast implements CastsAttributes
10
-{
11
-    public function get(Model $model, string $key, mixed $value, array $attributes): int
12
-    {
13
-        return (int) $value;
14
-    }
15
-
16
-    /**
17
-     * @throws UnexpectedValueException
18
-     */
19
-    public function set(Model $model, string $key, mixed $value, array $attributes): int
20
-    {
21
-        return (int) $value;
22
-    }
23
-}

+ 0
- 63
app/Casts/TransactionAmountCast.php 파일 보기

@@ -1,63 +0,0 @@
1
-<?php
2
-
3
-namespace App\Casts;
4
-
5
-use App\Models\Banking\BankAccount;
6
-use App\Utilities\Currency\CurrencyAccessor;
7
-use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
8
-use Illuminate\Database\Eloquent\Model;
9
-use UnexpectedValueException;
10
-
11
-class TransactionAmountCast implements CastsAttributes
12
-{
13
-    /**
14
-     * Static cache to persist across instances
15
-     */
16
-    private static array $currencyCache = [];
17
-
18
-    /**
19
-     * Eagerly load all required bank accounts at once if needed
20
-     */
21
-    private function loadMissingBankAccounts(array $ids): void
22
-    {
23
-        $missingIds = array_filter($ids, static fn ($id) => ! isset(self::$currencyCache[$id]) && $id !== null);
24
-
25
-        if (empty($missingIds)) {
26
-            return;
27
-        }
28
-
29
-        /** @var BankAccount[] $accounts */
30
-        $accounts = BankAccount::with('account')
31
-            ->whereIn('id', $missingIds)
32
-            ->get();
33
-
34
-        foreach ($accounts as $account) {
35
-            self::$currencyCache[$account->id] = $account->account->currency_code ?? CurrencyAccessor::getDefaultCurrency();
36
-        }
37
-    }
38
-
39
-    public function get(Model $model, string $key, mixed $value, array $attributes): int
40
-    {
41
-        return (int) $value;
42
-    }
43
-
44
-    /**
45
-     * @throws UnexpectedValueException
46
-     */
47
-    public function set(Model $model, string $key, mixed $value, array $attributes): int
48
-    {
49
-        return (int) $value;
50
-    }
51
-
52
-    /**
53
-     * Get currency code from the cache or use default
54
-     */
55
-    private function getCurrencyCodeFromBankAccountId(?int $bankAccountId): string
56
-    {
57
-        if ($bankAccountId === null) {
58
-            return CurrencyAccessor::getDefaultCurrency();
59
-        }
60
-
61
-        return self::$currencyCache[$bankAccountId] ?? CurrencyAccessor::getDefaultCurrency();
62
-    }
63
-}

+ 0
- 14
app/Casts/TrimLeadingZeroCast.php 파일 보기

@@ -1,14 +0,0 @@
1
-<?php
2
-
3
-namespace App\Casts;
4
-
5
-use Illuminate\Contracts\Database\Eloquent\CastsInboundAttributes;
6
-use Illuminate\Database\Eloquent\Model;
7
-
8
-class TrimLeadingZeroCast implements CastsInboundAttributes
9
-{
10
-    public function set(Model $model, string $key, mixed $value, array $attributes): int
11
-    {
12
-        return (int) ltrim($value, '0');
13
-    }
14
-}

+ 0
- 1
app/Models/Accounting/DocumentLineItem.php 파일 보기

@@ -3,7 +3,6 @@
3 3
 namespace App\Models\Accounting;
4 4
 
5 5
 use Akaunting\Money\Money;
6
-use App\Casts\DocumentMoneyCast;
7 6
 use App\Concerns\Blamable;
8 7
 use App\Concerns\CompanyOwned;
9 8
 use App\Enums\Accounting\AdjustmentCategory;

+ 0
- 2
app/Models/Accounting/JournalEntry.php 파일 보기

@@ -2,7 +2,6 @@
2 2
 
3 3
 namespace App\Models\Accounting;
4 4
 
5
-use App\Casts\JournalEntryCast;
6 5
 use App\Collections\Accounting\JournalEntryCollection;
7 6
 use App\Concerns\Blamable;
8 7
 use App\Concerns\CompanyOwned;
@@ -32,7 +31,6 @@ class JournalEntry extends Model
32 31
 
33 32
     protected $casts = [
34 33
         'type' => JournalEntryType::class,
35
-        'amount' => JournalEntryCast::class,
36 34
     ];
37 35
 
38 36
     public function account(): BelongsTo

Loading…
취소
저장