Completed
Pull Request — master (#163)
by Beñat
05:43
created

OrganizationFixturesCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 9

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 9
dl 0
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 4 1
A execute() 0 22 1
1
<?php
2
3
namespace Kreta\AppBundle\Command;
4
5
use Kreta\SharedKernel\Domain\Model\Identity\Slug;
6
use Kreta\TaskManager\Domain\Model\Organization\Organization;
7
use Kreta\TaskManager\Domain\Model\Organization\OrganizationId;
8
use Kreta\TaskManager\Domain\Model\Organization\OrganizationName;
9
use Kreta\TaskManager\Domain\Model\Organization\Owner;
10
use Kreta\TaskManager\Domain\Model\Organization\OwnerId;
11
use Kreta\TaskManager\Domain\Model\User\User;
12
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Output\OutputInterface;
15
16
class OrganizationFixturesCommand extends ContainerAwareCommand
17
{
18
    protected function configure()
19
    {
20
        $this->setName('fixtures.organization');
21
    }
22
23
    protected function execute(InputInterface $input, OutputInterface $output)
24
    {
25
        $manager = $this->getContainer()->get('doctrine.orm.entity_manager');
26
27
        $users = $this->getContainer()->get('doctrine')->getRepository(User::class)->findAll();
28
29
        $organizationId = OrganizationId::generate();
30
        $organization = new Organization(
31
            $organizationId,
32
            new OrganizationName('Organization name'),
33
            new Slug('Organization name'),
34
            new Owner(
35
                OwnerId::generate(
36
                    $users[0]->id(),
37
                    $organizationId
38
                )
39
            )
40
        );
41
        $manager->persist($organization);
42
        $manager->flush();
43
        $output->writeln('Population is successfully done');
44
    }
45
}
46