File size: 752 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 32 33 34 35 36 | <?php
declare(strict_types=1);
namespace Plugin\Application\CommandHandlers;
use Plugin\Application\Commands\CountPluginsCommand;
use Plugin\Domain\Repositories\PluginRepositoryInterface;
class CountPluginsCommandHandler
{
public function __construct(
private PluginRepositoryInterface $repo
) {
}
public function handle(CountPluginsCommand $cmd): int
{
$plugins = $this->repo;
if ($cmd->type) {
$plugins = $plugins->filterByType($cmd->type);
}
if ($cmd->status) {
$plugins = $plugins->filterByStatus($cmd->status);
}
if ($cmd->query) {
$plugins = $plugins->search($cmd->query);
}
return $plugins->count();
}
}
|