Completed
Push — master ( e32eeb...714cda )
by
unknown
89:50 queued 46:29
created

CreateTestCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 34.78 %

Coupling/Cohesion

Components 0
Dependencies 5
Metric Value
wmc 4
lcom 0
cbo 5
dl 16
loc 46
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 16 16 1
A execute() 0 18 3

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 Oro\Bundle\TestGeneratorBundle\Command;
4
5
use Symfony\Component\Console\Input\InputArgument;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
9
10
class CreateTestCommand extends ContainerAwareCommand
11
{
12
    const NAME = 'oro:generate:test';
13
14
    /**
15
     * {@inheritdoc}
16
     */
17 View Code Duplication
    protected function configure()
18
    {
19
        $this
20
            ->setName(self::NAME)
21
            ->setDescription('Create Test')
22
            ->addArgument(
23
                'class',
24
                InputArgument::REQUIRED,
25
                'Full qualified class name or path to php file'
26
            )
27
            ->addArgument(
28
                'type',
29
                InputArgument::REQUIRED,
30
                'Test type. Supported types are: unit, entity, functional'
31
            );
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    protected function execute(InputInterface $input, OutputInterface $output)
38
    {
39
        $type = $input->getArgument('type');
40
        if (!in_array($type, ['unit', 'entity', 'functional'], true)) {
41
            throw new \InvalidArgumentException(
42
                sprintf('Type "%s" is not known. Supported types are: unit, entity, functional', $type)
43
            );
44
        }
45
46
        $generator = $this->getContainer()->get('oro_test_generator.generator.test.' . $type);
47
        $class = $input->getArgument('class');
48
        if (strpos($class, '\\') === false) {
49
            $class = str_replace('.php', '', $class);
50
            $class = str_replace('/', '\\', substr($class, strripos($class, '/src/') + 5));
51
        }
52
        $generator->generate($class);
53
        $output->writeln('<info>Test was generated successful</info>');
54
    }
55
}
56