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

DirectoryCreator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 11.76 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 8
loc 68
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 6 1
A createAllDirectories() 0 13 1
A createKernel() 0 9 1
A getKernelStub() 0 6 1
A resolveConsoleNamespace() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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