Link   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A boot() 0 16 3
1
<?php
2
3
namespace App\Models;
4
5
use Illuminate\Database\Eloquent\Factories\HasFactory;
6
use Illuminate\Database\Eloquent\Model;
7
8
class Link extends Model
9
{
10
    use HasFactory;
11
12
    protected $fillable = ['link', 'title', 'button_id', 'type_params', 'type', 'custom_icon'];
13
14
    protected static function boot()
15
    {
16
        parent::boot();
17
18
        static::creating(function ($link) {
19
          if (config('linkstack.disable_random_link_ids') != 'true') {
20
            $numberOfDigits = config('linkstack.link_id_length') ?? 9;
21
22
            $minIdValue = 10**($numberOfDigits - 1);
23
            $maxIdValue = 10**$numberOfDigits - 1;
24
25
            do {
26
                $randomId = rand($minIdValue, $maxIdValue);
27
            } while (Link::find($randomId));
28
29
            $link->id = $randomId;
30
          }
31
        });
32
    }
33
}
34