Completed
Push — master ( 2e22d6...16a402 )
by Nicolai
01:59
created

GenerateSetup   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
B fire() 0 24 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\ModuleTesting\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
        /**
45
         * @var string $moduleName
46
         */
47
        $moduleName = $this->argument('moduleName');
48
        $this->info("Creating testing setup for '{$moduleName}'.");
49
        
50
        $setup = new Setup($moduleName);
51
        $generator = new SetupGenerator($setup);
52
        
53
        // TODO: Get default suites from Laravel config
54
        $defaultSuites = ['Unit', 'Integration', 'GraphQL', 'Acceptance'];
55
        
56
        $suites = $this->getOption('suites', $defaultSuites);
57
        
58
        $suiteCount = count($suites);
59
        $suiteText = Str::plural('suite', $suiteCount);
60
        
61
        $this->info("Generating {$suiteCount} {$suiteText}: '" . implode("', '", $suites) . "'");
62
        $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...
63
        
64
        $this->info("Done! Go create some tests!");
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('suites', InputArgumentType::optionalArray(), 'The suites to generate.'),
75
        ]);
76
    }
77
}
78