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

TrackActivityFactory::__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 TrackActivityFactory extends Factory
11
{
12
    use ModelChanges;
13
14
    /**
15
     * TrackActivityFactory 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::TrackActivity();
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
            'user_id' => $this->faker->randomNumber(3),
46
            'route' => $this->route(),
47
            'description' => $this->faker->text(),
48
49
            'model_table' => $this->faker->randomElement(['people', 'address']),
50
            'model_key' => $this->faker->randomNumber(3),
51
            'model_changes' => $this->faker->randomElements($this->modelChanges()),
52
53
            'request_token' => $this->faker->uuid,
54
        ];
55
    }
56
57
    /**
58
     * Retrieve an array of 'route' that can be used as random elements.
59
     *
60
     * @return string
61
     */
62
    protected function route(): string
63
    {
64
        $prefixes = ['projects', 'tasks', 'reports', 'client'];
65
        $actions = ['store', 'update',  'delete'];
66
67
        return $this->faker->randomElement($prefixes).'.'.$this->faker->randomElement($actions);
68
    }
69
}
70