Table::columns()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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