Completed
Push — dev ( 122982...5e45c8 )
by Zach
02:18
created

DirectoryCreator::resolveConsoleNamespace()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Yarak\Console;
4
5
use Yarak\Helpers\Creator;
6
use Yarak\Helpers\NamespaceResolver;
7
8
class DirectoryCreator extends Creator
9
{
10
    /**
11
     * Create all directories and files for console.
12
     */
13
    public function create($createExample = true)
14
    {
15
        $createdDirs = (bool) count($this->makeDirectoryStructure([
16
            'console'  => $this->config->getConsoleDirectory(),
17
            'commands' => $this->config->getCommandsDirectory(),
18
        ], $this->output));
19
20
        $createdKernel = $this->createKernel();
21
22
        $createdExample = $createExample ? $this->createExampleCommand() : false;
0 ignored issues
show
Unused Code introduced by
$createdExample is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
23
        
24
        $this->outputNothingCreated([$createdDirs, $createdKernel]);
25
    }
26
27
    /**
28
     * Create the kernel file.
29
     *
30
     * @return bool
31
     */
32 View Code Duplication
    protected function createKernel()
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...
33
    {
34
        $path = $this->config->getConsoleDirectory('Kernel.php');
35
36
        if (!file_exists($path)) {
37
            $this->writeFile(
38
                $path,
39
                $this->getKernelStub()
40
            );
41
42
            $this->output->writeInfo('Created kernel file.');
43
44
            return true;
45
        }
46
47
        return false;
48
    }
49
50
    /**
51
     * Get the kernel stub.
52
     *
53
     * @return string
54
     */
55
    protected function getKernelStub()
56
    {
57
        $stub = file_get_contents(__DIR__.'/Stubs/kernel.stub');
58
59
        return $this->setNamespace($stub, NamespaceResolver::resolve('console'));
60
    }
61
62
    /**
63
     * Create an example command.
64
     *
65
     * @return bool
66
     */
67 View Code Duplication
    protected function createExampleCommand()
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...
68
    {
69
        $path = $this->config->getCommandsDirectory('ExampleCommand.php');
70
71
        if (!file_exists($path)) {
72
            $this->writeFile(
73
                $path,
74
                $this->getExampleStub()
75
            );
76
77
            $this->output->writeInfo('Created example command file.');
78
79
            return true;
80
        }
81
82
        return false;
83
    }
84
85
    protected function getExampleStub()
86
    {
87
        $stub = file_get_contents(__DIR__.'/Stubs/exampleCommand.stub');
88
89
        return $this->setNamespace($stub, NamespaceResolver::resolve('console', 'Commands'));
90
    }
91
}
92