StorageTrait::getStorage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Nopolabs\Yabot\Helpers;
4
5
6
use Nopolabs\Yabot\Storage\StorageInterface;
7
8
trait StorageTrait
9
{
10
    private $storage;
11
    private $storageKey;
12
13
    protected function setStorageKey($key)
14
    {
15
        $this->storageKey = str_replace('\\', '_', static::class).'.'.$key;
16
    }
17
18
    protected function setStorage(StorageInterface $storage)
19
    {
20
        $this->storage = $storage;
21
    }
22
23
    protected function getStorage() : StorageInterface
24
    {
25
        return $this->storage;
26
    }
27
28
    protected function load()
29
    {
30
        return $this->getStorage()->get($this->storageKey);
31
    }
32
33
    protected function save($data)
34
    {
35
        $this->getStorage()->save($this->storageKey, $data);
36
    }
37
}