Update   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%
Metric Value
dl 0
loc 46
wmc 7
lcom 1
cbo 1
ccs 24
cts 24
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A addTable() 0 11 2
A toString() 0 18 3
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