for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Uxmp\Core\Component\Cli;
use Ahc\Cli\Input\Command;
use Ahc\Cli\IO\Interactor;
use Psr\Container\ContainerInterface;
use Throwable;
use Uxmp\Core\Component\User\UserDeleterInterface;
use Uxmp\Core\Orm\Repository\UserRepositoryInterface;
final class UserDeleteCommand extends Command
{
public function __construct(
private readonly ContainerInterface $dic
) {
parent::__construct(
'user:del',
'Deletes a user'
);
$this
->argument(
'<userId>',
'User Id'
)
->usage(
'<bold> $0 ud 666</end> <comment></end> ## Deletes the user with the id `666`<eol/>'
}
public function execute(?string $userId): void
/** @var Interactor|null $io */
$io = $this->app()?->io();
$userId = (int) $userId;
$user = $this->dic->get(UserRepositoryInterface::class)->find($userId);
if ($user === null) {
$io?->error(sprintf('User with id `%d` not found', $userId), true);
return;
try {
$this->dic->get(UserDeleterInterface::class)->delete($user);
$io?->ok('The user has been deleted', true);
} catch (Throwable) {
$io?->error('Error deleting user (see logs)', true);