RemoveDeletedUsers   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 18
ccs 0
cts 6
cp 0
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 9 1
A __construct() 0 2 1
1
<?php
2
3
namespace App\Command;
4
5
use App\Repository\UserRepositoryInterface;
6
use SchulIT\CommonBundle\Helper\DateHelper;
7
use Shapecode\Bundle\CronBundle\Attribute\AsCronJob;
8
use Symfony\Component\Console\Attribute\AsCommand;
9
use Symfony\Component\Console\Command\Command;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
use Symfony\Component\Console\Style\SymfonyStyle;
13
14
#[AsCronJob(schedule: '0 0 * * *')]
15
#[AsCommand(name: 'app:user:remove_deleted', description: 'Löscht alle zum Löschen vorgemerkten Benutzer, die vor mehr als 30 Tagen zum Löschen markiert wurden.')]
16
class RemoveDeletedUsers extends Command {
17
    private const Modifier = '-30 days';
18
19
    public function __construct(private readonly DateHelper $dateHelper, private readonly UserRepositoryInterface $userRepository, string $name = null) {
20
        parent::__construct($name);
21
    }
22
23
    public function execute(InputInterface $input, OutputInterface $output): int {
24
        $style = new SymfonyStyle($input, $output);
25
26
        $threshold = $this->dateHelper->getToday()->modify(self::Modifier);
27
        $count = $this->userRepository->removeDeletedUsers($threshold);
28
29
        $style->success(sprintf('%d Benutzer gelöscht', $count));
30
31
        return 0;
32
    }
33
}