Passed
Push — dbal ( a67a72...c31592 )
by Greg
08:19
created

Table   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 89
rs 10
c 0
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getIndexes() 0 3 1
A getPrimaryKeys() 0 3 1
A __construct() 0 7 1
A getUniqueIndexes() 0 3 1
A addColumn() 0 5 1
A getName() 0 3 1
A getForeignKeys() 0 3 1
A getColumns() 0 3 1
1
<?php
2
3
/**
4
 * webtrees: online genealogy
5
 * Copyright (C) 2022 webtrees development team
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 * GNU General Public License for more details.
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16
 */
17
18
declare(strict_types=1);
19
20
namespace Fisharebest\Webtrees\DB\Schema;
21
22
/**
23
 *
24
 */
25
class Table
26
{
27
    /** @var array<ColumnInterface> */
28
    private array $columns;
29
30
    /** @var array<Index> */
31
    private array $indexes;
32
33
    /** @var array<UniqueIndex> */
34
    private array $unique_indexes;
35
36
    /** @var array<PrimaryKey> */
37
    private array $primary_keys;
38
39
    /** @var array<ForeignKey> */
40
    private array $foreign_keys;
41
42
43
    /**
44
     * @param string                                                         $name
45
     * @param array<ColumnInterface|Index|UniqueIndex|PrimaryKey|ForeignKey> $components
46
     */
47
    public function __construct(private readonly string $name, array $components = [])
48
    {
49
        $this->columns        = array_filter($components, static fn($component): bool => $component instanceof ColumnInterface);
50
        $this->indexes        = array_filter($components, static fn($component): bool => $component instanceof Index);
51
        $this->unique_indexes = array_filter($components, static fn($component): bool => $component instanceof UniqueIndex);
52
        $this->primary_keys   = array_filter($components, static fn($component): bool => $component instanceof PrimaryKey);
53
        $this->foreign_keys   = array_filter($components, static fn($component): bool => $component instanceof ForeignKey);
54
    }
55
56
    /**
57
     * @param ColumnInterface $column
58
     *
59
     * @return $this
60
     */
61
    public function addColumn(ColumnInterface $column): static
62
    {
63
        $this->columns[$column->getName()] = $column;
64
65
        return $this;
66
    }
67
68
    /**
69
     * @return string
70
     */
71
    public function getName(): string
72
    {
73
        return $this->name;
74
    }
75
76
    /**
77
     * @return array<ColumnInterface>
78
     */
79
    public function getColumns(): array
80
    {
81
        return $this->columns;
82
    }
83
84
    /**
85
     * @return array<Index>
86
     */
87
    public function getIndexes(): array
88
    {
89
        return $this->indexes;
90
    }
91
92
    /**
93
     * @return array<UniqueIndex>
94
     */
95
    public function getUniqueIndexes(): array
96
    {
97
        return $this->unique_indexes;
98
    }
99
100
    /**
101
     * @return array<ForeignKey>
102
     */
103
    public function getForeignKeys(): array
104
    {
105
        return $this->foreign_keys;
106
    }
107
108
    /**
109
     * @return array<PrimaryKey>
110
     */
111
    public function getPrimaryKeys(): array
112
    {
113
        return $this->primary_keys;
114
    }
115
}
116