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

Generator::renderServiceProvider()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 37
Code Lines 25

Duplication

Lines 14
Ratio 37.84 %

Code Coverage

Tests 25
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 14
loc 37
ccs 25
cts 25
cp 1
rs 8.439
c 1
b 0
f 0
cc 5
eloc 25
nc 16
nop 1
crap 5
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