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

Cache   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 30
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A schemeToArray() 0 10 2
A __construct() 0 4 1
A getTables() 0 4 1
A getTableFields() 0 4 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