Completed
Push — master ( 19732d...076741 )
by Paweł
11:47
created

Version20180605111249   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 39.22 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setContainer() 0 4 1
A up() 0 5 1
A postUp() 20 20 2
A down() 0 5 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
declare(strict_types=1);
4
5
namespace SWP\Migrations;
6
7
use Behat\Transliterator\Transliterator;
8
use Doctrine\DBAL\Migrations\AbstractMigration;
9
use Doctrine\DBAL\Schema\Schema;
10
use SWP\Bundle\ContentBundle\Model\ArticleAuthor;
11
use SWP\Bundle\ContentBundle\Model\ArticleAuthorInterface;
12
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
13
use Symfony\Component\DependencyInjection\ContainerInterface;
14
15
/**
16
 * Auto-generated Migration: Please modify to your needs!
17
 */
18
final class Version20180605111249 extends AbstractMigration implements ContainerAwareInterface
0 ignored issues
show
Deprecated Code introduced by
The class Doctrine\DBAL\Migrations\AbstractMigration has been deprecated with message: Please use Doctrine\Migrations\AbstractMigration

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
19
{
20
    /**
21
     * @var ContainerInterface
22
     */
23
    private $container;
24
25
    /**
26
     * @param ContainerInterface|null $container
27
     */
28
    public function setContainer(ContainerInterface $container = null)
29
    {
30
        $this->container = $container;
31
    }
32
33
    public function up(Schema $schema): void
34
    {
35
        // this up() migration is auto-generated, please modify it to your needs
36
        $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
37
    }
38
39
    /**
40
     * @param Schema $schema
41
     */
42 View Code Duplication
    public function postUp(Schema $schema)
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
        $entityManager = $this->container->get('doctrine.orm.default_entity_manager');
45
        $query = $entityManager
46
            ->createQuery('SELECT au.id, au.name FROM SWP\Bundle\ContentBundle\Model\ArticleAuthor AS au  WHERE au.slug IS NULL');
47
        $articleAuthors = $query->getArrayResult();
48
49
        /** @var ArticleAuthorInterface $articleAuthor */
50
        foreach ((array) $articleAuthors as $articleAuthor) {
51
            $qb = $entityManager->createQueryBuilder();
52
            $query = $qb->update(ArticleAuthor::class, 'au')
53
                ->set('au.slug', '?1')
54
                ->where('au.id = ?2')
55
                ->setParameter(1, Transliterator::transliterate($articleAuthor['name']))
56
                ->setParameter(2, $articleAuthor['id'])
57
                ->getQuery();
58
59
            $query->execute();
60
        }
61
    }
62
63
    public function down(Schema $schema): void
64
    {
65
        // this down() migration is auto-generated, please modify it to your needs
66
        $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
67
    }
68
}
69