Total Complexity | 8 |
Total Lines | 78 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
15 | class Result implements ResultInterface |
||
16 | { |
||
17 | /** |
||
18 | * @var integer |
||
19 | */ |
||
20 | protected $affected = 0; |
||
21 | |||
22 | /** |
||
23 | * @var \Illuminate\Support\Collection |
||
24 | */ |
||
25 | protected $result; |
||
26 | |||
27 | /** |
||
28 | * Returns a number of affected rows. |
||
29 | * |
||
30 | * @return integer |
||
31 | */ |
||
32 | 9 | public function affected() |
|
35 | } |
||
36 | |||
37 | /** |
||
38 | * Returns a result from a query instance. |
||
39 | * |
||
40 | * @param \Rougin\Windstorm\QueryInterface $query |
||
41 | * @return \Rougin\Windstorm\ResultInterface |
||
42 | */ |
||
43 | 15 | public function execute(QueryInterface $query) |
|
44 | { |
||
45 | 15 | $builder = $query->instance(); |
|
46 | |||
47 | 15 | if ($query->type() === QueryInterface::TYPE_SELECT) |
|
48 | 10 | { |
|
49 | 6 | $this->result = $builder->get(); |
|
50 | |||
51 | 6 | return $this; |
|
52 | } |
||
53 | |||
54 | 9 | $bindings = $query->bindings(); |
|
55 | |||
56 | 9 | switch ($query->type()) |
|
57 | { |
||
58 | 9 | case QueryInterface::TYPE_INSERT: |
|
59 | 3 | $this->affected = $builder->insert($bindings); |
|
60 | |||
61 | 3 | break; |
|
62 | 6 | case QueryInterface::TYPE_UPDATE: |
|
63 | 3 | $this->affected = $builder->update($bindings); |
|
64 | |||
65 | 3 | break; |
|
66 | 3 | case QueryInterface::TYPE_DELETE: |
|
67 | 3 | $this->affected = $builder->delete($bindings); |
|
68 | |||
69 | 3 | break; |
|
70 | 6 | } |
|
71 | |||
72 | 9 | return $this; |
|
73 | } |
||
74 | |||
75 | /** |
||
76 | * Returns the first row from result. |
||
77 | * |
||
78 | * @return mixed |
||
79 | */ |
||
80 | 3 | public function first() |
|
83 | } |
||
84 | |||
85 | /** |
||
86 | * Returns the first row from result. |
||
87 | * |
||
88 | * @return mixed |
||
89 | */ |
||
90 | 3 | public function items() |
|
93 | } |
||
94 | } |
||
95 |