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

SeederCreator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 26.67 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 12
loc 45
rs 10
c 1
b 1
f 0
wmc 3
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 12 19 2
A getStub() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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