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

AbstractComponentFactory::init()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.7085

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 2
nop 2
dl 0
loc 10
ccs 4
cts 7
cp 0.5714
crap 3.7085
rs 9.4285
c 0
b 0
f 0
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