Passed
Push — develop ( 83a19a...5dcd0c )
by Daniel
05:43
created

AbstractComponentFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
dl 0
loc 35
ccs 9
cts 12
cp 0.75
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getIgnoreOps() 0 4 1
A defaultOps() 0 6 1
A init() 0 10 3
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
    /**
12
     * @param AbstractComponent $component
13
     * @param array|null $ops
14
     */
15 22
    protected function init($component, ?array $ops = null): void
16
    {
17 22
        parent::init($component, $ops);
18
        if (
19 22
            $this->ops['parentContent'] &&
20 22
            !$component->isContentComponent($this->ops['parentContent'])
21
        ) {
22
            $location = new ComponentLocation($this->ops['parentContent'], $component);
23
            $component->addLocation($location);
24
            $this->manager->persist($location);
25
        }
26 22
    }
27
28 18
    protected static function getIgnoreOps(): array
29
    {
30
        return [
31 18
            'parentContent'
32
        ];
33
    }
34
35
    /**
36
     * @inheritdoc
37
     */
38 43
    protected static function defaultOps(): array
39
    {
40
        return [
41 43
            'className' => null,
42
            'parentComponent' => null,
43
            'parentContent' => null
44
        ];
45
    }
46
}
47