ResetTables   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 35.7%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 34
ccs 5
cts 14
cp 0.357
rs 10
c 0
b 0
f 0
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 32 7
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