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

SeederCreator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 18 1
A getStub() 0 6 1
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