Completed
Push — develop ( 64da93...4b596e )
by Serhii
21s queued 12s
created

Version20210425203036   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 62
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 0 4 1
A up() 0 7 1
A down() 0 3 1
A insertData() 0 40 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineMigrations;
6
7
use App\Enum\EmployeeStaffEnum;
8
use Doctrine\DBAL\Schema\Schema;
9
use Doctrine\Migrations\AbstractMigration;
10
11
final class Version20210425203036 extends AbstractMigration
12
{
13
    private const DATA = __DIR__.'/data/performances_duration_producers_age_limits.csv';
14
15
    public function getDescription() : string
16
    {
17
        return 'Added: performance age limit data, performance producer field with data, performance len with data';
18
    }
19
20
    public function up(Schema $schema) : void
21
    {
22
        $this->addSql('ALTER TABLE performances ADD producer_id INT DEFAULT NULL, ADD durationInMin INT NOT NULL, ADD extProducer VARCHAR(255) DEFAULT NULL');
23
        $this->addSql('ALTER TABLE performances ADD CONSTRAINT FK_8133AB2B89B658FE FOREIGN KEY (producer_id) REFERENCES employees (id) ON DELETE SET NULL');
24
        $this->addSql('CREATE INDEX IDX_8133AB2B89B658FE ON performances (producer_id)');
25
        $this->insertData();
26
    }
27
28
    public function down(Schema $schema) : void
29
    {
30
    }
31
32
    public function insertData()
33
    {
34
        $performances = array_map('str_getcsv', file(self::DATA));
35
        array_shift($performances); // remove headers
36
37
        foreach ($performances as $performance) {
38
            $slug = array_shift($performance);
39
            $title = array_shift($performance);
0 ignored issues
show
Unused Code introduced by
$title is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
40
            $link = array_shift($performance);
0 ignored issues
show
Unused Code introduced by
$link is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
41
            $ageLimit = array_shift($performance);
42
            $producer = array_shift($performance);
43
            $len = array_shift($performance);
44
45
            $inHouseProducer = $this->connection->fetchAssociative(
46
                'SELECT id, deletedAt FROM employees WHERE lastName LIKE :lastName',
47
                ['lastName' => '%'.trim(explode(' ', $producer)[0]).'%']
48
            );
49
50
            if ($inHouseProducer) {
51
                $this->addSql(
52
                    'UPDATE performances SET durationInMin=:len, ageLimit=:ageLimit, producer_id=:producer WHERE slug=:slug',
53
                    ['len' => (int) $len, 'ageLimit' => (int) $ageLimit, 'producer' => $inHouseProducer['id'], 'slug' => $slug]
54
                );
55
56
                if ($inHouseProducer['deletedAt']) {
57
                    $this->addSql(
58
                        'UPDATE employees SET deletedAt=NULL, deletedBy=NULL, staff=:staff WHERE id=:id',
59
                        ['staff' => EmployeeStaffEnum::EPOCH, 'id' => $inHouseProducer['id']]
60
                    );
61
                }
62
63
                continue;
64
            }
65
66
            $this->addSql(
67
                'UPDATE performances SET durationInMin=:len, ageLimit=:ageLimit, extProducer=:producer WHERE slug=:slug',
68
                ['len' => (int) $len, 'ageLimit' => (int) $ageLimit, 'producer' => $producer, 'slug' => $slug]
69
            );
70
        }
71
    }
72
}
73