Passed
Push — master ( 039de6...202994 )
by
unknown
07:02
created

Version20230426081006::up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 90
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 40
c 2
b 0
f 0
dl 0
loc 90
ccs 0
cts 39
cp 0
rs 9.28
cc 1
nc 1
nop 1
crap 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Migration;
6
7
use Doctrine\DBAL\Schema\Schema;
8
use Doctrine\Migrations\AbstractMigration;
9
10
class Version20230426081006 extends AbstractMigration
11
{
12
    public function up(Schema $schema): void
13
    {
14
        $this->addSql('ALTER TABLE antique_name ADD usage_count INT UNSIGNED DEFAULT 0 NOT NULL');
15
        $this->addSql('ALTER TABLE artist ADD usage_count INT UNSIGNED DEFAULT 0 NOT NULL');
16
        $this->addSql('ALTER TABLE document_type ADD usage_count INT UNSIGNED DEFAULT 0 NOT NULL');
17
        $this->addSql('ALTER TABLE domain ADD usage_count INT UNSIGNED DEFAULT 0 NOT NULL');
18
        $this->addSql('ALTER TABLE institution ADD usage_count INT UNSIGNED DEFAULT 0 NOT NULL');
19
        $this->addSql('ALTER TABLE material ADD usage_count INT UNSIGNED DEFAULT 0 NOT NULL');
20
        $this->addSql('ALTER TABLE period ADD usage_count INT UNSIGNED DEFAULT 0 NOT NULL');
21
        $this->addSql('ALTER TABLE tag ADD usage_count INT UNSIGNED DEFAULT 0 NOT NULL');
22
23
        $this->addSql(
24
            <<<SQL
25
                UPDATE antique_name INNER JOIN (
26
                    SELECT card_antique_name.antique_name_id AS id, COUNT(*) AS count
27
                    FROM card_antique_name
28
                    GROUP BY id
29
                ) AS tmp ON tmp.id = antique_name.id
30
                SET usage_count = tmp.count;
31
                SQL
32
        );
33
34
        $this->addSql(
35
            <<<SQL
36
                UPDATE artist INNER JOIN (
37
                    SELECT card_artist.artist_id AS id, COUNT(*) AS count
38
                    FROM card_artist
39
                    GROUP BY id
40
                ) AS tmp ON tmp.id = artist.id
41
                SET usage_count = tmp.count;
42
                SQL
43
        );
44
45
        $this->addSql(
46
            <<<SQL
47
                UPDATE document_type INNER JOIN (
48
                    SELECT card.document_type_id AS id, COUNT(*) AS count
49
                    FROM card
50
                    GROUP BY document_type_id
51
                ) AS tmp ON tmp.id = document_type.id
52
                SET usage_count = tmp.count;
53
                SQL
54
        );
55
56
        $this->addSql(
57
            <<<SQL
58
                UPDATE domain INNER JOIN (
59
                    SELECT card_domain.domain_id AS id, COUNT(*) AS count
60
                    FROM card_domain
61
                    GROUP BY id
62
                ) AS tmp ON tmp.id = domain.id
63
                SET usage_count = tmp.count;
64
                SQL
65
        );
66
67
        $this->addSql(
68
            <<<SQL
69
                UPDATE institution INNER JOIN (
70
                    SELECT card.institution_id AS id, COUNT(*) AS count
71
                    FROM card
72
                    GROUP BY institution_id
73
                ) AS tmp ON tmp.id = institution.id
74
                SET usage_count = tmp.count;
75
                SQL
76
        );
77
78
        $this->addSql(
79
            <<<SQL
80
                UPDATE material INNER JOIN (
81
                    SELECT card_material.material_id AS id, COUNT(*) AS count
82
                    FROM card_material
83
                    GROUP BY id
84
                ) AS tmp ON tmp.id = material.id
85
                SET usage_count = tmp.count;
86
                SQL
87
        );
88
89
        $this->addSql(
90
            <<<SQL
91
                UPDATE period INNER JOIN (
92
                    SELECT card_period.period_id AS id, COUNT(*) AS count
93
                    FROM card_period
94
                    GROUP BY id
95
                ) AS tmp ON tmp.id = period.id
96
                SET usage_count = tmp.count;
97
                SQL
98
        );
99
100
        $this->addSql(
101
            <<<SQL
102
                UPDATE tag INNER JOIN (
103
                    SELECT card_tag.tag_id AS id, COUNT(*) AS count
104
                    FROM card_tag
105
                    GROUP BY id
106
                ) AS tmp ON tmp.id = tag.id
107
                SET usage_count = tmp.count;
108
                SQL
109
        );
110
    }
111
}
112