TrackActivityFactory::definition()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 16
rs 9.9332
c 2
b 0
f 1
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
use Sfneal\Tracking\Utils\RandomTrackable;
10
11
class TrackActivityFactory extends Factory
12
{
13
    use ModelChanges;
14
15
    /**
16
     * TrackActivityFactory constructor.
17
     *
18
     * @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...
19
     * @param  Collection|null  $states
20
     * @param  Collection|null  $has
21
     * @param  Collection|null  $for
22
     * @param  Collection|null  $afterMaking
23
     * @param  Collection|null  $afterCreating
24
     * @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...
25
     */
26
    public function __construct($count = null,
27
                                ?Collection $states = null,
28
                                ?Collection $has = null,
29
                                ?Collection $for = null,
30
                                ?Collection $afterMaking = null,
31
                                ?Collection $afterCreating = null,
32
                                $connection = null)
33
    {
34
        $this->model = ModelAdapter::TrackActivity();
35
        parent::__construct($count, $states, $has, $for, $afterMaking, $afterCreating, $connection);
36
    }
37
38
    /**
39
     * Define the model's default state.
40
     *
41
     * @return array
42
     */
43
    public function definition(): array
44
    {
45
        $trackable = new RandomTrackable();
46
47
        return [
48
            'user_id' => $this->faker->randomNumber(3),
49
            'route' => $this->route(),
50
            'description' => $this->faker->text(),
51
52
            'model_changes' => $this->faker->randomElements($this->modelChanges()),
0 ignored issues
show
Bug introduced by
The call to Faker\Generator::randomElements() has too few arguments starting with 'b'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
            'model_changes' => $this->faker->/** @scrutinizer ignore-call */ randomElements($this->modelChanges()),

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
53
            'request_token' => $this->faker->uuid,
54
55
            'trackable_id' => $trackable->id,
56
            'trackable_type' => $trackable->type,
57
58
            'created_at' => $this->faker->date('Y-m-d H:i:s'),
59
        ];
60
    }
61
62
    /**
63
     * Retrieve an array of 'route' that can be used as random elements.
64
     *
65
     * @return string
66
     */
67
    protected function route(): string
68
    {
69
        $prefixes = ['projects', 'tasks', 'reports', 'client'];
70
        $actions = ['store', 'update',  'delete'];
71
72
        return $this->faker->randomElement($prefixes).'.'.$this->faker->randomElement($actions);
0 ignored issues
show
Bug introduced by
The call to Faker\Generator::randomElement() has too few arguments starting with 'b'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

72
        return $this->faker->/** @scrutinizer ignore-call */ randomElement($prefixes).'.'.$this->faker->randomElement($actions);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
73
    }
74
}
75