Completed
Push — dev ( 9f49ce...7f87b9 )
by Zach
02:14
created

SeederCreator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 59
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 16 1
A getStub() 0 6 1
1
<?php
2
3
namespace Yarak\DB\Seeders;
4
5
use Yarak\Config\Config;
6
use Yarak\Helpers\Filesystem;
7
8
class SeederCreator
9
{
10
    use Filesystem;
11
12
    /**
13
     * Yarak config.
14
     *
15
     * @var Config
16
     */
17
    protected $config;
18
19
    /**
20
     * Construct.
21
     *
22
     * @param Config $config
23
     */
24
    public function __construct(Config $config)
25
    {
26
        $this->config = $config;
27
    }
28
29
    /**
30
     * Create a seeder file with the given name.
31
     *
32
     * @param  string $name
33
     *
34
     * @return string
35
     */
36
    public function create($name)
37
    {
38
        $seedDir = $this->config->getSeedDirectory();
39
40
        $this->makeDirectoryStructure([
41
            $this->config->getDatabaseDirectory(),
42
            $seedDir,
43
        ]);      
44
45
        $this->writeFile(
46
            $path = $seedDir.$name.'.php',
47
            $this->getStub($name)
48
        );
49
50
        return $path;
51
    }
52
53
    /**
54
     * Get the stub and insert the given class name.
55
     *
56
     * @param  string $name
57
     *
58
     * @return string
59
     */
60
    public function getStub($name)
61
    {
62
        $stub = file_get_contents(__DIR__.'/../Stubs/seeder.stub');
63
64
        return str_replace('DatabaseSeeder', $name, $stub);
65
    }
66
}
67