ResetTables::run()   B
last analyzed

Complexity

Conditions 7
Paths 11

Size

Total Lines 32
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 20.0204

Importance

Changes 0
Metric Value
cc 7
eloc 15
nc 11
nop 1
dl 0
loc 32
ccs 5
cts 14
cp 0.357
crap 20.0204
rs 8.8333
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Schema\Generator;
6
7
use Cycle\Schema\GeneratorInterface;
8
use Cycle\Schema\Registry;
9
10
/**
11
 * Declare table dropped (initiate diff calculation).
12
 */
13
final class ResetTables implements GeneratorInterface
14
{
15
    public function run(Registry $registry): Registry
16
    {
17
        foreach ($registry as $entity) {
18
            if (!$registry->hasTable($entity)) {
19
                continue;
20 16
            }
21
22 16
            $schema = $registry->getTableSchema($entity);
23 16
            if ($schema->exists()) {
24
                $state = $schema->getState();
25
26
                // clean up all indexes and columns
27 16
                foreach ($state->getForeignKeys() as $fk) {
28 16
                    $state->forgerForeignKey($fk);
0 ignored issues
show
Deprecated Code introduced by
The function Cycle\Database\Schema\State::forgerForeignKey() has been deprecated: Since cycle/database 2.2.0, use {@see forgetForeignKey()} instead. ( Ignorable by Annotation )

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

28
                    /** @scrutinizer ignore-deprecated */ $state->forgerForeignKey($fk);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
29
                }
30
31
                // clean up all indexes and columns
32
                foreach ($state->getColumns() as $column) {
33
                    $state->forgetColumn($column);
34
                }
35
36
                foreach ($state->getIndexes() as $index) {
37
                    $state->forgetIndex($index);
38
                }
39
40
                $state->setPrimaryKeys([]);
41
42
                $schema->setState($state);
43
            }
44
        }
45
46
        return $registry;
47
    }
48
}
49