Completed
Push — master ( 8bc203...e5859f )
by recca
09:43
created

CommandFactory::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Recca0120\Generator;
4
5
use Recca0120\Generator\Console\GeneratorCommand;
6
7
class CommandFactory
8
{
9
    private $app;
10
11
    public function __construct($config, Generator $generator, $app)
12
    {
13
        $this->config = $config;
0 ignored issues
show
Bug introduced by
The property config does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
14
        $this->generator = $generator;
0 ignored issues
show
Bug introduced by
The property generator does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
15
        $this->app = $app;
16
    }
17
18
    public function create()
19
    {
20
        return array_map(function ($name) {
21
            $command = new GeneratorCommand($this->generator, $name);
22
23
            $instanceName = 'generator.'.$name;
24
            $this->app->instance($instanceName, $command);
25
26
            return $instanceName;
27
        }, array_keys($this->config));
28
    }
29
}
30