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

DirectoryCreator::createAllDirectories()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 10
rs 9.4285
c 1
b 0
f 0
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