Template   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 45
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getStatement() 0 12 3
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
use Phossa2\Query\Interfaces\OutputInterface;
19
20
/**
21
 * Template
22
 *
23
 * Clause template
24
 *
25
 * @package Phossa2\Query
26
 * @author  Hong Zhang <[email protected]>
27
 * @see     Raw
28
 * @version 2.0.0
29
 * @since   2.0.0 added
30
 */
31
class Template extends Raw
32
{
33
    use QuoteTrait;
34
35
    /**
36
     * @var    string
37
     * @access protected
38
     */
39
    protected $template;
40
41
    /**
42
     * @var    string|string[]
43
     * @access protected
44
     */
45
    protected $col;
46
47
    /**
48
     * Constructor
49
     *
50
     * @param  string|OutputInterface $template
51
     * @param  string|string[] $col column[s]
52
     * @access public
53
     */
54
    public function __construct($template, $col)
55
    {
56
        $this->template = (string) $template;
57
        $this->col = $col;
58
    }
59
60
    /**
61
     * {@inheritDoc}
62
     */
63
    public function getStatement(array $settings = [])/*# : string */
64
    {
65
        if (!empty($settings)) {
66
            $quoted = [];
67
            foreach ((array) $this->col as $c) {
68
                $quoted[] = $this->quote($c, $settings);
69
            }
70
        } else {
71
            $quoted = (array) $this->col;
72
        }
73
        return vsprintf($this->template, $quoted);
74
    }
75
}
76