TStorage   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 33
ccs 10
cts 10
cp 1
rs 10
c 1
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isStored() 0 3 2
A deleteStored() 0 4 2
A setStorage() 0 5 1
1
<?php
2
3
namespace kalanis\kw_forms\Cache;
4
5
6
use kalanis\kw_storage\Interfaces\ITarget;
7
use kalanis\kw_storage\StorageException;
8
9
10
trait TStorage
11
{
12
    protected ?Storage $storage = null;
13
14 2
    public function setStorage(?ITarget $storage = null): self
15
    {
16 2
        $this->storage = new Storage($storage);
17 2
        $this->storage->setAlias(strval($this->getAlias()));
18 2
        return $this;
19
    }
20
21
    /**
22
     * Check if data is set inside storage
23
     * @throws StorageException
24
     * @return bool
25
     */
26 1
    public function isStored(): bool
27
    {
28 1
        return $this->storage ? $this->storage->isStored() : false ;
29
    }
30
31
    /**
32
     * Delete form data in storage
33
     * @throws StorageException
34
     */
35 1
    public function deleteStored(): void
36
    {
37 1
        if ($this->storage) {
38 1
            $this->storage->delete();
39
        }
40 1
    }
41
42
    abstract public function getAlias(): ?string;
43
}
44