Completed
Pull Request — master (#8)
by Jarek
05:19
created

MigrationCreator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getStub() 0 4 1
A populateStub() 0 22 1
1
<?php
2
3
namespace Spatie\Sluggable;
4
5
class MigrationCreator extends \Illuminate\Database\Migrations\MigrationCreator
6
{
7
    /**
8
     * Get the migration stub file.
9
     *
10
     * @param  string  $table
0 ignored issues
show
Bug introduced by
There is no parameter named $table. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
11
     * @param  bool    $create
0 ignored issues
show
Bug introduced by
There is no parameter named $create. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
12
     * @return string
13
     */
14
    protected function getStub($t, $c)
15
    {
16
        return $this->files->get(__DIR__.'/migration.stub');
17
    }
18
19
    /**
20
     * Populate the place-holders in the migration stub.
21
     *
22
     * @param  string  $name
23
     * @param  string  $stub
24
     * @param  \Illuminate\Support\Collection|array  $migrations
25
     * @return string
26
     */
27
    protected function populateStub($name, $stub, $migrations)
28
    {
29
        $stub = str_replace('DummyClass', $this->getClassName($name), $stub);
30
31
        $up = collect($migrations)->map(function ($migration) {
32
            return <<<UP
33
        Schema::table('{$migration['table']}', function (Blueprint \$table) {
34
            \$table->string('{$migration['column']}', {$migration['length']})->nullable();
35
        });
36
UP;
37
        })->implode(PHP_EOL);
38
39
        $down = collect($migrations)->map(function ($migration) {
40
            return <<<DOWN
41
        Schema::table('{$migration['table']}', function (Blueprint \$table) {
42
            \$table->dropColumn('{$migration['column']}');
43
        });
44
DOWN;
45
        })->implode(PHP_EOL);
46
47
        return str_replace(['up_placeholder', 'down_placeholder'], [$up, $down], $stub);
48
    }
49
}
50