Completed
Branch feature/pre-split (67216b)
by Anton
03:28
created

AddColumn   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 13 2
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
namespace Spiral\Migrations\Operations\Columns;
9
10
use Spiral\Migrations\CapsuleInterface;
11
use Spiral\Migrations\Exceptions\Operations\ColumnException;
12
use Spiral\Migrations\Operations\ColumnOperation;
13
14
class AddColumn extends ColumnOperation
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function execute(CapsuleInterface $capsule)
20
    {
21
        $schema = $capsule->getSchema($this->getTable(), $this->getDatabase());
22
23
        if ($schema->hasColumn($this->name)) {
24
            throw new ColumnException(
25
                "Unable to create column '{$schema->getName()}'.'{$this->name}', column already exists"
26
            );
27
        }
28
29
        //Declaring column
30
        $this->declareColumn($schema);
31
    }
32
}