setNameGenerator()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace RDV\Bundle\MigrationBundle\Migration;
4
5
use RDV\Bundle\MigrationBundle\Exception\InvalidNameException;
6
use RDV\Bundle\MigrationBundle\Migration\Schema\SchemaWithNameGenerator;
7
use RDV\Bundle\MigrationBundle\Tools\DbIdentifierNameGenerator;
8
9
class MigrationExecutorWithNameGenerator extends MigrationExecutor
10
{
11
    /**
12
     * @var DbIdentifierNameGenerator
13
     */
14
    protected $nameGenerator;
15
16
    /**
17
     * @param DbIdentifierNameGenerator $nameGenerator
18
     */
19
    public function setNameGenerator(DbIdentifierNameGenerator $nameGenerator)
20
    {
21
        $this->nameGenerator = $nameGenerator;
22
        if ($this->extensionManager) {
23
            $this->extensionManager->setNameGenerator($this->nameGenerator);
24
        }
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function setExtensionManager(MigrationExtensionManager $extensionManager)
31
    {
32
        parent::setExtensionManager($extensionManager);
33
        if ($this->nameGenerator) {
34
            $this->extensionManager->setNameGenerator($this->nameGenerator);
35
        }
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    protected function createSchemaObject(array $tables = [], array $sequences = [], $schemaConfig = null)
42
    {
43
        if ($schemaConfig && $this->nameGenerator) {
44
            $schemaConfig->setMaxIdentifierLength($this->nameGenerator->getMaxIdentifierSize());
45
        }
46
47
        return new SchemaWithNameGenerator(
48
            $this->nameGenerator,
49
            $tables,
50
            $sequences,
51
            $schemaConfig
52
        );
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 View Code Duplication
    protected function checkTableName($tableName, Migration $migration)
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...
59
    {
60
        parent::checkTableName($tableName, $migration);
61
        if (strlen($tableName) > $this->nameGenerator->getMaxIdentifierSize()) {
62
            throw new InvalidNameException(
63
                sprintf(
64
                    'Max table name length is %s. Please correct "%s" table in "%s" migration',
65
                    $this->nameGenerator->getMaxIdentifierSize(),
66
                    $tableName,
67
                    get_class($migration)
68
                )
69
            );
70
        }
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76 View Code Duplication
    protected function checkColumnName($tableName, $columnName, Migration $migration)
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...
77
    {
78
        parent::checkColumnName($tableName, $columnName, $migration);
79
        if (strlen($columnName) > $this->nameGenerator->getMaxIdentifierSize()) {
80
            throw new InvalidNameException(
81
                sprintf(
82
                    'Max column name length is %s. Please correct "%s:%s" column in "%s" migration',
83
                    $this->nameGenerator->getMaxIdentifierSize(),
84
                    $tableName,
85
                    $columnName,
86
                    get_class($migration)
87
                )
88
            );
89
        }
90
    }
91
}
92