Completed
Push — master ( cd8605...3b7290 )
by
unknown
09:46
created

AccountNameExprIndexQuery   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 3
dl 37
loc 37
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 10 10 1
A execute() 4 4 1
A doExecute() 12 12 3

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 OroCRM\Bundle\AccountBundle\Migrations\Schema\v1_11;
4
5
use Doctrine\DBAL\Platforms\PostgreSQL92Platform;
6
7
use Psr\Log\LoggerInterface;
8
9
use Oro\Bundle\MigrationBundle\Migration\ArrayLogger;
10
use Oro\Bundle\MigrationBundle\Migration\ParametrizedMigrationQuery;
11
12 View Code Duplication
class AccountNameExprIndexQuery extends ParametrizedMigrationQuery
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...
13
{
14
    public function getDescription()
15
    {
16
        $logger = new ArrayLogger();
17
        $logger->info(
18
            'Create additional expression index on PostgreSQL'
19
        );
20
        $this->doExecute($logger, true);
21
22
        return $logger->getMessages();
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function execute(LoggerInterface $logger)
29
    {
30
        $this->doExecute($logger);
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function doExecute(LoggerInterface $logger, $dryRun = false)
37
    {
38
        $platform = $this->connection->getDatabasePlatform();
39
        if ($platform instanceof PostgreSQL92Platform) {
40
            $createIndex = 'CREATE INDEX account_name_expr_idx ON orocrm_account (lower(name))';
41
42
            $this->logQuery($logger, $createIndex);
43
            if (!$dryRun) {
44
                $this->connection->executeUpdate($createIndex);
45
            }
46
        }
47
    }
48
}
49