Completed
Push — master ( 6adfd5...8dd9a1 )
by Rasmus
02:23
created

Returning   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 45.45%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 61
ccs 5
cts 11
cp 0.4545
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A returningTable() 0 6 1
A returningColumns() 0 6 1
A returningValue() 0 6 1
A getMappers() 0 4 1
1
<?php
2
3
namespace mindplay\sql\model\components;
4
5
use mindplay\sql\model\Column;
6
use mindplay\sql\model\Table;
7
use mindplay\sql\model\Type;
8
9
/**
10
 * This trait implements support for the `RETURNING` clause of Postgres `INSERT`, `UPDATE` and `DELETE` queries.
11
 */
12
trait Returning
13
{
14
    use Mappers;
15
16
    /**
17
     * @var ReturnVars
18
     */
19
    protected $return_vars;
20
    
21
    /**
22
     * Add all the Columns of a full Table to be selected and returned
23
     *
24
     * @param Table $table Table to select and return
25
     *
26
     * @return $this
27
     */
28
    public function returningTable(Table $table)
29
    {
30
        $this->return_vars->addTable($table);
31
32
        return $this;
33
    }
34
35
    /**
36
     * Add one or more Columns to select and return
37
     *
38
     * @param Column|Column[] one or more Columns to select and return
39
     *
40
     * @return $this
41
     */
42 1
    public function returningColumns($cols)
43
    {
44 1
        $this->return_vars->addColumns($cols);
45
46 1
        return $this;
47
    }
48
49
    /**
50
     * Add an SQL expression to select and return
51
     *
52
     * @param string           $expr return expression
53
     * @param string|null      $name return variable name (optional, but usually required)
54
     * @param Type|string|null $type optional Type (or Type class-name)
55
     *
56
     * @return $this
57
     */
58
    public function returningValue($expr, $name = null, $type = null)
59
    {
60
        $this->return_vars->addValue($expr, $name, $type);
61
62
        return $this;
63
    }
64
65
    /**
66
     * @inheritdoc
67
     */
68 1
    public function getMappers()
69
    {
70 1
        return array_merge([$this->return_vars->createTypeMapper()], $this->mappers);
71
    }
72
}
73