FormEntryFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 19
c 0
b 0
f 0
dl 0
loc 53
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A definition() 0 10 1
A type() 0 4 1
A usingContent() 0 5 1
A notified() 0 4 1
A notNotified() 0 4 1
1
<?php
2
3
namespace FormEntries\Database\Factories;
4
5
use Carbon\Carbon;
6
use FormEntries\Forms\FormContent;
7
use FormEntries\Models\FormEntry;
8
use Illuminate\Database\Eloquent\Factories\Factory;
9
use Illuminate\Database\Eloquent\Model;
10
11
class FormEntryFactory extends Factory
12
{
13
    /**
14
     * The name of the factory's corresponding model.
15
     *
16
     * @var string
17
     */
18
    protected $model = FormEntry::class;
19
20
    /**
21
     * Define the model's default state.
22
     *
23
     * @return array
24
     */
25
    public function definition()
26
    {
27
        return [
28
            'type'         => 'default',
29
            'content_type' => null,
30
            'content'      => null,
31
            'notified_at'  => null,
32
            'sender_id'    => null,
33
            'sender_type'  => null,
34
            'meta'         => null,
35
        ];
36
    }
37
38
    public function type(?string $type): static
39
    {
40
        return $this->state([
41
            'type' => $type,
42
        ]);
43
    }
44
45
    public function notified(?\DateTimeInterface $dateTime): static
46
    {
47
        return $this->state([
48
            'notified_at' => $dateTime ?? Carbon::now(),
49
        ]);
50
    }
51
52
    public function notNotified(): static
53
    {
54
        return $this->state([
55
            'notified_at' => null,
56
        ]);
57
    }
58
59
    public function usingContent(FormContent $formContent): static
60
    {
61
        return $this->state([
62
            'content_type' => $formContent::getType(),
63
            'content'      => $formContent->toArray(),
64
        ]);
65
    }
66
}
67