Completed
Push — dev ( 6bece5...cad8d6 )
by Zach
02:11
created

DirectoryCreator::createAllDirectories()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Yarak\Console;
4
5
use Yarak\Helpers\Creator;
6
7
class DirectoryCreator extends Creator
8
{
9
    /**
10
     * Create all directories and files for console.
11
     */
12
    public function create()
13
    {
14
        $this->createAllDirectories();
15
16
        $this->createKernel();
17
    }
18
19
    /**
20
     * Create cosnole directory structure.
21
     */
22
    protected function createAllDirectories()
23
    {
24
        $commandsDir = $this->config->getCommandsDirectory();
25
26
        $this->makeDirectoryStructure([
27
            $this->config->getConsoleDirectory(), 
28
            $commandsDir
29
        ]);
30
31
        $this->output->writeInfo('Created console directory.');
32
33
        $this->output->writeInfo('Created commands directory.');
34
    }
35
36
    /**
37
     * Create the kernel file.
38
     */
39
    protected function createKernel()
40
    {
41
        $this->writeFile(
42
            $this->config->getConsoleDirectory('Kernel.php'),
43
            $this->getKernelStub()
44
        );
45
46
        $this->output->writeInfo('Created kernel file.');
47
    }
48
49
    /**
50
     * Get the kernel stub.
51
     *
52
     * @return string
53
     */
54
    protected function getKernelStub()
55
    {
56
        $stub = file_get_contents(__DIR__.'/Stubs/kernel.stub');
57
58
        return $this->setNamespace($stub, $this->resolveConsoleNamespace());
59
    }
60
61
    /**
62
     * Resolve the console namespace.
63
     *
64
     * @return string
65
     */
66 View Code Duplication
    protected function resolveConsoleNamespace()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
    {
68
        if ($this->config->has(['namespaces', 'consoleNamespace'])) {
69
            return $this->config->get(['namespaces', 'consoleNamespace']);
70
        }
71
        
72
        return $this->guessNamespace($this->config->getConsoleDirectory());
73
    }
74
}
75