Passed
Push — develop ( dbd842...b818d1 )
by
unknown
02:41
created

ConfigInitializer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A initialize() 0 15 2
1
<?php
2
3
namespace AppBundle\Tenant\Initializer;
4
5
use Ds\Component\Config\Service\ConfigService;
6
use Ds\Component\Tenant\Initializer\Initializer;
7
8
/**
9
 * Class ConfigInitializer
10
 */
11
class ConfigInitializer implements Initializer
12
{
13
    /**
14
     * @var \Ds\Component\Config\Service\ConfigService
15
     */
16
    protected $configService;
17
18
    /**
19
     * Constructor
20
     *
21
     * @param \Ds\Component\Config\Service\ConfigService $configService
22
     */
23
    public function __construct(ConfigService $configService)
24
    {
25
        $this->configService = $configService;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function initialize(array $data)
32
    {
33
        $items = [];
34
        $manager = $this->configService->getManager();
35
36
        foreach ($items as $item) {
37
            $config = $this->configService->createInstance();
38
            $config
39
                ->setOwner('BusinessUnit')
40
                ->setOwnerUuid($data['business_unit']['administration']['uuid'])
41
                ->setKey($item['key'])
42
                ->setValue($item['value'])
43
                ->setTenant($data['tenant']['uuid']);
44
            $manager->persist($config);
45
            $manager->flush();
46
        }
47
    }
48
}
49