Completed
Push — dev ( 3ddbd6...175d0e )
by Zach
02:08
created

DirectoryCreator::createAllDirectories()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 13
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
        $createdDirs = (bool) count($this->makeDirectoryStructure([
15
            'console'  => $this->config->getConsoleDirectory(),
16
            'commands' => $this->config->getCommandsDirectory(),
17
        ], $this->output));
18
19
        $createdKernel = $this->createKernel();
20
21
        $this->outputNothingCreated([$createdDirs, $createdKernel]);
22
    }
23
24
    /**
25
     * Create the kernel file.
26
     *
27
     * @return bool
28
     */
29
    protected function createKernel()
30
    {
31
        $path = $this->config->getConsoleDirectory('Kernel.php');
32
33
        if (!file_exists($path)) {
34
            $this->writeFile(
35
                $path,
36
                $this->getKernelStub()
37
            );
38
39
            $this->output->writeInfo('Created kernel file.');
40
41
            return true;
42
        }
43
44
        return false;
45
    }
46
47
    /**
48
     * Get the kernel stub.
49
     *
50
     * @return string
51
     */
52
    protected function getKernelStub()
53
    {
54
        $stub = file_get_contents(__DIR__.'/Stubs/kernel.stub');
55
56
        return $this->setNamespace($stub, $this->resolveConsoleNamespace());
57
    }
58
59
    /**
60
     * Resolve the console namespace.
61
     *
62
     * @return string
63
     */
64 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...
65
    {
66
        if ($this->config->has(['namespaces', 'consoleNamespace'])) {
67
            return $this->config->get(['namespaces', 'consoleNamespace']);
68
        }
69
70
        return $this->guessNamespace($this->config->getConsoleDirectory());
71
    }
72
}
73