Completed
Branch feature/pre-split (e801ec)
by Anton
03:11
created

DropReference   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 13 13 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
namespace Spiral\Migrations\Operations\References;
9
10
use Spiral\Migrations\CapsuleInterface;
11
use Spiral\Migrations\Exceptions\Operations\ReferenceException;
12
use Spiral\Migrations\Operations\ReferenceOperation;
13
14 View Code Duplication
class DropReference extends ReferenceOperation
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function execute(CapsuleInterface $capsule)
20
    {
21
        $schema = $capsule->getSchema($this->getDatabase(), $this->getTable());
22
23
        if (!$schema->hasForeign($this->column)) {
24
            throw new ReferenceException(
25
                "Unable to drop foreign key '{$schema->getName()}'.'{$this->column}', "
26
                . "foreign key does not exists"
27
            );
28
        }
29
30
        $schema->dropForeign($this->column);
31
    }
32
}