Completed
Pull Request — master (#1)
by Paul
03:30 queued 40s
created

CreateTestUsersCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4
Metric Value
wmc 3
lcom 1
cbo 4
dl 46
loc 46
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 11 11 1
A execute() 11 11 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
namespace Codeception\Module\Drupal\UserRegistry\Command;
4
5
use Codeception\Exception\Module as ModuleException;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
/**
12
 * Class CreateTestUsersCommand.
13
 *
14
 * @package Codeception\Module\DrupalUserRegistry\Command\TestUsersCommand
15
 */
16 View Code Duplication
class CreateTestUsersCommand extends Command
0 ignored issues
show
Duplication introduced by
This class 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...
17
{
18
    use TestUsersCommandTrait;
19
20
    /**
21
     * Configuration for this command.
22
     */
23
    protected function configure()
24
    {
25
        $this
26
            ->setName('users:create')
27
            ->setDescription('Create test users.')
28
            ->addArgument(
29
                'suite',
30
                InputArgument::OPTIONAL,
31
                "Which suite configuration to use. Defaults to 'acceptance'."
32
            );
33
    }
34
35
    /**
36
     * Execute command: create any defined test users on the configured Drush alias.
37
     *
38
     * @todo Codeception debug calls won't work here.
39
     *
40
     * @param InputInterface $input
41
     *   The command input.
42
     *
43
     * @param OutputInterface $output
44
     *   The command output.
45
     *
46
     * @return int|null|void
47
     *
48
     * @throws ModuleException
49
     */
50
    protected function execute(InputInterface $input, OutputInterface $output)
51
    {
52
        // The suite name can be passed as an argument. Without it, the command defaults to 'acceptance'.
53
        $suiteName = $input->getArgument('suite');
54
        if (!$suiteName) {
55
            $suiteName = 'acceptance';
56
        }
57
58
        $this->getTestUsers($suiteName);
59
        $this->testUserManager->createUsers($this->users);
60
    }
61
}
62