Completed
Push — master ( af237a...780e00 )
by Hong
02:32
created

Template::getStatement()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 11
nc 2
nop 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\Misc;
16
17
use Phossa2\Query\Traits\Clause\QuoteTrait;
18
19
/**
20
 * Template
21
 *
22
 * Clause template
23
 *
24
 * @package Phossa2\Query
25
 * @author  Hong Zhang <[email protected]>
26
 * @see     Raw
27
 * @version 2.0.0
28
 * @since   2.0.0 added
29
 */
30
class Template extends Raw
31
{
32
    use QuoteTrait;
33
34
    /**
35
     * @var    string
36
     * @access protected
37
     */
38
    protected $template;
39
40
    /**
41
     * @var    string|string[]
42
     * @access protected
43
     */
44
    protected $col;
45
46
    /**
47
     * @param  string $template
48
     * @param  string|string[] $col column[s]
49
     * @access public
50
     */
51
    public function __construct(/*# string */ $template, $col)
52
    {
53
        $this->template = $template;
54
        $this->col = $col;
55
    }
56
57
    /**
58
     * {@inheritDoc}
59
     */
60
    public function getStatement(array $settings= [])/*# : string */
61
    {
62
        if (!empty($settings)) {
63
            $quoted = [];
64
            foreach ((array) $this->col as $c) {
65
                $quoted[] = $this->quote(
66
                    $c,
67
                    $settings['quotePrefix'],
68
                    $settings['quoteSuffix']
69
                );
70
            }
71
        } else {
72
            $quoted = (array) $this->col;
73
        }
74
        return vsprintf($this->template, $quoted);
75
    }
76
}
77