Completed
Pull Request — master (#3)
by Rougin
02:40
created

Describe   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 91.67%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 10
c 2
b 0
f 0
lcom 1
cbo 3
dl 0
loc 85
ccs 22
cts 24
cp 0.9167
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getPrimaryKey() 0 16 4
A getTable() 0 12 3
A showTables() 0 4 1
A __call() 0 4 1
1
<?php
2
3
namespace Rougin\Describe;
4
5
/**
6
 * Describe
7
 *
8
 * Gets information of a table schema from a database.
9
 *
10
 * @package Describe
11
 * @author  Rougin Royce Gutib <[email protected]>
12
 */
13
class Describe
14
{
15
    /**
16
     * @var array
17
     */
18
    protected $columns = [];
19
20
    /**
21
     * @var \Rougin\Describe\Driver\DriverInterface
22
     */
23
    protected $driver;
24
25
    /**
26
     * @param \Rougin\Describe\Driver\DriverInterface $driver
27
     */
28 69
    public function __construct(\Rougin\Describe\Driver\DriverInterface $driver)
29
    {
30 69
        $this->driver = $driver;
31 69
    }
32
33
    /**
34
     * Gets the primary key in the specified table.
35
     *
36
     * @param  string $table
37
     * @return string
38
     */
39 12
    public function getPrimaryKey($table)
40
    {
41 12
        $result = '';
42
43 12
        if (empty($this->columns)) {
44 12
            $this->columns = $this->driver->getTable($table);
45 12
        }
46
47 12
        foreach ($this->columns as $column) {
48 12
            if ($column->isPrimaryKey()) {
49 12
                $result = $column->getField();
50 12
            }
51 12
        }
52
53 12
        return $result;
54
    }
55
56
    /**
57
     * Returns the result.
58
     *
59
     * @param  string $table
0 ignored issues
show
Bug introduced by
There is no parameter named $table. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
60
     * @return array
61
     * @throws \Rougin\Describe\Exceptions\TableNameNotFoundException
62
     */
63 45
    public function getTable($tableName)
64
    {
65 45
        $table = $this->driver->getTable($tableName);
66
67 45
        if (empty($table) || is_null($table)) {
68
            $message = '"' . $tableName . '" table not found in database!';
69
70
            throw new Exceptions\TableNameNotFoundException($message);
71
        }
72
73 45
        return $table;
74
    }
75
76
    /**
77
     * Shows the list of tables.
78
     *
79
     * @return array
80
     */
81 12
    public function showTables()
82
    {
83 12
        return $this->driver->showTables();
84
    }
85
86
    /**
87
     * Calls methods from this class in underscore case.
88
     *
89
     * @param  string $method
90
     * @param  mixed  $parameters
91
     * @return mixed
92
     */
93 36
    public function __call($method, $parameters)
94
    {
95 36
        return MagicMethodHelper::call($this, $method, $parameters);
96
    }
97
}
98