SQL   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 36
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A flush() 0 10 1
1
<?php
2
3
namespace MatthiasMullie\Scrapbook\Adapters\Collections;
4
5
use MatthiasMullie\Scrapbook\Adapters\Collections\Utils\PrefixKeys;
6
use MatthiasMullie\Scrapbook\Adapters\SQL as Adapter;
7
8
/**
9
 * SQL adapter for a subset of data, accomplished by prefixing keys.
10
 *
11
 * @author Matthias Mullie <[email protected]>
12
 * @copyright Copyright (c) 2014, Matthias Mullie. All rights reserved
13
 * @license LICENSE MIT
14
 */
15
class SQL extends PrefixKeys
16
{
17
    /**
18
     * @var \PDO
19
     */
20
    protected $client;
21
22
    /**
23
     * @var string
24
     */
25
    protected $table;
26
27
    /**
28
     * @param string $table
29
     * @param string $name
30
     */
31
    public function __construct(Adapter $cache, \PDO $client, $table, $name)
32
    {
33
        parent::__construct($cache, 'collection:'.$name.':');
34
        $this->client = $client;
35
        $this->table = $table;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function flush()
42
    {
43
        // deleting key with a prefixed LIKE should be fast, they're indexed
44
        $statement = $this->client->prepare(
45
            "DELETE FROM $this->table
46
            WHERE k LIKE :key"
47
        );
48
49
        return $statement->execute(array(
50
            ':key' => $this->prefix.'%',
51
        ));
52
    }
53
}
54