Completed
Push — master ( ff3370...c7a062 )
by Beñat
38s queued 33s
created

LoadTaskData   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 5
dl 0
loc 61
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A type() 0 4 1
A getOrder() 0 4 1
B load() 0 39 3
A taskPriority() 0 6 2
1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace Kreta\TaskManager\Infrastructure\Persistence\Doctrine\DataFixtures;
16
17
use Doctrine\Common\Persistence\ObjectManager;
18
use Kreta\SharedKernel\Infrastructure\Persistence\Doctrine\DataFixtures\AbstractFixture;
19
use Kreta\TaskManager\Application\Command\Project\Task\CreateTaskCommand;
20
use Kreta\TaskManager\Application\Query\Organization\OrganizationOfIdQuery;
21
use Kreta\TaskManager\Application\Query\Project\FilterProjectsQuery;
22
use Kreta\TaskManager\Domain\Model\Project\Task\TaskPriority;
23
24
class LoadTaskData extends AbstractFixture
25
{
26
    const TASK_PRIORITIES = [TaskPriority::LOW, TaskPriority::MEDIUM, TaskPriority::HIGH];
27
28
    protected function type() : string
29
    {
30
        return 'task';
31
    }
32
33
    public function getOrder() : int
34
    {
35
        return 4;
36
    }
37
38
    public function load(ObjectManager $manager) : void
39
    {
40
        $i = 0;
41
        while ($i < $this->amount()) {
42
            $userId = $this->getRandomUserByIndex($i);
43
44
            $this->queryBus()->handle(
45
                new FilterProjectsQuery(
46
                    $userId,
47
                    0,
48
                    1
49
                ),
50
                $projects
51
            );
52
53
            foreach ($projects as $project) {
54
                $this->queryBus()->handle(
55
                    new OrganizationOfIdQuery(
56
                        $project['organization_id'],
57
                        $userId
58
                    ),
59
                    $organization
60
                );
61
                $this->commandBus()->handle(
62
                    new CreateTaskCommand(
63
                        'Task ' . $i,
64
                        'The description of the task ' . $i,
65
                        $userId,
66
                        $organization['owners'][0]['id'],
67
                        $this->taskPriority($i),
68
                        $project['id'],
69
                        null,
70
                        $this->fakeIds()[$i]
71
                    )
72
                );
73
                ++$i;
74
            }
75
        }
76
    }
77
78
    private function taskPriority($index)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
79
    {
80
        $priorityIndex = $index % 2 > 3 ? 0 : 2 - $index % 3;
81
82
        return self::TASK_PRIORITIES[$priorityIndex];
83
    }
84
}
85