Completed
Push — master ( 99696f...35c3f5 )
by Rougin
02:37
created

Table   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 61
rs 10

4 Methods

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