Completed
Push — master ( 7fe5eb...9bad48 )
by Beñat
08:54 queued 04:27
created

LoadFakeUsersCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace Kreta\Notifier\Infrastructure\Symfony\CliCommand;
16
17
use Kreta\Notifier\Application\Inbox\SignUpUserCommand;
18
use Kreta\SharedKernel\Application\CommandBus;
19
use Kreta\SharedKernel\Infrastructure\Persistence\Fake\UserFakeData;
20
use Predis\Client;
21
use Symfony\Component\Console\Command\Command;
22
use Symfony\Component\Console\Input\InputInterface;
23
use Symfony\Component\Console\Output\OutputInterface;
24
25
class LoadFakeUsersCommand extends Command
26
{
27
    private $commandBus;
28
    private $redis;
29
    private $userFakeData;
30
31 View Code Duplication
    public function __construct(CommandBus $commandBus, Client $redis, UserFakeData $userFakeData)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
    {
33
        $this->commandBus = $commandBus;
34
        $this->redis = $redis;
35
        $this->userFakeData = $userFakeData;
36
37
        parent::__construct('kreta:notifier:inbox:user:load');
38
    }
39
40
    protected function execute(InputInterface $input, OutputInterface $output)
41
    {
42
        $this->purgeDatabases();
43
44
        $i = 0;
45
        while ($i < $this->userFakeData->amount()) {
46
            $this->commandBus->handle(
47
                new SignUpUserCommand(
48
                    $this->userFakeData->userOfIndex($i)
49
                )
50
            );
51
            ++$i;
52
        }
53
54
        $output->writeln('The fake users are successfully loaded');
55
    }
56
57 View Code Duplication
    private function purgeDatabases() : void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
    {
59
        $i = 0;
60
        while ($i < $this->userFakeData->amount()) {
61
            $this->redis->del('user-' . $this->userFakeData->userOfIndex($i));
62
            ++$i;
63
        }
64
    }
65
}
66