RemoveForeignKeysFromTable::createIndexName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php namespace Xethron\MigrationsGenerator\Syntax;
2
3
/**
4
 * Class RemoveForeignKeysFromTable
5
 * @package Xethron\MigrationsGenerator\Syntax
6
 */
7
class RemoveForeignKeysFromTable extends Table
8
{
9
    /**
10
     * Return string for dropping a foreign key
11
     *
12
     * @param  array  $foreignKey
13
     * @return string
14
     */
15
    protected function getItem(array $foreignKey): string
16
    {
17
        $name = empty($foreignKey['name']) ? $this->createIndexName($foreignKey['field']) : $foreignKey['name'];
18
        return sprintf("\$table->dropForeign('%s');", $name);
19
    }
20
21
    /**
22
     * Create a default index name for the table.
23
     *
24
     * @param  string  $column
25
     * @return string
26
     */
27
    protected function createIndexName(string $column): string
28
    {
29
        $index = strtolower($this->table.'_'.$column.'_foreign');
30
31
        return str_replace(['-', '.'], '_', $index);
32
    }
33
}
34