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

LoadFakeUsersCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 39.02 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 16
loc 41
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 8 8 1
A execute() 0 16 2
A purgeDatabases() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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