RemoveForeignKeysFromTable   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 25
ccs 0
cts 9
cp 0
rs 10
c 3
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getItem() 0 4 2
A createIndexName() 0 5 1
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