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

DirectoryCreator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 36.67 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 22
loc 60
rs 10
c 1
b 0
f 0
wmc 4
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 8 1
A createAllDirectories() 0 12 1
A createFactoriesFile() 11 11 1
A createSeederFile() 11 11 1

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\DB;
4
5
use Yarak\Helpers\Creator;
6
7
class DirectoryCreator extends Creator
8
{
9
    /**
10
     * Create all the directories and files necessary for Yarak DB functions.
11
     */
12
    public function create()
13
    {
14
        $this->createAllDirectories();
15
16
        $this->createFactoriesFile();
17
18
        $this->createSeederFile();
19
    }
20
21
    /**
22
     * Create all needed directories.
23
     */
24
    protected function createAllDirectories()
25
    {
26
        $this->makeDirectoryStructure(
27
            $this->config->getAllDatabaseDirectories()
28
        );
29
30
        $this->output->writeInfo('Created migrations directory.');
31
32
        $this->output->writeInfo('Created seeds directory.');
33
34
        $this->output->writeInfo('Created factories directory.');
35
    }
36
37
    /**
38
     * Create factory file stub.
39
     */
40 View Code Duplication
    protected function createFactoriesFile()
41
    {
42
        $stub = file_get_contents(__DIR__.'/Stubs/factory.stub');
43
44
        $this->writeFile(
45
            $this->config->getFactoryDirectory('ModelFactory.php'),
46
            $stub
47
        );
48
49
        $this->output->writeInfo('Created ModelFactory file.');
50
    }
51
52
    /**
53
     * Create seeder file stub.
54
     */
55 View Code Duplication
    protected function createSeederFile()
56
    {
57
        $stub = file_get_contents(__DIR__.'/Stubs/seeder.stub');
58
59
        $this->writeFile(
60
            $this->config->getSeedDirectory('DatabaseSeeder.php'),
61
            $stub
62
        );
63
64
        $this->output->writeInfo('Created DatabaseSeeder file.');
65
    }
66
}
67