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

DirectoryCreator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 56.72 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 38
loc 67
rs 10
c 1
b 0
f 0
wmc 5
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 15 1
A createFactoriesFile() 19 19 2
A createSeederFile() 19 19 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\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
        $createdDirs = (bool) count($this->makeDirectoryStructure(
15
            $this->config->getAllDatabaseDirectories(),
16
            $this->output
17
        ));
18
19
        $createdFactories = $this->createFactoriesFile();
20
21
        $createdSeeder = $this->createSeederFile();
22
23
        $this->outputNothingCreated(
24
            [$createdDirs, $createdFactories, $createdSeeder]
25
        );
26
    }
27
28
    /**
29
     * Create factory file stub.
30
     */
31 View Code Duplication
    protected function createFactoriesFile()
32
    {
33
        $path = $this->config->getFactoryDirectory('ModelFactory.php');
34
35
        if (!file_exists($path)) {
36
            $stub = file_get_contents(__DIR__.'/Stubs/factory.stub');
37
38
            $this->writeFile(
39
                $path,
40
                $stub
41
            );
42
43
            $this->output->writeInfo('Created ModelFactory file.');
44
45
            return true;
46
        }
47
48
        return false;
49
    }
50
51
    /**
52
     * Create seeder file stub.
53
     */
54 View Code Duplication
    protected function createSeederFile()
55
    {
56
        $path = $this->config->getSeedDirectory('DatabaseSeeder.php');
57
58
        if (!file_exists($path)) {
59
            $stub = file_get_contents(__DIR__.'/Stubs/seeder.stub');
60
61
            $this->writeFile(
62
                $this->config->getSeedDirectory('DatabaseSeeder.php'),
63
                $stub
64
            );
65
66
            $this->output->writeInfo('Created DatabaseSeeder file.');
67
68
            return true;
69
        }
70
71
        return false;
72
    }
73
}
74