Completed
Push — master ( 4eddf0...7fb17b )
by Christopher
04:53
created

Manager   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 1 Features 1
Metric Value
wmc 5
c 1
b 1
f 1
lcom 1
cbo 1
dl 0
loc 68
ccs 0
cts 29
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __call() 0 9 1
A get() 0 10 1
A first() 0 12 2
1
<?php
2
3
namespace AsyncPHP\Icicle\Database;
4
5
use Icicle\Coroutine;
6
use Icicle\Promise\PromiseInterface;
7
8
final class Manager
9
{
10
    /**
11
     * @var Connector
12
     */
13
    private $connector;
14
15
    /**
16
     * @var Builder
17
     */
18
    private $builder;
19
20
    /**
21
     * @param Connector $connector
22
     * @param Builder $builder
23
     */
24
    public function __construct(Connector $connector, Builder $builder)
25
    {
26
        $this->connector = $connector;
27
        $this->builder = $builder;
28
    }
29
30
    /**
31
     * @param string $method
32
     * @param array $parameters
33
     *
34
     * @return mixed
35
     */
36
    public function __call($method, array $parameters = [])
37
    {
38
        $builder = call_user_func_array([$this->builder, $method], $parameters);
39
40
        $clone = clone $this;
41
        $clone->builder = $builder;
42
43
        return $clone;
44
    }
45
46
    /**
47
     * @return PromiseInterface
48
     */
49
    public function get()
50
    {
51
        return Coroutine\create(function () {
52
            list($statement, $bindings) = $this->builder->build();
0 ignored issues
show
Unused Code introduced by
The assignment to $bindings is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
53
54
            // TODO
55
56
            yield $this->connector->query($statement);
57
        });
58
    }
59
60
    /**
61
     * @return PromiseInterface
62
     */
63
    public function first()
64
    {
65
        return Coroutine\create(function () {
66
            $rows = (yield $this->limit(1)->get());
67
68
            if (count($rows) > 0) {
69
                yield $rows[0];
70
            } else {
71
                yield [];
72
            }
73
        });
74
    }
75
}
76