File size: 664 Bytes
cf14c12 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | <?php
declare(strict_types=1);
namespace Affiliate\Application\CommandHandlers;
use Affiliate\Application\Commands\CountPayoutsCommand;
use Affiliate\Domain\Repositories\PayoutRepositoryInterface;
class CountPayoutsCommandHandler
{
public function __construct(
private PayoutRepositoryInterface $repo
) {}
public function handle(CountPayoutsCommand $cmd): int
{
$payouts = $this->repo;
if ($cmd->status) {
$payouts = $payouts->filterByStatus($cmd->status);
}
if ($cmd->user) {
$payouts = $payouts->filterByUser($cmd->user);
}
return $payouts->count();
}
}
|