ZendSession   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 90
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A has() 0 4 1
A get() 0 8 2
A set() 0 4 1
A all() 0 4 1
A remove() 0 12 2
A clear() 0 8 1
1
<?php
2
/**
3
 * This file is part of phpab/phpab. (https://github.com/phpab/phpab)
4
 *
5
 * @link https://github.com/phpab/phpab for the canonical source repository
6
 * @copyright Copyright (c) 2015-2016 phpab. (https://github.com/phpab/)
7
 * @license https://raw.githubusercontent.com/phpab/phpab/master/LICENSE.md MIT
8
 */
9
10
namespace PhpAb\Storage\Adapter;
11
12
use Zend\Session\Container;
13
14
/**
15
 * An adapter that makes use of zendframework/zend-session.
16
 *
17
 * @package PhpAb
18
 */
19
class ZendSession implements AdapterInterface
20
{
21
    /**
22
     * @var Container The session container used to store data.
23
     */
24
    private $container;
25
26
    /**
27
     * Initializes a new instance of this class.
28
     *
29
     * @param Container $container The container used to store data.
30
     */
31
    public function __construct(Container $container)
32
    {
33
        $this->container = $container;
34
    }
35
36
    /**
37
     * {@inheritDoc}
38
     *
39
     * @param string $identifier The tests identifier
40
     */
41
    public function has($identifier)
42
    {
43
        return $this->container->offsetExists($identifier);
44
    }
45
46
    /**
47
     * {@inheritDoc}
48
     *
49
     * @param string $identifier The tests identifier name
50
     */
51
    public function get($identifier)
52
    {
53
        if (!$this->has($identifier)) {
54
            return null;
55
        }
56
57
        return $this->container[$identifier];
58
    }
59
60
    /**
61
     * {@inheritDoc}
62
     *
63
     * @param string $identifier The tests identifier
64
     * @param mixed  $participation The participated variant
65
     */
66
    public function set($identifier, $participation)
67
    {
68
        $this->container[$identifier] = $participation;
69
    }
70
71
    /**
72
     * {@inheritDoc}
73
     */
74
    public function all()
75
    {
76
        return $this->container->getArrayCopy();
77
    }
78
79
    /**
80
     * {@inheritDoc}
81
     *
82
     * @param string $identifier The identifier of the test to remove.
83
     */
84
    public function remove($identifier)
85
    {
86
        if (!$this->has($identifier)) {
87
            return null;
88
        }
89
90
        $removedValue = $this->container[$identifier];
91
92
        unset($this->container[$identifier]);
93
94
        return $removedValue;
95
    }
96
97
    /**
98
     * {@inheritDoc}
99
     */
100
    public function clear()
101
    {
102
        $removedValues = $this->all();
103
104
        $this->container->getManager()->getStorage()->clear($this->container->getName());
105
106
        return $removedValues;
107
    }
108
}
109