Passed
Push — master ( 6df7c9...74bc2a )
by y
02:15
created

AbstractTable   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 5
c 1
b 0
f 0
dl 0
loc 52
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A offsetSet() 0 2 1
A offsetUnset() 0 2 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
     * @var DB
16
     */
17
    protected $db;
18
19
    /**
20
     * @param DB $db
21
     */
22
    public function __construct (DB $db) {
23
        $this->db = $db;
24
    }
25
26
    /**
27
     * Returns the SQL reference qualifier (i.e. the table name)
28
     *
29
     * @return string
30
     */
31
    abstract public function __toString ();
32
33
    /**
34
     * @param string $name
35
     * @return bool
36
     */
37
    abstract public function offsetExists ($name): bool;
38
39
    /**
40
     * @param string $name
41
     * @return Column
42
     */
43
    abstract public function offsetGet ($name);
44
45
    /**
46
     * Throws.
47
     *
48
     * @param void $name
49
     * @param void $value
50
     * @throws Exception
51
     */
52
    final public function offsetSet ($name, $value): void {
53
        throw new Exception('Tables are immutable.');
54
    }
55
56
    /**
57
     * Throws.
58
     *
59
     * @param void $name
60
     * @throws Exception
61
     */
62
    final public function offsetUnset ($name): void {
63
        $this->offsetSet($name, null);
64
    }
65
}