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

AbstractTable::offsetExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 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
}