Passed
Push — develop ( 9486de...e25dc5 )
by Daniel
06:06
created

AbstractComponentFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 62.5%

Importance

Changes 0
Metric Value
dl 0
loc 48
ccs 10
cts 16
cp 0.625
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getIgnoreOps() 0 5 1
A defaultOps() 0 3 1
A init() 0 17 4
1
<?php
2
3
namespace Silverback\ApiComponentBundle\Factory\Entity\Content\Component;
4
5
use Silverback\ApiComponentBundle\Entity\Content\Component\AbstractComponent;
6
use Silverback\ApiComponentBundle\Entity\Content\Component\ComponentLocation;
7
use Silverback\ApiComponentBundle\Factory\Entity\AbstractFactory;
8
9
abstract class AbstractComponentFactory extends AbstractFactory
10
{
11
    public const COMPONENT_OPS = [
12
        'className' => null,
13
        'parentComponent' => null,
14
        'parentContent' => null,
15
        'componentGroup' => null,
16
        'dynamicPage' => null
17
    ];
18
19
    /**
20
     * @param AbstractComponent $component
21
     * @param array|null $ops
22
     */
23 22
    protected function init($component, ?array $ops = null): void
24
    {
25 22
        parent::init($component, $ops);
26
        if (
27 22
            $this->ops['parentContent'] &&
28 22
            !$component->hasParentContent($this->ops['parentContent'])
29
        ) {
30
            $location = new ComponentLocation($this->ops['parentContent'], $component);
31
            $component->addLocation($location);
32
            $this->manager->persist($location);
33
        }
34
        if (
35 22
            $this->ops['dynamicPage']
36
        ) {
37
            $location = new ComponentLocation(null, $component);
38
            $location->setDynamicPageClass($this->ops['dynamicPage']);
39
            $this->manager->persist($location);
40
        }
41 22
    }
42
43 18
    protected static function getIgnoreOps(): array
44
    {
45
        return [
46 18
            'parentContent',
47
            'dynamicPage'
48
        ];
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54 43
    protected static function defaultOps(): array
55
    {
56 43
        return self::COMPONENT_OPS;
57
    }
58
}
59