Passed
Push — master ( 6c4562...bd418e )
by y
01:33
created

AbstractTable   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

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

4 Methods

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