Completed
Push — develop ( 87538f...e43479 )
by Daniel
07:02
created

AbstractComponentFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 58.81%

Importance

Changes 0
Metric Value
dl 0
loc 49
ccs 10
cts 17
cp 0.5881
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 18 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
        'dynamicPageClass' => 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['dynamicPageClass']
36
        ) {
37
            $location = new ComponentLocation(null, $component);
38
            $location->setDynamicPageClass($this->ops['dynamicPageClass']);
39
            $component->addLocation($location);
40
            $this->manager->persist($location);
41
        }
42 22
    }
43
44 18
    protected static function getIgnoreOps(): array
45
    {
46
        return [
47 18
            'parentContent',
48
            'dynamicPageClass'
49
        ];
50
    }
51
52
    /**
53
     * @inheritdoc
54
     */
55 43
    protected static function defaultOps(): array
56
    {
57 43
        return self::COMPONENT_OPS;
58
    }
59
}
60