• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dg / dibi / 22284747548

22 Feb 2026 08:29PM UTC coverage: 76.399% (+0.09%) from 76.31%
22284747548

push

github

dg
added CLAUDE.md

1761 of 2305 relevant lines covered (76.4%)

0.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.6
/src/Dibi/Reflection/Table.php
1
<?php declare(strict_types=1);
2

3
/**
4
 * This file is part of the Dibi, smart database abstraction layer (https://dibi.nette.org)
5
 * Copyright (c) 2005 David Grudl (https://davidgrudl.com)
6
 */
7

8
namespace Dibi\Reflection;
9

10
use Dibi;
11
use function array_values, strtolower;
12

13

14
/**
15
 * Reflection metadata class for a database table.
16
 *
17
 * @property-read string $name
18
 * @property-read bool $view
19
 * @property-read list<Column> $columns
20
 * @property-read list<string> $columnNames
21
 * @property-read list<ForeignKey> $foreignKeys
22
 * @property-read list<Index> $indexes
23
 * @property-read Index $primaryKey
24
 */
25
class Table
26
{
27
        private readonly Dibi\Reflector $reflector;
28
        private string $name;
29
        private bool $view;
30

31
        /** @var Column[] */
32
        private array $columns;
33

34
        /** @var ForeignKey[] */
35
        private array $foreignKeys;
36

37
        /** @var Index[] */
38
        private array $indexes;
39
        private ?Index $primaryKey = null;
40

41

42
        /** @param  array{name: string, view?: bool}  $info */
43
        public function __construct(Dibi\Reflector $reflector, array $info)
1✔
44
        {
45
                $this->reflector = $reflector;
1✔
46
                $this->name = $info['name'];
1✔
47
                $this->view = !empty($info['view']);
1✔
48
        }
1✔
49

50

51
        public function getName(): string
52
        {
53
                return $this->name;
1✔
54
        }
55

56

57
        public function isView(): bool
58
        {
59
                return $this->view;
1✔
60
        }
61

62

63
        /** @return Column[] */
64
        public function getColumns(): array
65
        {
66
                $this->initColumns();
1✔
67
                return array_values($this->columns);
1✔
68
        }
69

70

71
        /** @return string[] */
72
        public function getColumnNames(): array
73
        {
74
                $this->initColumns();
×
75
                $res = [];
×
76
                foreach ($this->columns as $column) {
×
77
                        $res[] = $column->getName();
×
78
                }
79

80
                return $res;
×
81
        }
82

83

84
        public function getColumn(string $name): Column
1✔
85
        {
86
                $this->initColumns();
1✔
87
                $l = strtolower($name);
1✔
88
                if (isset($this->columns[$l])) {
1✔
89
                        return $this->columns[$l];
1✔
90

91
                } else {
92
                        throw new Dibi\Exception("Table '$this->name' has no column '$name'.");
×
93
                }
94
        }
95

96

97
        public function hasColumn(string $name): bool
1✔
98
        {
99
                $this->initColumns();
1✔
100
                return isset($this->columns[strtolower($name)]);
1✔
101
        }
102

103

104
        /** @return ForeignKey[] */
105
        public function getForeignKeys(): array
106
        {
107
                $this->initForeignKeys();
×
108
                return $this->foreignKeys;
×
109
        }
110

111

112
        /** @return Index[] */
113
        public function getIndexes(): array
114
        {
115
                $this->initIndexes();
1✔
116
                return $this->indexes;
1✔
117
        }
118

119

120
        public function getPrimaryKey(): ?Index
121
        {
122
                $this->initIndexes();
×
123
                return $this->primaryKey;
×
124
        }
125

126

127
        protected function initColumns(): void
128
        {
129
                if (!isset($this->columns)) {
1✔
130
                        $this->columns = [];
1✔
131
                        foreach ($this->reflector->getColumns($this->name) as $info) {
1✔
132
                                $this->columns[strtolower($info['name'])] = new Column($this->reflector, $info);
1✔
133
                        }
134
                }
135
        }
1✔
136

137

138
        protected function initIndexes(): void
139
        {
140
                if (!isset($this->indexes)) {
1✔
141
                        $this->initColumns();
1✔
142
                        $this->indexes = [];
1✔
143
                        foreach ($this->reflector->getIndexes($this->name) as $info) {
1✔
144
                                $cols = [];
1✔
145
                                foreach ($info['columns'] as $name) {
1✔
146
                                        $cols[] = $this->columns[strtolower($name)];
1✔
147
                                }
148

149
                                $info['columns'] = $cols;
1✔
150
                                $this->indexes[strtolower($info['name'])] = new Index($info);
1✔
151
                                if (!empty($info['primary'])) {
1✔
152
                                        $this->primaryKey = $this->indexes[strtolower($info['name'])];
1✔
153
                                }
154
                        }
155
                }
156
        }
1✔
157

158

159
        protected function initForeignKeys(): void
160
        {
161
                throw new Dibi\NotImplementedException;
×
162
        }
163
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc