Passed
Push — master ( 7a7f8a...b2317b )
by Anton
01:59
created

CleanTables   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 13 4
1
<?php declare(strict_types=1);
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
9
namespace Cycle\Schema\Generator;
10
11
use Cycle\Schema\GeneratorInterface;
12
use Cycle\Schema\Registry;
13
14
/**
15
 * Declare table dropped (initiate diff calculation).
16
 */
17
final class CleanTables implements GeneratorInterface
18
{
19
    public const OPT_SKIP = 'skipClean';
20
21
    /**
22
     * @param Registry $registry
23
     * @return Registry
24
     */
25
    public function run(Registry $registry): Registry
26
    {
27
        foreach ($registry as $entity) {
28
            if (!$registry->hasTable($entity)) {
29
                continue;
30
            }
31
32
            if (!$entity->getOptions()->has(self::OPT_SKIP)) {
33
                $registry->getTableSchema($entity)->declareDropped();
34
            }
35
        }
36
37
        return $registry;
38
    }
39
}