TableWithNameGenerator::addForeignKeyConstraint()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 22
rs 9.2
cc 2
eloc 16
nc 2
nop 5
1
<?php
2
3
namespace RDV\Bundle\MigrationBundle\Migration\Schema;
4
5
use RDV\Bundle\MigrationBundle\Tools\DbIdentifierNameGenerator;
6
7
class TableWithNameGenerator extends Table
8
{
9
    /**
10
     * @var DbIdentifierNameGenerator
11
     */
12
    protected $nameGenerator;
13
14
    /**
15
     * @param array $args
16
     */
17
    public function __construct(array $args)
18
    {
19
        $this->nameGenerator = $args['nameGenerator'];
20
21
        parent::__construct($args);
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 View Code Duplication
    public function addIndex(array $columnNames, $indexName = null, array $flags = [], array $options = [])
0 ignored issues
show
Duplication introduced by
This method 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...
28
    {
29
        if (!$indexName) {
30
            $indexName = $this->nameGenerator->generateIndexName(
31
                $this->getName(),
32
                $columnNames
33
            );
34
        }
35
36
        return parent::addIndex($columnNames, $indexName, $flags, $options);
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 View Code Duplication
    public function addUniqueIndex(array $columnNames, $indexName = null, array $options = [])
0 ignored issues
show
Duplication introduced by
This method 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...
43
    {
44
        if (!$indexName) {
45
            $indexName = $this->nameGenerator->generateIndexName(
46
                $this->getName(),
47
                $columnNames,
48
                true
49
            );
50
        }
51
52
        return parent::addUniqueIndex($columnNames, $indexName, $options);
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function addForeignKeyConstraint(
59
        $foreignTable,
60
        array $localColumnNames,
61
        array $foreignColumnNames,
62
        array $options = [],
63
        $constraintName = null
64
    ) {
65
        if (!$constraintName) {
66
            $constraintName = $this->nameGenerator->generateForeignKeyConstraintName(
67
                $this->getName(),
68
                $localColumnNames
69
            );
70
        }
71
72
        return parent::addForeignKeyConstraint(
73
            $foreignTable,
74
            $localColumnNames,
75
            $foreignColumnNames,
76
            $options,
77
            $constraintName
78
        );
79
    }
80
}
81