AbstractAdapter   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 63
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getStorage() 0 8 2
A isSatisfied() 0 5 2
A setStorage() 0 5 1
A setSatisfied() 0 10 2
1
<?php
2
3
namespace ZfcUser\Authentication\Adapter;
4
5
use Zend\Authentication\Storage\StorageInterface;
6
use Zend\Authentication\Storage\Session as SessionStorage;
7
8
abstract class AbstractAdapter implements ChainableAdapter
9
{
10
    /**
11
     * @var StorageInterface
12
     */
13
    protected $storage;
14
15
    /**
16
     * Returns the persistent storage handler
17
     *
18
     * Session storage is used by default unless a different storage adapter has been set.
19
     *
20
     * @return StorageInterface
21
     */
22
    public function getStorage()
23
    {
24
        if (null === $this->storage) {
25
            $this->setStorage(new SessionStorage(get_class($this)));
26
        }
27
28
        return $this->storage;
29
    }
30
31
    /**
32
     * Sets the persistent storage handler
33
     *
34
     * @param  StorageInterface $storage
35
     * @return AbstractAdapter Provides a fluent interface
36
     */
37
    public function setStorage(StorageInterface $storage)
38
    {
39
        $this->storage = $storage;
40
        return $this;
41
    }
42
43
    /**
44
     * Check if this adapter is satisfied or not
45
     *
46
     * @return bool
47
     */
48
    public function isSatisfied()
49
    {
50
        $storage = $this->getStorage()->read();
51
        return (isset($storage['is_satisfied']) && true === $storage['is_satisfied']);
52
    }
53
54
    /**
55
     * Set if this adapter is satisfied or not
56
     *
57
     * @param bool $bool
58
     * @return AbstractAdapter
59
     */
60
    public function setSatisfied($bool = true)
61
    {
62
        $storage = $this->getStorage();
63
        $data    = $storage->read() ?: array();
64
65
        $data['is_satisfied'] = (bool) $bool;
66
        $storage->write($data);
67
68
        return $this;
69
    }
70
}
71