Table   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 50
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A validate() 0 8 2
A getColumn() 0 4 2
1
<?php
2
3
namespace ORM\Dbal;
4
5
use ArrayObject;
6
use ORM\Exception\UnknownColumn;
7
8
/**
9
 * Table is basically an array of Columns
10
 *
11
 * @package ORM\Dbal
12
 * @author  Thomas Flori <[email protected]>
13
 * @method Column offsetGet($offset)
14
 */
15
class Table extends ArrayObject
16
{
17
    /** The columns from this table
18
     * @var Column[] */
19
    protected $columns;
20
21
    /**
22
     * Table constructor.
23
     *
24
     * @param Column[] $columns
25
     */
26 110
    public function __construct(array $columns)
27
    {
28 110
        foreach ($columns as $column) {
29 107
            $this->columns[$column->name] = $column;
30
        }
31
32 110
        parent::__construct($columns);
33 110
    }
34
35
    /**
36
     * Validate $value for column $col.
37
     *
38
     * Returns an array with at least
39
     *
40
     * @param string $col
41
     * @param mixed $value
42
     * @return bool|Error
43
     * @throws UnknownColumn
44
     */
45 4
    public function validate($col, $value)
46
    {
47 4
        if (!($column = $this->getColumn($col))) {
48 2
            throw new UnknownColumn('Unknown column ' . $col);
49
        }
50
51 2
        return $column->validate($value);
52
    }
53
54
    /**
55
     * Get the Column object for $col
56
     *
57
     * @param string $col
58
     * @return Column
59
     */
60 4
    public function getColumn($col)
61
    {
62 4
        return isset($this->columns[$col]) ? $this->columns[$col] : null;
63
    }
64
}
65