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%

Importance

Changes 0
Metric Value
dl 0
loc 46
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1
ccs 18
cts 18
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
declare(strict_types = 1);
4
5
namespace Puzzle\QueryBuilder\Queries\Snippets;
6
7
use Puzzle\QueryBuilder\Snippet;
8
9
class Update implements Snippet
10
{
11
    private
12
        $tables;
1 ignored issue
show
Coding Style introduced by
The visibility should be declared for property $tables.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
13
14 17
    public function __construct($table = null, ?string $alias = null)
15
    {
16 17
        $this->tables = array();
17
18 17
        if(! empty($table))
19
        {
20 7
            $this->addTable($table, $alias);
21
        }
22 17
    }
23
24 14
    public function addTable($table, ?string $alias = null): self
25
    {
26 14
        if(! $table instanceof TableName)
27
        {
28 13
            $table = new TableName($table, $alias);
29
        }
30
31 12
        $this->tables[] = $table;
32
33 12
        return $this;
34
    }
35
36 15
    public function toString(): string
37
    {
38 15
        if(empty($this->tables))
39
        {
40 3
            return '';
41
        }
42
43 12
        $tables = array();
44
45 12
        foreach($this->tables as $table)
46
        {
47 12
            $tables[] = $table->toString();
48
        }
49
50 12
        $tablesString = implode(', ', array_filter($tables));
51
52 12
        return sprintf('UPDATE %s', $tablesString);
53
    }
54
}
55