Passed
Push — master ( 4c5faf...429320 )
by Chris
04:23
created

SimpleFieldFactory::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 11
ccs 0
cts 9
cp 0
crap 6
rs 10
1
<?php
2
3
namespace WebTheory\Saveyour\Factories;
4
5
use WebTheory\Saveyour\Contracts\FieldDataManagerResolverFactoryInterface;
6
use WebTheory\Saveyour\Contracts\FormFieldResolverFactoryInterface;
7
use WebTheory\Saveyour\Factories\DataManagerFactory;
8
use WebTheory\Saveyour\Factories\FieldFactory;
9
use WebTheory\Saveyour\Factories\FormFieldFactory;
10
11
class SimpleFieldFactory extends FieldFactory
12
{
13
    /**
14
     *
15
     */
16
    public function __construct(array $options = [])
17
    {
18
        $field = $options['form_field_factory'] ?? [];
19
        $manager = $options['data_manager_factory'] ?? [];
20
        $controller = $options['controller'] ?? null;
21
22
        $this->formFieldFactory = $this->createFormFieldFactory($field);
23
        $this->dataManagerFactory = $this->createDataManagerFactory($manager);
24
25
        if (isset($controller)) {
26
            $this->controller = $controller;
27
        }
28
    }
29
30
    /**
31
     *
32
     */
33
    protected function createFormFieldFactory(array $options): FormFieldResolverFactoryInterface
34
    {
35
        $namespaces = $options['namespaces'] ?? [];
36
        $fields = $options['fields'] ?? [];
37
38
        return new FormFieldFactory($namespaces, $fields);
39
    }
40
41
    /**
42
     *
43
     */
44
    protected function createDataManagerFactory(array $options): FieldDataManagerResolverFactoryInterface
45
    {
46
        $namespaces = $options['namespaces'] ?? [];
47
        $managers = $options['managers'] ?? [];
48
49
        return new DataManagerFactory($namespaces, $managers);
50
    }
51
}
52