GenerateTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 62
loc 62
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B handle() 24 24 2
A provideArguments() 8 8 1

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
namespace SmartWeb\ModuleTesting\Console\Command;
5
6
use Exception;
7
use SmartWeb\ModuleTesting\Codeception\SmartWeb\Setup;
8
use SmartWeb\ModuleTesting\Console\CommandArgument;
9
use SmartWeb\ModuleTesting\Console\CommandArguments;
10
use SmartWeb\ModuleTesting\Console\InputArgumentType;
11
use SmartWeb\ModuleTesting\Generator\Test\TestGenerator;
12
13
/**
14
 * Command for generating a Codeception test for a Module.
15
 *
16
 * @package SmartWeb\ModuleTesting\Console
17
 */
18 View Code Duplication
class GenerateTest extends BaseCommand
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...
19
{
20
    
21
    /**
22
     * The console command name.
23
     *
24
     * @var string
25
     */
26
    protected $name = 'make-test';
27
    
28
    /**
29
     * The console command description.
30
     *
31
     * @var string
32
     */
33
    protected $description = 'Generate a Codeception Test for the given module and suite';
34
    
35
    /**
36
     * Execute the console command.
37
     *
38
     * @return void
39
     *
40
     * @throws Exception
41
     */
42
    public function handle()
43
    {
44
        /**
45
         * @var string $moduleName
46
         * @var string $suite
47
         * @var string $name
48
         */
49
        $moduleName = $this->argument('moduleName');
50
        $suite = $this->argument('suite');
51
        $name = $this->argument('name');
52
        
53
        $this->info("Creating '{$name}' for module '{$moduleName}' in suite '{$suite}'.");
54
        
55
        $setup = new Setup($moduleName);
56
        
57
        try {
58
            $generator = new TestGenerator($setup, $suite, $name);
0 ignored issues
show
Bug introduced by
It seems like $suite defined by $this->argument('suite') on line 50 can also be of type array; however, SmartWeb\ModuleTesting\G...enerator::__construct() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $name defined by $this->argument('name') on line 51 can also be of type array; however, SmartWeb\ModuleTesting\G...enerator::__construct() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
59
            $generator->generate();
60
            $this->info("Created test!");
61
        } catch (Exception $e) {
62
            $this->error("Failed to create test!");
63
            throw $e;
64
        }
65
    }
66
    
67
    /**
68
     * @return CommandArguments
69
     */
70
    protected function provideArguments() : CommandArguments
71
    {
72
        return new CommandArguments([
73
            new CommandArgument('moduleName', InputArgumentType::required(), 'The name of the module.'),
74
            new CommandArgument('suite', InputArgumentType::required(), 'The suite to generate test in.'),
75
            new CommandArgument('name', InputArgumentType::required(), 'The name of the test.'),
76
        ]);
77
    }
78
    
79
}
80