1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace DoctrineMigrations; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Schema\Schema; |
8
|
|
|
use Doctrine\Migrations\AbstractMigration; |
9
|
|
|
|
10
|
|
|
final class Version20210425203036 extends AbstractMigration |
11
|
|
|
{ |
12
|
|
|
private const DATA = __DIR__.'/data/performances_duration_producers_age_limits.csv'; |
13
|
|
|
|
14
|
|
|
public function getDescription() : string |
15
|
|
|
{ |
16
|
|
|
return 'Added: performance age limit data, performance producer field with data, performance len with data'; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function up(Schema $schema) : void |
20
|
|
|
{ |
21
|
|
|
$this->addSql('ALTER TABLE performances ADD producer_id INT DEFAULT NULL, ADD durationInMin INT NOT NULL, ADD extProducer VARCHAR(255) DEFAULT NULL'); |
22
|
|
|
$this->addSql('ALTER TABLE performances ADD CONSTRAINT FK_8133AB2B89B658FE FOREIGN KEY (producer_id) REFERENCES employees (id)'); |
23
|
|
|
$this->addSql('CREATE INDEX IDX_8133AB2B89B658FE ON performances (producer_id)'); |
24
|
|
|
$this->insertData(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function down(Schema $schema) : void |
28
|
|
|
{ |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function insertData() |
32
|
|
|
{ |
33
|
|
|
$performances = array_map('str_getcsv', file(self::DATA)); |
34
|
|
|
array_shift($performances); // remove headers |
35
|
|
|
|
36
|
|
|
foreach ($performances as $performance) { |
37
|
|
|
$slug = array_shift($performance); |
38
|
|
|
$title = array_shift($performance); |
|
|
|
|
39
|
|
|
$link = array_shift($performance); |
|
|
|
|
40
|
|
|
$ageLimit = array_shift($performance); |
41
|
|
|
$producer = array_shift($performance); |
42
|
|
|
$len = array_shift($performance); |
43
|
|
|
|
44
|
|
|
$this->addSql( |
45
|
|
|
'UPDATE performances SET durationInMin=:len, ageLimit=:ageLimit, extProducer=:producer WHERE slug=:slug', |
46
|
|
|
['len' => (int) $len, 'ageLimit' => (int) $ageLimit, 'producer' => $producer, 'slug' => $slug] |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.