Skip to content

Commit

Permalink
Merge pull request #877 from gkmk/v11-receivedTransfers
Browse files Browse the repository at this point in the history
[11.x] received transfers
  • Loading branch information
rez1dent3 authored Feb 1, 2024
2 parents cf3858c + 543fc83 commit d96abf3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Interfaces/Wallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,9 @@ public function transactions(): MorphMany;
* @return HasMany<Transfer>
*/
public function transfers(): HasMany;

/**
* @return HasMany<Transfer>
*/
public function receivedTransfers(): HasMany;
}
1 change: 1 addition & 0 deletions src/Models/Wallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Bavix\Wallet\Internal\Service\MathServiceInterface;
use Bavix\Wallet\Internal\Service\UuidFactoryServiceInterface;
use Bavix\Wallet\Services\AtomicServiceInterface;
use Bavix\Wallet\Services\CastServiceInterface;
use Bavix\Wallet\Services\RegulatorServiceInterface;
use Bavix\Wallet\Traits\CanConfirm;
use Bavix\Wallet\Traits\CanExchange;
Expand Down
13 changes: 13 additions & 0 deletions src/Traits/HasWallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,17 @@ public function transfers(): HasMany
->hasMany(config('wallet.transfer.model', Transfer::class), 'from_id')
;
}

/**
* returns all the receiving transfers to this wallet.
*
* @return HasMany<Transfer>
*/
public function receivedTransfers(): HasMany
{
return app(CastServiceInterface::class)
->getWallet($this, false)
->hasMany(config('wallet.transfer.model', Transfer::class), 'to_id')

Check notice on line 240 in src/Traits/HasWallet.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

PHPStan validation

phpstan:: Parameter #1 $related of method Illuminate\\Database\\Eloquent\\Model::hasMany() expects string, mixed given.
;
}
}
2 changes: 2 additions & 0 deletions tests/Units/Service/AtomicServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public function testBlock(): void
);

self::assertSame(1, $user2->transfers()->count());
self::assertSame(2, $user2->receivedTransfers()->count());
self::assertSame(2, $user1->transfers()->count());
self::assertSame(1, $user1->receivedTransfers()->count());
self::assertSame(3, $user2->transactions()->count());
self::assertSame(4, $user1->transactions()->count());

Expand Down

0 comments on commit d96abf3

Please sign in to comment.