Completed
Push — master ( 96d434...f2324b )
by Daniel
04:52 queued 55s
created

FieldOptions::create()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 17

Duplication

Lines 6
Ratio 23.08 %

Importance

Changes 0
Metric Value
dl 6
loc 26
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 17
nc 2
nop 1
1
<?php
2
3
namespace Psi\Component\ContentType;
4
5
final class FieldOptions
6
{
7
    private $sharedOptions;
8
    private $formOptions;
9
    private $viewOptions;
10
    private $storageOptions;
11
12
    public static function create(array $options)
13
    {
14
        $defaults = [
15
            'shared' => [],
16
            'form' => [],
17
            'view' => [],
18
            'storage' => [],
19
        ];
20
21 View Code Duplication
        if ($diff = array_diff(array_keys($options), array_keys($defaults))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
            throw new \InvalidArgumentException(sprintf(
23
                'Unexpected field option keys: "%s". Allowed keys: "%s"',
24
                implode('", "', $diff), implode('", "', array_keys($defaults))
25
            ));
26
        }
27
28
        $options = array_merge($defaults, $options);
29
30
        $instance = new self();
31
        $instance->sharedOptions = $options['shared'];
32
        $instance->formOptions = $options['form'];
33
        $instance->viewOptions = $options['view'];
34
        $instance->storageOptions = $options['storage'];
35
36
        return $instance;
37
    }
38
39
    public function getSharedOptions()
40
    {
41
        return $this->sharedOptions;
42
    }
43
44
    public function getFormOptions()
45
    {
46
        return $this->formOptions;
47
    }
48
49
    public function getViewOptions()
50
    {
51
        return $this->viewOptions;
52
    }
53
54
    public function getStorageOptions()
55
    {
56
        return $this->storageOptions;
57
    }
58
}
59