Completed
Pull Request — master (#172)
by Gorka
05:15
created

OrganizationFixturesCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 7
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 4 1
B execute() 0 26 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
namespace Kreta\AppBundle\Command;
14
15
use Kreta\SharedKernel\Domain\Model\Identity\Slug;
16
use Kreta\TaskManager\Domain\Model\Organization\Organization;
17
use Kreta\TaskManager\Domain\Model\Organization\OrganizationId;
18
use Kreta\TaskManager\Domain\Model\Organization\OrganizationName;
19
use Kreta\TaskManager\Domain\Model\User\User;
20
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
21
use Symfony\Component\Console\Input\InputInterface;
22
use Symfony\Component\Console\Output\OutputInterface;
23
24
class OrganizationFixturesCommand extends ContainerAwareCommand
25
{
26
    protected function configure()
27
    {
28
        $this->setName('fixtures:organization');
29
    }
30
31
    protected function execute(InputInterface $input, OutputInterface $output)
32
    {
33
        $manager = $this->getContainer()->get('doctrine.orm.entity_manager');
34
35
        $users = $this->getContainer()->get('doctrine')->getRepository(User::class)->findAll();
36
37
        $organizationId = OrganizationId::generate();
38
        $organization = new Organization(
39
            $organizationId,
40
            new OrganizationName('Organization name'),
41
            new Slug('Organization name'),
42
            $users[0]->id()
43
        );
44
45
        $i = 0;
46
        foreach ($users as $user) {
47
            if ($i > 0) {
48
                $organization->addOrganizationMember($user->id());
49
            }
50
            ++$i;
51
        }
52
53
        $manager->persist($organization);
54
        $manager->flush();
55
        $output->writeln('Population is successfully done');
56
    }
57
}
58