AbstractTable   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
c 2
b 0
f 0
dl 0
loc 66
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetSet() 0 3 1
A offsetExists() 0 3 1
A offsetUnset() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
namespace Helix\DB;
4
5
use ArrayAccess;
6
use Exception;
7
use Helix\DB;
8
9
/**
10
 * Uses `ArrayAccess` to produce {@link Column} instances.
11
 */
12
abstract class AbstractTable implements ArrayAccess
13
{
14
15
    /**
16
     * Returns the SQL reference qualifier (i.e. the table name)
17
     *
18
     * @return string
19
     */
20
    abstract public function __toString();
21
22
    /**
23
     * Columns keyed by name/alias.
24
     *
25
     * @return Column[]
26
     */
27
    abstract public function getColumns();
28
29
    /**
30
     * @param string $column
31
     * @return null|Column
32
     */
33
    abstract public function offsetGet($column);
34
35
    /**
36
     * @var DB
37
     */
38
    protected $db;
39
40
    /**
41
     * @param DB $db
42
     */
43
    public function __construct(DB $db)
44
    {
45
        $this->db = $db;
46
    }
47
48
    /**
49
     * @param int|string $column
50
     * @return bool
51
     */
52
    public function offsetExists($column): bool
53
    {
54
        return $this->offsetGet($column) !== null;
55
    }
56
57
    /**
58
     * Throws.
59
     *
60
     * @param void $offset
61
     * @param void $value
62
     * @throws Exception
63
     */
64
    final public function offsetSet($offset, $value): void
65
    {
66
        throw new Exception('Tables are immutable.');
67
    }
68
69
    /**
70
     * Throws.
71
     *
72
     * @param void $name
73
     * @throws Exception
74
     */
75
    final public function offsetUnset($name): void
76
    {
77
        $this->offsetSet($name, null);
78
    }
79
}
80