FieldFactory   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 53
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
C create() 0 27 7
1
<?php namespace PascalKleindienst\FormListGenerator\Fields;
2
3
/**
4
 * Factory to create field classes
5
 * @package \PascalKleindienst\FormListGenerator\Fields
6
 */
7
class FieldFactory
8
{
9
    /**
10
     * Custom Field Types
11
     * @var array
12
     */
13
    public $customFields = [];
14
15
    /**
16
     * Set Custom fields
17
     *
18
     * @param array $fields
19
     */
20 33
    public function __construct(array $fields = [])
21
    {
22 33
        $this->customFields = $fields;
23 33
    }
24
25
    /**
26
     * Create new Field class.
27
     *
28
     * @param string $name
29
     * @param array $config
30
     * @return \PascalKleindienst\FormListGenerator\Data\Field
31
     */
32 27
    public function create($name, array $config)
33
    {
34 27
        $type = isset($config['type']) ? strtolower($config['type']) : 'text';
35 27
        $field = null;
0 ignored issues
show
Unused Code introduced by
$field is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
36
37
        switch ($type) {
38 27
            case 'radio':
39 27
            case 'checkboxlist':
40 3
                $field = new RadioCheckboxList($name, $config);
41 3
                break;
42 24
            case 'section':
43 24
            case 'partial':
44 3
                $field = new PartialHTMLField($name, $config);
45 3
                break;
46 21
            default:
47 21
                $field = new Field($name, $config);
48
49
                // Custom Field
50 21
                if (array_key_exists($type, $this->customFields)) {
51 3
                    $class = $this->customFields[$type];
52 3
                    $field = new $class($name, $config);
53 3
                }
54 21
        }
55
56 27
        $field->setup();
57 27
        return $field;
58
    }
59
}
60