SortableDecorator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 38
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A sort() 0 4 1
A set() 0 5 1
A keys() 0 10 2
1
<?php
2
3
/*
4
 * This file is part of the webmozart/key-value-store package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Webmozart\KeyValueStore\Decorator;
13
14
use Webmozart\KeyValueStore\Api\SortableStore;
15
16
/**
17
 * A sortable decorator implementing a sort system for any store.
18
 *
19
 * @since  1.0
20
 *
21
 * @author Bernhard Schussek <[email protected]>
22
 * @author Titouan Galopin <[email protected]>
23
 */
24
class SortableDecorator extends AbstractDecorator implements SortableStore
25
{
26
    /**
27
     * @var int
28
     */
29
    private $flags;
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 6
    public function sort($flags = SORT_REGULAR)
35
    {
36 6
        $this->flags = $flags;
37 6
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 7
    public function set($key, $value)
43
    {
44 7
        $this->flags = null;
45 7
        $this->store->set($key, $value);
46 7
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 7
    public function keys()
52
    {
53 7
        $keys = $this->store->keys();
54
55 7
        if (null !== $this->flags) {
56 6
            sort($keys, $this->flags);
57
        }
58
59 7
        return $keys;
60
    }
61
}
62