Table   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 11
c 2
b 0
f 1
dl 0
loc 59
ccs 14
cts 14
cp 1
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A primary() 0 9 4
A columns() 0 3 1
A name() 0 3 1
1
<?php
2
3
namespace Rougin\Describe;
4
5
use Rougin\Describe\Driver\DriverInterface;
6
7
/**
8
 * Table
9
 *
10
 * Stores the table information from the given results.
11
 *
12
 * @package Describe
13
 * @author  Rougin Gutib <[email protected]>
14
 */
15
class Table
16
{
17
    /**
18
     * @var \Rougin\Describe\Driver\DriverInterface
19
     */
20
    protected $driver;
21
22
    /**
23
     * @var string
24
     */
25
    protected $name;
26
27
    /**
28
     * Initializes the table instance.
29
     *
30
     * @param string                                  $name
31
     * @param \Rougin\Describe\Driver\DriverInterface $driver
32
     */
33 60
    public function __construct($name, DriverInterface $driver)
34
    {
35 60
        $this->driver = $driver;
36
37 60
        $this->name = (string) $name;
38 60
    }
39
40
    /**
41
     * Returns an array of Column instances.
42
     *
43
     * @return \Rougin\Describe\Column[]
44
     */
45 27
    public function columns()
46
    {
47 27
        return $this->driver->columns($this->name);
48
    }
49
50
    /**
51
     * Returns the name of the table.
52
     *
53
     * @return string
54
     */
55 3
    public function name()
56
    {
57 3
        return $this->name;
58
    }
59
60
    /**
61
     * Returns the primary key of a table.
62
     *
63
     * @return \Rougin\Describe\Column|null
64
     */
65 24
    public function primary()
66
    {
67 24
        foreach ($this->columns() as $column) {
68 24
            $primary = $column->isPrimaryKey();
69
70 24
            $primary && $result = $column;
71 8
        }
72
73 24
        return isset($result) ? $result : null;
74
    }
75
}
76