Table   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 19
dl 0
loc 43
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getFromMapper() 0 23 4
1
<?php
2
/********************************************************************************
3
 *   Apache License, Version 2.0                                                *
4
 *                                                                              *
5
 *   Copyright [2020] [Nurlan Mukhanov <[email protected]>]                      *
6
 *                                                                              *
7
 *   Licensed under the Apache License, Version 2.0 (the "License");            *
8
 *   you may not use this file except in compliance with the License.           *
9
 *   You may obtain a copy of the License at                                    *
10
 *                                                                              *
11
 *       http://www.apache.org/licenses/LICENSE-2.0                             *
12
 *                                                                              *
13
 *   Unless required by applicable law or agreed to in writing, software        *
14
 *   distributed under the License is distributed on an "AS IS" BASIS,          *
15
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
16
 *   See the License for the specific language governing permissions and        *
17
 *   limitations under the License.                                             *
18
 *                                                                              *
19
 ********************************************************************************/
20
21
declare(strict_types=1);
22
23
namespace DBD\Entity;
24
25
/**
26
 * Class Table useless still
27
 *
28
 * @package DBD\Entity
29
 */
30
class Table
31
{
32
    /** @var string $name */
33
    public $name;
34
    /** @var string $scheme */
35
    public $scheme;
36
    /** @var Column[] $columns */
37
    public $columns = [];
38
    /** @var Key[] $keys */
39
    public $keys = [];
40
    /** @var string $annotation */
41
    public $annotation;
42
    /** @var Constraint[] $constraints */
43
    public $constraints = [];
44
45
    /**
46
     * @param Mapper $mapper
47
     *
48
     * @return Table
49
     */
50
    public static function getFromMapper(Mapper $mapper): Table
51
    {
52
        $table = new Table();
53
54
        /** @var Entity $entityClass Getting class name from Mapper instance, which can be used as class instance */
55
        $entityClass = $mapper->getEntityClass();
56
57
        $table->name = $entityClass::TABLE;
58
        $table->scheme = $entityClass::SCHEME;
59
        $table->annotation = $mapper->getAnnotation();
60
61
        foreach ($mapper->getColumns() as $column) {
62
            $table->columns[] = $column;
63
            if ($column->key) {
64
                $table->keys[] = $column;
65
            }
66
        }
67
68
        foreach ($mapper->getConstraints() as $constraint) {
69
            $table->constraints[] = $constraint;
70
        }
71
72
        return $table;
73
    }
74
}
75