Update::addTable()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2
Metric Value
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4286
cc 2
eloc 5
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Muffin\Queries\Snippets;
4
5
use Muffin\Snippet;
6
7
class Update implements Snippet
8
{
9
    private
10
        $tables;
11
12 17
    public function __construct($table = null, $alias = null)
13
    {
14 17
        $this->tables = array();
15
16 17
        if(! empty($table))
17 17
        {
18 7
            $this->addTable($table, $alias);
19 7
        }
20 17
    }
21
22 14
    public function addTable($table, $alias = null)
23
    {
24 14
        if(! $table instanceof TableName)
25 14
        {
26 13
            $table = new TableName($table, $alias);
27 11
        }
28
29 12
        $this->tables[] = $table;
30
31 12
        return $this;
32
    }
33
34 15
    public function toString()
35
    {
36 15
        if(empty($this->tables))
37 15
        {
38 3
            return '';
39
        }
40
41 12
        $tables = array();
42
43 12
        foreach($this->tables as $table)
44
        {
45 12
            $tables[] = $table->toString();
46 12
        }
47
48 12
        $tablesString = implode(', ', array_filter($tables));
49
50 12
        return sprintf('UPDATE %s', $tablesString);
51
    }
52
}
53