Passed
Push — master ( 7248ab...0a52e0 )
by Pierre
10:18
created

Pool::offsetSet()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
nc 2
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace App\Component\Db;
4
5
use ArrayAccess;
6
use Countable;
7
8
/**
9
 * Pool is a storage to store object identified by a string key
10
 */
11
class Pool implements ArrayAccess, Countable
12
{
13
14
    /**
15
     * connections
16
     *
17
     * @var array
18
     */
19
    private $connections = [];
20
21
    /**
22
     * Assigns a value to the specified offset
23
     *
24
     * @param string The offset to assign the value to
25
     * @param mixed  The value to set
0 ignored issues
show
Bug introduced by
The type App\Component\Db\The was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
     */
27 1
    public function offsetSet($connexionId, $connection)
28
    {
29 1
        if ($this->valid($connexionId, $connection)) {
30 1
            $this->connections[$connexionId] = $connection;
31
        }
32
    }
33
34
    /**
35
     * Whether or not an offset exists
36
     *
37
     * @param string An offset to check for
0 ignored issues
show
Bug introduced by
The type App\Component\Db\An was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
38
     * @return boolean
39
     */
40 1
    public function offsetExists($connexionId)
41
    {
42 1
        return isset($this->connections[$connexionId]);
43
    }
44
45
    /**
46
     * Unsets an offset
47
     *
48
     * @param string The offset to unset
49
     */
50 1
    public function offsetUnset($connexionId)
51
    {
52 1
        if ($this->offsetExists($connexionId)) {
53 1
            unset($this->connections[$connexionId]);
54
        }
55
    }
56
57
    /**
58
     * Returns the value at specified offset
59
     *
60
     * @param string The offset to retrieve
61
     * @return mixed
62
     */
63 1
    public function offsetGet($connexionId)
64
    {
65 1
        return $this->offsetExists($connexionId)
66 1
            ? $this->connections[$connexionId]
67 1
            : null;
68
    }
69
70
    /**
71
     * return number of connections
72
     *
73
     * @return integer
74
     */
75 1
    public function count()
76
    {
77 1
        return count($this->connections);
78
    }
79
80
    /**
81
     * return true id connectionId is not null and is string
82
     * and connection is object
83
     *
84
     * @param string $connexionId
85
     * @param object $connection
86
     * @return boolean
87
     */
88 23
    protected function valid($connexionId, $connection): bool
89
    {
90 23
        return (!is_null($connexionId)
91 23
            && is_string($connexionId)
92 23
            && is_object($connection));
93
    }
94
}
95