TStorage::isStored()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
nc 2
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 2
rs 10
c 1
b 0
f 0
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