PartitionTrait::buildPartition()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 2
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\PartitionInterface;
18
19
/**
20
 * PartitionTrait
21
 *
22
 * Implementation of PartitionInterface
23
 *
24
 * @package Phossa2\Query
25
 * @author  Hong Zhang <[email protected]>
26
 * @see     PartitionInterface
27
 * @version 2.0.0
28
 * @since   2.0.0 added
29
 */
30
trait PartitionTrait
31
{
32
    use AbstractTrait;
33
34
    /**
35
     * {@inheritDoc}
36
     */
37
    public function partition($partitionNames)
38
    {
39
        $clause = &$this->getClause('PARTITION');
40
        if (is_array($partitionNames)) {
41
            $clause = array_merge($clause, $partitionNames);
42
        } elseif (func_num_args() > 1) {
43
            $clause = array_merge($clause, func_get_args());
44
        } else {
45
            $clause[] = $partitionNames;
46
        }
47
        return $this;
48
    }
49
50
    /**
51
     * Build PARTITION
52
     *
53
     * @param  string $prefix
54
     * @param  array $settings
55
     * @return string
56
     * @access protected
57
     */
58
    protected function buildPartition(
59
        /*# string */ $prefix,
60
        array $settings
61
    )/*# : string */ {
62
        $sepr = $settings['seperator'];
63
        $clause = &$this->getClause('PARTITION');
64
        if (empty($clause)) {
65
            return '';
66
        } else {
67
            return $sepr . $prefix . ' (' . join(', ', $clause) . ')';
68
        }
69
    }
70
}
71