Completed
Push — feature/test-php-7-2-in-travis ( a56bae...2774bc )
by
unknown
02:41
created

Version20141209150426   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 55
loc 55
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setContainer() 4 4 1
A up() 17 17 1
A down() 14 14 1
A getGatewaySchema() 4 4 1
A getMiddlewareUser() 4 4 1

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 Surfnet\Migrations;
4
5
use Doctrine\DBAL\Migrations\AbstractMigration;
6
use Doctrine\DBAL\Schema\Schema;
7
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
8
use Symfony\Component\DependencyInjection\ContainerInterface;
9
10
/**
11
 * Auto-generated Migration: Please modify to your needs!
12
 */
13 View Code Duplication
class Version20141209150426 extends AbstractMigration implements ContainerAwareInterface
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...
14
{
15
    /**
16
     * @var ContainerInterface
17
     */
18
    private $container;
19
20
    public function setContainer(ContainerInterface $container = null)
21
    {
22
        $this->container = $container;
23
    }
24
25
    public function up(Schema $schema)
26
    {
27
        $gatewaySchema  = $this->getGatewaySchema();
28
        $middlewareUser = $this->getMiddlewareUser();
29
30
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
31
32
        $this->addSql(sprintf(
33
            'CREATE TABLE %s.second_factor (identity_id VARCHAR(36) NOT NULL, name_id VARCHAR(200) NOT NULL, institution VARCHAR(200) NOT NULL, second_factor_id VARCHAR(36) NOT NULL, second_factor_type VARCHAR(50) NOT NULL, second_factor_identifier VARCHAR(100) NOT NULL, INDEX idx_secondfactor_nameid (name_id), PRIMARY KEY(identity_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB',
34
            $gatewaySchema
35
        ));
36
        $this->addSql(sprintf(
37
            'GRANT DELETE,INSERT,SELECT,UPDATE ON %s.second_factor TO %s',
38
            $gatewaySchema,
39
            $middlewareUser
40
        ));
41
    }
42
43
    public function down(Schema $schema)
44
    {
45
        $gatewaySchema  = $this->getGatewaySchema();
46
        $middlewareUser = $this->getMiddlewareUser();
47
48
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
49
50
        $this->addSql(sprintf(
51
            'REVOKE DELETE,INSERT,SELECT,UPDATE ON %s.second_factor FROM %s',
52
            $gatewaySchema,
53
            $middlewareUser
54
        ));
55
        $this->addSql('DROP TABLE second_factor');
56
    }
57
58
    private function getGatewaySchema()
59
    {
60
        return $this->container->getParameter('database_gateway_name');
61
    }
62
63
    private function getMiddlewareUser()
64
    {
65
        return $this->container->getParameter('database_middleware_user');
66
    }
67
}
68