Passed
Push — dbal ( 52c0e6...62c715 )
by Greg
05:49
created

Table   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 72
rs 10
wmc 7

7 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 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
class Table
23
{
24
    /** @var array<ColumnInterface> */
25
    private array $columns;
26
27
    /** @var array<Index> */
28
    private array $indexes;
29
30
    /** @var array<UniqueIndex> */
31
    private array $unique_indexes;
32
33
    /** @var array<PrimaryKey> */
34
    private array $primary_keys;
35
36
    /** @var array<ForeignKey> */
37
    private array $foreign_keys;
38
39
40
    public function __construct(public readonly string $name, private array $components = [])
41
    {
42
        $this->columns        = array_filter($this->components, static fn($component): bool => $component instanceof ColumnInterface);
43
        $this->indexes        = array_filter($this->components, static fn($component): bool => $component instanceof Index);
44
        $this->unique_indexes = array_filter($this->components, static fn($component): bool => $component instanceof UniqueIndex);
45
        $this->primary_keys   = array_filter($this->components, static fn($component): bool => $component instanceof PrimaryKey);
46
        $this->foreign_keys   = array_filter($this->components, static fn($component): bool => $component instanceof ForeignKey);
47
    }
48
49
    public function addColumn(ColumnInterface $column): static
50
    {
51
        $this->columns[] = $column;
52
53
        return $this;
54
    }
55
56
    /**
57
     * @return array<ColumnInterface>
58
     */
59
    public function getColumns(): array
60
    {
61
        return $this->columns;
62
    }
63
64
    /**
65
     * @return array<Index>
66
     */
67
    public function getIndexes(): array
68
    {
69
        return $this->indexes;
70
    }
71
72
    /**
73
     * @return array<UniqueIndex>
74
     */
75
    public function getUniqueIndexes(): array
76
    {
77
        return $this->unique_indexes;
78
    }
79
80
    /**
81
     * @return array<ForeignKey>
82
     */
83
    public function getForeignKeys(): array
84
    {
85
        return $this->foreign_keys;
86
    }
87
88
    /**
89
     * @return array<PrimaryKey>
90
     */
91
    public function getPrimaryKeys(): array
92
    {
93
        return $this->primary_keys;
94
    }
95
}
96