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

LoadProjectData   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A type() 0 4 1
A getOrder() 0 4 1
B load() 0 29 3
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\CreateProjectCommand;
20
use Kreta\TaskManager\Application\Query\Organization\FilterOrganizationsQuery;
21
22
class LoadProjectData extends AbstractFixture
23
{
24
    protected function type() : string
25
    {
26
        return 'project';
27
    }
28
29
    public function getOrder() : int
30
    {
31
        return 3;
32
    }
33
34
    public function load(ObjectManager $manager) : void
35
    {
36
        $i = 0;
37
        while ($i < $this->amount()) {
38
            $this->queryBus()->handle(
39
                new FilterOrganizationsQuery(
40
                    $this->getRandomUserByIndex($i),
41
                    0,
42
                    1
43
                ),
44
                $organizations
45
            );
46
47
            if (empty($organizations)) {
48
                ++$i;
49
                continue;
50
            }
51
52
            $this->commandBus()->handle(
53
                new CreateProjectCommand(
54
                    'Project ' . $i,
55
                    $organizations[0]['id'],
56
                    $organizations[0]['owners'][0]['id'],
57
                    $this->fakeIds()[$i]
58
                )
59
            );
60
            ++$i;
61
        }
62
    }
63
}
64