Passed
Pull Request — master (#29)
by Stephen
03:27
created

TrackActionFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 7
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Database\Factories;
4
5
use Database\Factories\Traits\ModelChanges;
6
use Illuminate\Database\Eloquent\Factories\Factory;
7
use Illuminate\Support\Collection;
8
use Sfneal\Tracking\Utils\ModelAdapter;
9
10
class TrackActionFactory extends Factory
11
{
12
    use ModelChanges;
13
14
    /**
15
     * TrackActionFactory constructor.
16
     *
17
     * @param null $count
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $count is correct as it would always require null to be passed?
Loading history...
18
     * @param Collection|null $states
19
     * @param Collection|null $has
20
     * @param Collection|null $for
21
     * @param Collection|null $afterMaking
22
     * @param Collection|null $afterCreating
23
     * @param null $connection
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $connection is correct as it would always require null to be passed?
Loading history...
24
     */
25
    public function __construct($count = null,
26
                                ?Collection $states = null,
27
                                ?Collection $has = null,
28
                                ?Collection $for = null,
29
                                ?Collection $afterMaking = null,
30
                                ?Collection $afterCreating = null,
31
                                $connection = null)
32
    {
33
        $this->model = ModelAdapter::TrackAction();
34
        parent::__construct($count, $states, $has, $for, $afterMaking, $afterCreating, $connection);
35
    }
36
37
    /**
38
     * Define the model's default state.
39
     *
40
     * @return array
41
     */
42
    public function definition(): array
43
    {
44
        return [
45
            'action' => $this->faker->randomElement($this->randomAction()),
46
            'model_table' => $this->faker->randomElement(['people', 'address']),
47
            'model_key' => $this->faker->randomNumber(3),
48
            'model_changes' => $this->faker->randomElements($this->modelChanges()),
49
        ];
50
    }
51
52
    /**
53
     * Retrieve an array of 'actions' to be used as random elements.
54
     *
55
     * @return array
56
     */
57
    protected function randomAction(): array
58
    {
59
        return collect(['created', 'updated', 'deleted'])->each(function (string $action) {
60
            return ucfirst($action).' the model.';
61
        })->toArray();
62
    }
63
}
64