Step   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 31
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A booted() 0 7 1
A getHashedKeys() 0 8 2
1
<?php
2
3
namespace Infinitypaul\MultiStep\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Infinitypaul\MultiStep\Controller\Keys;
7
8
class Step extends Model
9
{
10
    protected $guarded = ['id'];
11
12
    protected $casts = [
13
        'data' => 'array',
14
    ];
15
16
    public function __construct(array $attributes = [])
17
    {
18
        parent::__construct($attributes);
19
        $this->setTable(config('steps.table_names'));
20
    }
21
22
    protected static function booted()
23
    {
24
        static::creating(function ($step) {
25
            self::getHashedKeys();
26
            $step->slug = session()->get('step_key');
27
        });
28
    }
29
30
    protected static function getHashedKeys()
31
    {
32
        $key = Keys::getHashedToken();
33
        while (self::where('slug', $key)->exists()) {
34
            $key = Keys::getHashedToken();
35
        }
36
        session(['step_key' => $key]);
37
    }
38
}
39