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

SeederCreator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Yarak\DB\Seeders;
4
5
use Yarak\Helpers\Creator;
6
7
class SeederCreator extends Creator
8
{
9
    /**
10
     * Create a seeder file with the given name.
11
     *
12
     * @param string $name
13
     *
14
     * @return string
15
     */
16
    public function create($name)
17
    {
18
        $seedDir = $this->config->getSeedDirectory();
19
20
        $this->makeDirectoryStructure([
21
            $this->config->getDatabaseDirectory(),
22
            $seedDir,
23
        ]);
24
25
        $this->writeFile(
26
            $path = $seedDir.$name.'.php',
27
            $this->getStub($name)
28
        );
29
30
        $this->output->writeInfo("Successfully created seeder {$name}.");
31
32
        return $path;
33
    }
34
35
    /**
36
     * Get the stub and insert the given class name.
37
     *
38
     * @param string $name
39
     *
40
     * @return string
41
     */
42
    public function getStub($name)
43
    {
44
        $stub = file_get_contents(__DIR__.'/../Stubs/seeder.stub');
45
46
        return str_replace('DatabaseSeeder', $name, $stub);
47
    }
48
}
49