DatabaseStorage   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 2
dl 0
loc 58
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A put() 0 24 3
A get() 0 7 1
A forget() 0 6 2
1
<?php
2
3
namespace Infinitypaul\MultiStep\Store;
4
5
use Illuminate\Support\Arr;
6
use Infinitypaul\MultiStep\Models\Step;
7
use Infinitypaul\MultiStep\Store\Contracts\StepStorage;
8
9
/**
10
 * @method string completed()
11
 */
12
class DatabaseStorage implements StepStorage
13
{
14
    protected $step;
15
16
    public function __construct()
17
    {
18
        $this->step = new Step();
19
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function put($key, $value)
25
    {
26
        $me = [];
27
28
        if (! is_array($key)) {
29
            $key = [$key => $value];
30
        }
31
32
        foreach ($key as $arrayKey => $arrayValue) {
33
            Arr::set($me, $arrayKey, $arrayValue);
34
        }
35
36
        var_dump($me);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($me); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
37
38
//        $this->step->data = json_encode($me);
39
//        $this->step->save();
40
41
//        $this->step->updateOrCreate(
42
//            ['slug' => session()->get('step_key')],
43
//            ['data' => json_encode($me), 'key' => $key]
44
//        );
45
46
        //dd(Arr::get($me, $key));
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function get($key)
53
    {
54
        $keys = explode('.', $key);
55
        $data = $this->step->where('slug', session()->get('step_key'))->first();
56
57
        return $data->data[end($keys)] ?? null;
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function forget($key)
64
    {
65
        if ($this->step->where('key', $key)->delete()) {
66
            session()->forget('step_key');
67
        }
68
    }
69
}
70