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

FieldOptions   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 11.11 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 6
loc 54
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
B create() 6 26 2
A getSharedOptions() 0 4 1
A getFormOptions() 0 4 1
A getViewOptions() 0 4 1
A getStorageOptions() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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