GenerateSetup   A
last analyzed

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 handle() 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
 * Command for generating a complete Codeception setup for a Module.
16
 *
17
 * @package SmartWeb\ModuleTesting\Console
18
 */
19
class GenerateSetup extends BaseCommand
20
{
21
    
22
    /**
23
     * The console command name.
24
     *
25
     * @var string
26
     */
27
    protected $name = 'setup';
28
    
29
    /**
30
     * The console command description.
31
     *
32
     * @var string
33
     */
34
    protected $description = 'Setting up Codeception testing for the first time';
35
    
36
    /**
37
     * Execute the console command.
38
     *
39
     * @return void
40
     */
41
    public function handle()
42
    {
43
        /**
44
         * @var string $moduleName
45
         */
46
        $moduleName = $this->argument('moduleName');
47
        $this->info("Creating testing setup for '{$moduleName}'.");
48
        
49
        $setup = new Setup($moduleName);
50
        $generator = new SetupGenerator($setup);
51
        
52
        // TODO: Get default suites from Laravel config
53
        $defaultSuites = ['Unit', 'Integration', 'GraphQL', 'Acceptance'];
54
        
55
        $suites = $this->getOption('suites', $defaultSuites);
56
        
57
        $suiteCount = count($suites);
58
        $suiteText = Str::plural('suite', $suiteCount);
59
        
60
        $this->info("Generating {$suiteCount} {$suiteText}: '" . implode("', '", $suites) . "'");
61
        $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...
62
        
63
        $this->info("Done! Go create some tests!");
64
    }
65
    
66
    /**
67
     * @return CommandArguments
68
     */
69
    protected function provideArguments() : CommandArguments
70
    {
71
        return new CommandArguments([
72
            new CommandArgument('moduleName', InputArgumentType::required(), 'The name of the module.'),
73
            new CommandArgument('suites', InputArgumentType::optionalArray(), 'The suites to generate.'),
74
        ]);
75
    }
76
}
77