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

SQLServerIndex::createInstance()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 4
nop 2
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
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
}