Version20200214041355   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 82
Duplicated Lines 15.85 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 3
dl 13
loc 82
ccs 0
cts 36
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 0 4 1
A up() 13 13 1
A addSeasonsToPerformances() 0 23 4
A insertSeasons() 0 6 2
A down() 0 9 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 DoctrineMigrations;
6
7
use Doctrine\DBAL\Schema\Schema;
8
use Doctrine\Migrations\AbstractMigration;
9
10
/**
11
 * Auto-generated Migration: Please modify to your needs!
12
 */
13
final class Version20200214041355 extends AbstractMigration
14
{
15
    protected $seasons = [
16
        ['number' => 83, 'startDate' => '2014-09-01 00:00:00', 'endDate' => '2015-07-31 23:59:59'],
17
        ['number' => 84, 'startDate' => '2015-09-01 00:00:00', 'endDate' => '2016-07-31 23:59:59'],
18
        ['number' => 85, 'startDate' => '2016-09-01 00:00:00', 'endDate' => '2017-07-31 23:59:59'],
19
        ['number' => 86, 'startDate' => '2017-09-01 00:00:00', 'endDate' => '2018-07-31 23:59:59'],
20
        ['number' => 87, 'startDate' => '2018-09-01 00:00:00', 'endDate' => '2019-07-31 23:59:59'],
21
        ['number' => 88, 'startDate' => '2019-09-01 00:00:00', 'endDate' => '2020-07-31 23:59:59'],
22
        ['number' => 89, 'startDate' => '2020-09-01 00:00:00', 'endDate' => '2021-07-31 23:59:59'],
23
        ['number' => 90, 'startDate' => '2021-09-01 00:00:00', 'endDate' => '2022-07-31 23:59:59'],
24
        ['number' => 91, 'startDate' => '2022-09-01 00:00:00', 'endDate' => '2023-07-31 23:59:59'],
25
        ['number' => 92, 'startDate' => '2023-09-01 00:00:00', 'endDate' => '2024-07-31 23:59:59'],
26
        ['number' => 93, 'startDate' => '2024-09-01 00:00:00', 'endDate' => '2025-07-31 23:59:59'],
27
        ['number' => 94, 'startDate' => '2025-09-01 00:00:00', 'endDate' => '2026-07-31 23:59:59'],
28
        ['number' => 95, 'startDate' => '2026-09-01 00:00:00', 'endDate' => '2027-07-31 23:59:59'],
29
        ['number' => 96, 'startDate' => '2027-09-01 00:00:00', 'endDate' => '2028-07-31 23:59:59'],
30
        ['number' => 97, 'startDate' => '2028-09-01 00:00:00', 'endDate' => '2029-07-31 23:59:59'],
31
        ['number' => 98, 'startDate' => '2029-09-01 00:00:00', 'endDate' => '2030-07-31 23:59:59'],
32
        ['number' => 99, 'startDate' => '2030-09-01 00:00:00', 'endDate' => '2031-07-31 23:59:59'],
33
    ];
34
35
    public function getDescription() : string
36
    {
37
        return '';
38
    }
39
40 View Code Duplication
    public function up(Schema $schema) : void
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...
41
    {
42
        // this up() migration is auto-generated, please modify it to your needs
43
        $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
44
45
        $this->addSql('CREATE TABLE RepertoireSeason (id INT AUTO_INCREMENT NOT NULL, startDate DATETIME NOT NULL, endDate DATETIME NOT NULL, number INT NOT NULL, UNIQUE INDEX UNIQ_C9FDBB996901F54 (number), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
46
        $this->addSql('CREATE TABLE performance_repertoireseason (performance_id INT NOT NULL, repertoireseason_id INT NOT NULL, INDEX IDX_58AE5ABFB91ADEEE (performance_id), INDEX IDX_58AE5ABFAC76615 (repertoireseason_id), PRIMARY KEY(performance_id, repertoireseason_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
47
        $this->addSql('ALTER TABLE performance_repertoireseason ADD CONSTRAINT FK_58AE5ABFB91ADEEE FOREIGN KEY (performance_id) REFERENCES performances (id) ON DELETE CASCADE');
48
        $this->addSql('ALTER TABLE performance_repertoireseason ADD CONSTRAINT FK_58AE5ABFAC76615 FOREIGN KEY (repertoireseason_id) REFERENCES RepertoireSeason (id) ON DELETE CASCADE');
49
50
        $this->insertSeasons();
51
        $this->addSeasonsToPerformances();
52
    }
53
54
    protected function addSeasonsToPerformances()
55
    {
56
        $file = __DIR__.'/data/theatreSeasons.csv';
57
        $performanceSeasons = $csv = array_map('str_getcsv', file($file));
0 ignored issues
show
Unused Code introduced by
$csv 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...
58
        $keys = array_shift($performanceSeasons);
0 ignored issues
show
Unused Code introduced by
$keys 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...
59
60
        foreach ($performanceSeasons as $performance) {
61
            $pId = array_shift($performance);
62
            $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...
63
64
            $psId = 6;
65
            while (!empty($performance)) {
66
                if (1 == array_shift($performance)) {
67
                    $this->addSql(
68
                        'INSERT INTO performance_repertoireseason (performance_id, repertoireseason_id) VALUES (:pId, :psId)',
69
                        ['pId' => $pId, 'psId' => $psId]
70
                    );
71
                }
72
                $psId--;
73
            }
74
        }
75
76
    }
77
78
    protected function insertSeasons()
79
    {
80
        foreach ($this->seasons as $season) {
81
            $this->addSql('INSERT INTO RepertoireSeason (startDate, endDate, number) VALUES (:startDate, :endDate, :number)', $season);
82
        }
83
    }
84
85
    public function down(Schema $schema) : void
86
    {
87
        // this down() migration is auto-generated, please modify it to your needs
88
        $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
89
90
        $this->addSql('ALTER TABLE performance_repertoireseason DROP FOREIGN KEY FK_58AE5ABFAC76615');
91
        $this->addSql('DROP TABLE RepertoireSeason');
92
        $this->addSql('DROP TABLE performance_repertoireseason');
93
    }
94
}
95