AbstractAdapter::getStorage()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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