DatabaseStorage::put()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 9.536
c 0
b 0
f 0
cc 3
nc 4
nop 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