Passed
Push — 2.x ( b9b47b...d5b1be )
by Aleksei
20:07
created

MySQLForeignKey   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 26
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createInstance() 0 12 1
A hasIndex() 0 3 1
1
<?php
2
3
/**
4
 * This file is part of Cycle ORM package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Cycle\Database\Driver\MySQL\Schema;
13
14
use Cycle\Database\Schema\AbstractForeignKey;
15
16
class MySQLForeignKey extends AbstractForeignKey
17
{
18
    /**
19
     * @param string $table
20
     * @param string $tablePrefix
21
     * @param array  $schema
22
     *
23
     * @return MySQLForeignKey
24
     */
25 56
    public static function createInstance(string $table, string $tablePrefix, array $schema): self
26
    {
27 56
        $reference = new self($table, $tablePrefix, $schema['CONSTRAINT_NAME']);
28
29 56
        $reference->columns = $schema['COLUMN_NAME'];
30 56
        $reference->foreignTable = $schema['REFERENCED_TABLE_NAME'];
31 56
        $reference->foreignKeys = $schema['REFERENCED_COLUMN_NAME'];
32
33 56
        $reference->deleteRule = $schema['DELETE_RULE'];
34 56
        $reference->updateRule = $schema['UPDATE_RULE'];
35
36 56
        return $reference;
37
    }
38
39
    public function hasIndex(): bool
40
    {
41
        return true;
42
    }
43
}
44