Completed
Push — master ( 46dbb7...9c8538 )
by Hong
02:48
created

TableTrait   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 64
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A from() 0 14 4
A table() 0 6 1
A multipleFrom() 0 10 3
A buildTable() 0 6 1
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Query
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Query\Traits\Clause;
16
17
use Phossa2\Query\Interfaces\Clause\TableInterface;
18
19
/**
20
 * TableTrait
21
 *
22
 * Implementation of TableInterface
23
 *
24
 * @package Phossa2\Query
25
 * @author  Hong Zhang <[email protected]>
26
 * @see     TableInterface
27
 * @version 2.0.0
28
 * @since   2.0.0 added
29
 */
30
trait TableTrait
31
{
32
    use AbstractTrait;
33
34
    /**
35
     * {@inheritDoc}
36
     */
37
    public function from($table, /*# string */ $alias = '')
38
    {
39
        if (is_array($table)) {
40
            $this->multipleFrom($table);
41
        } elseif (!empty($table)) {
42
            $clause = &$this->getClause('TABLE');
43
            if (empty($alias)) {
44
                $clause[] = [$table, false];
45
            } else {
46
                $clause[(string) $alias] = [$table, false];
47
            }
48
        }
49
        return $this;
50
    }
51
52
    /**
53
     * {@inheritDoc}
54
     */
55
    public function table($table, /*# string */ $alias = '')
56
    {
57
        $clause = &$this->getClause('TABLE');
58
        $clause = [];
59
        return $this->from($table, $alias);
60
    }
61
62
    /**
63
     * from multiple tables
64
     *
65
     * @param  array $tables
66
     * @access protected
67
     */
68
    protected function multipleFrom(array $tables)
69
    {
70
        foreach ($tables as $key => $val) {
71
            if (is_int($key)) {
72
                $this->from($val);
73
            } else {
74
                $this->from($key, $val);
75
            }
76
        }
77
    }
78
79
    /**
80
     * Build TABLE
81
     *
82
     * @param  string $prefix
83
     * @param  array $settings
84
     * @return array
85
     * @access protected
86
     */
87
    protected function buildTable(
88
        /*# string */ $prefix,
89
        array $settings
90
    )/*# : string */ {
91
        return $this->buildClause('TABLE', $prefix, $settings);
92
    }
93
}
94