Passed
Pull Request — master (#695)
by Alejandro
05:41
created

Version20200323190014::postUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 14
rs 9.8666
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ShlinkMigrations;
6
7
use Doctrine\DBAL\Schema\Schema;
8
use Doctrine\DBAL\Types\Types;
9
use Doctrine\Migrations\AbstractMigration;
10
11
final class Version20200323190014 extends AbstractMigration
12
{
13
    public function up(Schema $schema): void
14
    {
15
        $visitLocations = $schema->getTable('visit_locations');
16
        $this->skipIf($visitLocations->hasColumn('is_empty'));
17
18
        $visitLocations->addColumn('is_empty', Types::BOOLEAN, ['default' => false]);
19
    }
20
21
    public function postUp(Schema $schema): void
22
    {
23
        $qb = $this->connection->createQueryBuilder();
24
        $qb->update('visit_locations')
25
           ->set('is_empty', true)
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type string expected by parameter $value of Doctrine\DBAL\Query\QueryBuilder::set(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

25
           ->set('is_empty', /** @scrutinizer ignore-type */ true)
Loading history...
26
           ->where($qb->expr()->eq('country_code', ':empty'))
27
           ->andWhere($qb->expr()->eq('country_name', ':empty'))
28
           ->andWhere($qb->expr()->eq('region_name', ':empty'))
29
           ->andWhere($qb->expr()->eq('city_name', ':empty'))
30
           ->andWhere($qb->expr()->eq('timezone', ':empty'))
31
           ->andWhere($qb->expr()->eq('lat', 0))
32
           ->andWhere($qb->expr()->eq('lon', 0))
33
           ->setParameter('empty', '')
34
           ->execute();
35
    }
36
37
    public function down(Schema $schema): void
38
    {
39
        $visitLocations = $schema->getTable('visit_locations');
40
        $this->skipIf(!$visitLocations->hasColumn('is_empty'));
41
42
        $visitLocations->dropColumn('is_empty');
43
    }
44
}
45