BaseCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php namespace Wn\Generators\Commands;
2
3
use Illuminate\Console\Command;
4
use Illuminate\Filesystem\Filesystem;
5
use Wn\Generators\Argument\ArgumentFormatLoader;
6
use Wn\Generators\Argument\ArgumentParser;
7
use Wn\Generators\Template\TemplateLoader;
8
9
10
class BaseCommand extends Command {
11
12
    protected $fs;
13
	protected $templates;
14
15
	public function __construct(Filesystem $fs)
16
	{
17
        parent::__construct();
18
19
        $this->fs = $fs;
20
        $this->templates = new TemplateLoader($fs);
21
        $this->argumentFormatLoader = new ArgumentFormatLoader($fs);
0 ignored issues
show
Bug introduced by
The property argumentFormatLoader 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...
22
    }
23
24
    protected function getTemplate($name)
25
    {
26
        return $this->templates->load($name);
27
    }
28
29
    protected function getArgumentParser($name){
30
        $format = $this->argumentFormatLoader->load($name);
31
        return new ArgumentParser($format);
32
    }
33
34
    protected function save($content, $path, $name, $force = false)
35
    {
36
        if (!$force && $this->fs->exists($path) && $this->input->hasOption('force') && !$this->option('force')) {
37
            $this->info("{$name} already exists; use --force option to override it !");
38
            return;
39
        }
40
        $this->makeDirectory($path);
41
        $this->fs->put($path, $content);
42
        $this->info("{$name} generated !");
43
    }
44
45
    protected function makeDirectory($path)
46
    {
47
        if (!$this->fs->isDirectory(dirname($path))) {
48
            $this->fs->makeDirectory(dirname($path), 0777, true, true);
49
        }
50
    }
51
52
    protected function spaces($n)
53
    {
54
        return str_repeat(' ', $n);
55
    }
56
57
}
58