Completed
Push — master ( 4deee6...b383ba )
by Zach
05:43 queued 03:44
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
use Yarak\Exceptions\WriteError;
7
8
class SeederCreator extends Creator
9
{
10
    /**
11
     * Create a seeder file with the given name.
12
     *
13
     * @param string $name
14
     *
15
     * @throws WriteError
16
     *
17
     * @return string
18
     */
19
    public function create($name)
20
    {
21
        $path = $this->config->getSeedDirectory($name.'.php');
22
23 View Code Duplication
        if (!file_exists($path)) {
24
            $this->makeDirectoryStructure([
25
                'database' => $this->config->getDatabaseDirectory(),
26
                'seeds'    => $this->config->getSeedDirectory(),
27
            ], $this->output);
28
29
            $this->writeFile($path, $this->getStub($name));
30
31
            $this->output->writeInfo("Created seeder {$name}.");
32
33
            return $path;
34
        }
35
36
        throw WriteError::commandExists($name);
37
    }
38
39
    /**
40
     * Get the stub and insert the given class name.
41
     *
42
     * @param string $name
43
     *
44
     * @return string
45
     */
46
    public function getStub($name)
47
    {
48
        $stub = file_get_contents(__DIR__.'/../Stubs/seeder.stub');
49
50
        return str_replace('DatabaseSeeder', $name, $stub);
51
    }
52
}
53