StorageTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 30
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setStorageKey() 0 4 1
A setStorage() 0 4 1
A getStorage() 0 4 1
A load() 0 4 1
A save() 0 4 1
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
}