RestrictedLinkFactory::linkable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace LinkRestrictedAccess\Database\Factories;
4
5
use Carbon\Carbon;
6
use Illuminate\Database\Eloquent\Factories\Factory;
7
use Illuminate\Database\Eloquent\Model;
8
use LinkRestrictedAccess\Models\RestrictedLink;
9
10
class RestrictedLinkFactory extends Factory
11
{
12
    protected $model = RestrictedLink::class;
13
14
    public function definition(): array
15
    {
16
        return [
17
            'name'    => fake()->word(),
18
            'use_pin' => null,
19
            'pin'     => fake()->numberBetween(1000, 9999),
20
        ];
21
    }
22
23
    public function linkable(Model $linkable): static
24
    {
25
        return $this->state([
26
            'linkable_type' => $linkable->getMorphClass(),
27
            'linkable_id'   => $linkable->getKey(),
28
        ]);
29
    }
30
31
    public function usePin(string $pin): static
32
    {
33
        return $this->state([
34
            'use_pin' => Carbon::now(),
35
            'pin'     => $pin,
36
        ]);
37
    }
38
39
    public function useName(): static
40
    {
41
        return $this->state(function (array $attributes) {
42
            $accessConfiguration             = $attributes['access_configuration']??[];
43
            $accessConfiguration['use_name'] = Carbon::now();
44
45
            return [
46
                'access_configuration' => $accessConfiguration,
47
            ];
48
        });
49
    }
50
51
    public function useEmail(): static
52
    {
53
        return $this->state(function (array $attributes) {
54
            $accessConfiguration              = $attributes['access_configuration']??[];
55
            $accessConfiguration['use_email'] = Carbon::now();
56
57
            return [
58
                'access_configuration' => $accessConfiguration,
59
            ];
60
        });
61
    }
62
}
63