SQL::flush()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 10
rs 10
c 1
b 0
f 0
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