TrackActionFactory::__construct()   A
last analyzed

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
use Sfneal\Tracking\Utils\RandomTrackable;
10
11
class TrackActionFactory extends Factory
12
{
13
    use ModelChanges;
14
15
    /**
16
     * TrackActionFactory 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::TrackAction();
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
            'action' => $this->faker->randomElement($this->randomAction()),
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

48
            'action' => $this->faker->/** @scrutinizer ignore-call */ randomElement($this->randomAction()),

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...
49
            '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

49
            '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...
50
51
            'trackable_id' => $trackable->id,
52
            'trackable_type' => $trackable->type,
53
54
            'created_at' => $this->faker->date('Y-m-d H:i:s'),
55
        ];
56
    }
57
58
    /**
59
     * Retrieve an array of 'actions' to be used as random elements.
60
     *
61
     * @return array
62
     */
63
    protected function randomAction(): array
64
    {
65
        return collect(['created', 'updated', 'deleted'])->each(function (string $action) {
66
            return ucfirst($action).' the model.';
67
        })->toArray();
68
    }
69
}
70