Completed
Branch feature/pre-split (1fb805)
by Anton
03:35
created

SQLServerIndex   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A createInstance() 0 12 3
1
<?php
2
/**
3
 * components
4
 *
5
 * @author    Wolfy-J
6
 */
7
namespace Spiral\Database\Drivers\SQLServer\Schemas;
8
9
use Spiral\Database\Schemas\Prototypes\AbstractIndex;
10
11
class SQLServerIndex extends AbstractIndex
12
{
13
    /**
14
     * @param string $table Table name.
15
     * @param array  $schema
16
     *
17
     * @return SQLServerIndex
18
     */
19
    public static function createInstance(string $table, array $schema): self
20
    {
21
        //Schema is basically array of index columns merged with index meta
22
        $index = new self($table, current($schema)['indexName']);
23
        $index->type = current($schema)['isUnique'] ? self::UNIQUE : self::NORMAL;
24
25
        foreach ($schema as $indexColumn) {
26
            $index->columns[] = $indexColumn['columnName'];
27
        }
28
29
        return $index;
30
    }
31
}