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

Generator::set()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
cc 3
eloc 5
nc 2
nop 3
crap 3
1
<?php
2
3
namespace Recca0120\Generator;
4
5
use Illuminate\Support\Arr;
6
use Illuminate\Filesystem\Filesystem;
7
use Recca0120\Generator\Fixers\UseSortFixer;
8
9
class Generator
10
{
11
    private $config;
12
13
    private $fils;
0 ignored issues
show
Unused Code introduced by
The property $fils is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
14
15
    private $useSortFixer;
16
17 3
    public function __construct($config, Filesystem $files = null, UseSortFixer $useSortFixer = null)
18
    {
19 3
        $this->config = $config;
20 3
        $this->files = $files ?: new Filesystem;
0 ignored issues
show
Bug introduced by
The property files 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...
21 3
        $this->useSortFixer = $useSortFixer ?: new UseSortFixer();
22 3
    }
23
24 3
    public function generate($command, $name)
25
    {
26 3
        $config = Arr::get($this->config, $command, []);
27
28 3
        return new Code(
29 3
            $name,
30 3
            $config,
31 3
            $this->generateDependencies($name, Arr::get($config, 'dependencies', [])),
32 3
            $this->files,
33 3
            $this->useSortFixer
34 3
        );
35
    }
36
37 3
    private function generateDependencies($name, $dependencies)
38
    {
39 3
        $codes = [];
40 3
        foreach ($dependencies as $dependency) {
41 1
            $dependencyConfig = Arr::get($this->config, $dependency, []);
42 1
            $codes[$dependency] = new Code(
43 1
                $name,
44 1
                $dependencyConfig,
45 1
                [],
46 1
                $this->files,
47 1
                $this->useSortFixer
48 1
            );
49 3
        }
50
51 3
        return $codes;
52
    }
53
}
54