TableWithNameGenerator   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 74
Duplicated Lines 31.08 %

Coupling/Cohesion

Components 1
Dependencies 2
Metric Value
wmc 7
lcom 1
cbo 2
dl 23
loc 74
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A addIndex() 11 11 2
A addUniqueIndex() 12 12 2
A addForeignKeyConstraint() 0 22 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
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