Completed
Push — master ( bd69b1...b47d34 )
by nicolas
05:24 queued 02:30
created

MysqliScriptCache::clearMessageData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Dekalee\AdbackAnalytics\Driver;
4
5
/**
6
 * Class MysqliScriptCache
7
 */
8
class MysqliScriptCache extends SqlScriptCache implements ScriptCacheInterface
9
{
10
    protected $connection;
11
12
    /**
13
     * @param mixed $connection Mysqli Connection
14
     */
15
    public function __construct($connection)
16
    {
17
        $this->connection = $connection;
18
    }
19
20
    /**
21
     * @param string $key
22
     *
23
     * @return string|null
24
     */
25
    protected function get($key)
26
    {
27
        $value = null;
28
        $request = $this->connection->prepare('SELECT our_value FROM adback_cache_table WHERE our_key = ? LIMIT 1');
29
        $request->bind_param('s', $key);
30
31
        $request->execute();
32
        $request->bind_result($value);
33
        $request->fetch();
34
        $request->free_result();
35
36
        return $value;
37
    }
38
39
    /**
40
     * @param string $key
41
     * @param string $value
42
     */
43 View Code Duplication
    protected function set($key, $value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
    {
45
        $this->clear($key);
46
        $request = $this->connection->prepare("INSERT INTO adback_cache_table (our_key, our_value) VALUES (?, ?)");
47
        $request->bind_param('ss', $key, $value);
48
        $request->execute();
49
    }
50
51
    /**
52
     * @param string $key
53
     */
54
    protected function clear($key)
55
    {
56
        $request = $this->connection->prepare("DELETE FROM adback_cache_table WHERE our_key = ?");
57
        $request->bind_param('s', $key);
58
        $request->execute();
59
    }
60
}
61