Completed
Branch 7-dev (bf2895)
by Oscar
03:53
created

Cache::schemeToArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace SimpleCrud\Scheme;
5
6
/**
7
 * Class to cache the scheme
8
 */
9
final class Cache implements SchemeInterface
10
{
11
    private $scheme;
12
13
    public static function schemeToArray(SchemeInterface $scheme): array
14
    {
15
        $arrayScheme = [];
16
17
        foreach ($scheme->getTables() as $table) {
18
            $arrayScheme[$table] = $scheme->getTableFields($table);
19
        }
20
21
        return $arrayScheme;
22
    }
23
24
    public function __construct(array $scheme)
25
    {
26
        $this->scheme = $scheme;
27
    }
28
29
    public function getTables(): array
30
    {
31
        return array_keys($this->scheme);
32
    }
33
34
    public function getTableFields(string $table): array
35
    {
36
        return $this->scheme[$table];
37
    }
38
}
39