Completed
Push — master ( 8ecc57...3a02ee )
by Nicolai
02:04
created

GenerateCest::provideArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 5
Ratio 62.5 %

Importance

Changes 0
Metric Value
nc 1
dl 5
loc 8
c 0
b 0
f 0
cc 1
eloc 5
nop 0
rs 9.4285
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\CestGenerator;
12
13
14
/**
15
 * Command for generating a Codeception cest for a Module.
16
 *
17
 * @package SmartWeb\ModuleTesting\Console
18
 */
19 View Code Duplication
class GenerateCest 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...
20
{
21
    
22
    /**
23
     * The console command name.
24
     *
25
     * @var string
26
     */
27
    protected $name = 'make-cest';
28
    
29
    /**
30
     * The console command description.
31
     *
32
     * @var string
33
     */
34
    protected $description = 'Generate a Codeception Cest for the given module and suite';
35
    
36
    /**
37
     * Execute the console command.
38
     *
39
     * @return void
40
     *
41
     * @throws Exception
42
     */
43
    public function handle()
44
    {
45
        /**
46
         * @var string $moduleName
47
         * @var string $suite
48
         * @var string $name
49
         */
50
        $moduleName = $this->argument('moduleName');
51
        $suite = $this->argument('suite');
52
        $name = $this->argument('name');
53
        
54
        $this->info("Creating '{$name}' for module '{$moduleName}' in suite '{$suite}'.");
55
        
56
        $setup = new Setup($moduleName);
57
        
58
        try {
59
            $generator = new CestGenerator($setup, $suite, $name);
0 ignored issues
show
Bug introduced by
It seems like $suite defined by $this->argument('suite') 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...
Bug introduced by
It seems like $name defined by $this->argument('name') on line 52 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...
60
            $generator->generate();
61
            $this->info("Created test!");
62
        } catch (Exception $e) {
63
            $this->error("Failed to create test!");
64
            throw $e;
65
        }
66
    }
67
    
68
    /**
69
     * @return CommandArguments
70
     */
71
    protected function provideArguments() : CommandArguments
72
    {
73
        return new CommandArguments([
74
            new CommandArgument('moduleName', InputArgumentType::required(), 'The name of the module.'),
75
            new CommandArgument('suite', InputArgumentType::required(), 'The suite to generate test in.'),
76
            new CommandArgument('name', InputArgumentType::required(), 'The name of the test.'),
77
        ]);
78
    }
79
    
80
}
81