Failed Conditions
Push — master ( 2f2402...0ef5da )
by Adrien
13:58
created

EnumAutoMigrator::postGenerateSchema()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 10
cc 4
nc 4
nop 1
crap 20
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
    public function postGenerateSchema(GenerateSchemaEventArgs $eventArgs): void
16
    {
17
        foreach ($eventArgs->getSchema()->getTables() as $table) {
18
            foreach ($table->getColumns() as $column) {
19
                $type = $column->getType();
20
                if ($type instanceof EnumType) {
21
                    $hash = md5($type->getQuotedPossibleValues());
0 ignored issues
show
Bug introduced by
The method getQuotedPossibleValues() does not exist on Ecodev\Felix\DBAL\Types\EnumType. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

21
                    $hash = md5($type->/** @scrutinizer ignore-call */ getQuotedPossibleValues());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
22
                    $column->setComment("(FelixEnum:$hash)");
23
                }
24
            }
25
        }
26
    }
27
}
28