Completed
Push — master ( 06b292...adafac )
by Nicolai
02:22
created

GenerateSetup   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fire() 0 21 1
A provideArguments() 0 7 1
1
<?php
2
3
4
namespace SmartWeb\ModuleTesting\Console\Command;
5
6
use Illuminate\Support\Str;
7
use SmartWeb\ModuleTesting\Codeception\SmartWeb\Setup;
8
use SmartWeb\ModuleTesting\Codeception\SmartWeb\SetupGenerator;
9
use SmartWeb\ModuleTesting\Console\CommandArgument;
10
use SmartWeb\ModuleTesting\Console\CommandArguments;
11
use SmartWeb\ModuleTesting\Console\InputArgumentType;
12
use function implode;
13
14
15
/**
16
 * Command for generating a complete Codeception setup for a Module.
17
 *
18
 * @package SmartWeb\Testing\Console
19
 */
20
class GenerateSetup extends BaseCommand
21
{
22
    
23
    /**
24
     * The console command name.
25
     *
26
     * @var string
27
     */
28
    protected $name = 'setup';
29
    
30
    /**
31
     * The console command description.
32
     *
33
     * @var string
34
     */
35
    protected $description = 'Setting up Codeception testing for the first time';
36
    
37
    /**
38
     * Execute the console command.
39
     *
40
     * @return void
41
     */
42
    public function fire()
43
    {
44
        $moduleName = $this->argument('moduleName');
45
        $this->info("Creating testing setup for '{$moduleName}'.");
46
        
47
        $setup = new Setup($moduleName);
0 ignored issues
show
Bug introduced by
It seems like $moduleName defined by $this->argument('moduleName') on line 44 can also be of type array; however, SmartWeb\ModuleTesting\C...eb\Setup::__construct() does only seem to accept object<Nwidart\Modules\Module>|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...
48
        $generator = new SetupGenerator($setup);
49
        
50
        // TODO: Get default suites from Laravel config
51
        $defaultSuites = ['Unit', 'Integration', 'GraphQL', 'Acceptance'];
52
        
53
        $suites = $this->getOption('suites', $defaultSuites);
54
        
55
        $suiteCount = count($suites);
56
        $suiteText = Str::plural('suite', $suiteCount);
57
        
58
        $this->info("Generating {$suiteCount} {$suiteText}: '" . implode("', '", $suites) . "'");
59
        $generator->generate($suites);
0 ignored issues
show
Documentation introduced by
$suites is of type string|array, but the function expects a array<integer,string>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
60
        
61
        $this->info("Done! Go create some tests!");
62
    }
63
    
64
    /**
65
     * @return CommandArguments
66
     */
67
    protected function provideArguments() : CommandArguments
68
    {
69
        return new CommandArguments([
70
            new CommandArgument('moduleName', InputArgumentType::required(), 'The name of the module.'),
71
            new CommandArgument('suites', InputArgumentType::optionalArray(), 'The suites to generate.'),
72
        ]);
73
    }
74
}
75