SharedMemoryAdapter::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 3
eloc 8
nc 3
nop 2
1
<?php namespace AdammBalogh\KeyValueStore\Adapter;
2
3
use AdammBalogh\KeyValueStore\Adapter\SharedMemoryAdapter\ShmProxy;
4
use AdammBalogh\KeyValueStore\Adapter\SharedMemoryAdapter\KeyTrait;
5
use AdammBalogh\KeyValueStore\Adapter\SharedMemoryAdapter\ValueTrait;
6
use AdammBalogh\KeyValueStore\Adapter\SharedMemoryAdapter\ServerTrait;
7
8
class SharedMemoryAdapter extends AbstractAdapter
9
{
10
    use KeyTrait, ValueTrait, ServerTrait;
11
12
    /**
13
     * @var resource
14
     */
15
    protected $client;
16
17
    /**
18
     * @var ShmProxy
19
     */
20
    protected $shmProxy;
21
22
    /**
23
     * @param resource $client
24
     * @param ShmProxy $shmProxy
25
     *
26
     * @throws \InvalidArgumentException
27
     */
28
    public function __construct($client, ShmProxy $shmProxy = null)
29
    {
30
        if (!is_resource($client)) {
31
            throw new \InvalidArgumentException();
32
        }
33
34
        if (is_null($shmProxy)) {
35
            $this->shmProxy = new ShmProxy();
36
        } else {
37
            $this->shmProxy = $shmProxy;
38
        }
39
40
        $this->client = $client;
41
    }
42
43
    /**
44
     * @return resource
45
     */
46
    public function getClient()
47
    {
48
        return $this->client;
49
    }
50
}
51