Completed
Push — dev ( b3febe...ca104c )
by Zach
02:14
created

DirectoryCreator::createFactoriesFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 0
dl 15
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Yarak\DB;
4
5
use Yarak\Config\Config;
6
use Yarak\Helpers\Paths;
7
use Yarak\Helpers\Loggable;
8
9
class DirectoryCreator
10
{
11
    use Loggable, Paths;
12
13
    /**
14
     * Yarak config.
15
     *
16
     * @var Config
17
     */
18
    protected $config;
19
20
    /**
21
     * Construct.
22
     *
23
     * @param Config $config
24
     */
25
    public function __construct(Config $config)
26
    {
27
        $this->config = $config;
28
    }
29
30
    /**
31
     * Create all the directories and files necessary for Yarak DB functions.
32
     */
33
    public function create()
34
    {
35
        $this->createAllDirectories();
36
37
        $this->createFactoriesFile();
38
39
        $this->createSeederFile();
40
    }
41
42
    /**
43
     * Create all needed directories.
44
     */
45
    protected function createAllDirectories()
46
    {
47
        $this->makeDirectoryStructure(
48
            $this->config->getAllDatabaseDirectories()
49
        );
50
51
        $this->log("<info>Created all directories.</info>");
52
    }
53
54
    /**
55
     * Create factory file stub.
56
     */
57 View Code Duplication
    protected function createFactoriesFile()
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...
58
    {
59
        $stub = file_get_contents(__DIR__.'/Stubs/factory.stub');
60
61
        try {
62
            file_put_contents(
63
                $this->config->getFactoryDirectory('ModelFactory.php'),
64
                $stub
65
            );
66
        } catch (\Exception $e) {
67
            throw new Exception($e);
68
        }
69
70
        $this->log("<info>Created ModelFactory file.</info>");
71
    }
72
73
    /**
74
     * Create seeder file stub.
75
     */
76 View Code Duplication
    protected function createSeederFile()
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...
77
    {
78
        $stub = file_get_contents(__DIR__.'/Stubs/seeder.stub');
79
80
        try {
81
            file_put_contents(
82
                $this->config->getSeedDirectory('DatabaseSeeder.php'),
83
                $stub
84
            );
85
        } catch (\Exception $e) {
86
            throw new Exception($e);
87
        }
88
89
        $this->log("<info>Created DatabaseSeeder file.</info>");
90
    }
91
}
92