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

SeederCreator::createDirectories()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A SeederCreator::getStub() 0 6 1
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)) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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