Failed Conditions
Push — master ( 0ef5da...6c8847 )
by Adrien
11:04 queued 07:56
created

EnumAutoMigrator::postGenerateSchema()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 8
ccs 7
cts 7
cp 1
rs 10
cc 4
nc 4
nop 1
crap 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ecodev\Felix\Service;
6
7
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
8
use Ecodev\Felix\DBAL\Types\EnumType;
9
10
/**
11
 * When we update our enum values in PHP (native or non-native), a DB migration will be created automatically.
12
 */
13
class EnumAutoMigrator
14
{
15 1
    public function postGenerateSchema(GenerateSchemaEventArgs $eventArgs): void
16
    {
17 1
        foreach ($eventArgs->getSchema()->getTables() as $table) {
18 1
            foreach ($table->getColumns() as $column) {
19 1
                $type = $column->getType();
20 1
                if ($type instanceof EnumType) {
21 1
                    $hash = md5($type->getQuotedPossibleValues());
22 1
                    $column->setComment("(FelixEnum:$hash)");
23
                }
24
            }
25
        }
26
    }
27
}
28