Completed
Push — master ( 7eb0de...709b6c )
by Ryan
07:32
created

AssignmentFormFields::handle()   B

Complexity

Conditions 4
Paths 1

Size

Total Lines 60
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 60
rs 8.9618
cc 4
eloc 39
nc 1
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php namespace Anomaly\Streams\Platform\Assignment\Form;
2
3
/**
4
 * Class AssignmentFormFields
5
 *
6
 * @link          http://anomaly.is/streams-platform
7
 * @author        AnomalyLabs, Inc. <[email protected]>
8
 * @author        Ryan Thompson <[email protected]>
9
 * @package       Anomaly\Streams\Platform\Assignment\Form
10
 */
11
class AssignmentFormFields
12
{
13
14
    /**
15
     * Handle the form fields.
16
     *
17
     * @param AssignmentFormBuilder $builder
18
     */
19
    public function handle(AssignmentFormBuilder $builder)
20
    {
21
        $builder->setFields(
22
            [
23
                'label'        => [
24
                    'label'        => 'streams::assignment.label.name',
25
                    'instructions' => 'streams::assignment.label.instructions',
26
                    'type'         => 'anomaly.field_type.text'
27
                ],
28
                'placeholder'  => [
29
                    'label'        => 'streams::assignment.placeholder.name',
30
                    'instructions' => 'streams::assignment.placeholder.instructions',
31
                    'type'         => 'anomaly.field_type.text'
32
                ],
33
                'instructions' => [
34
                    'label'        => 'streams::assignment.instructions.name',
35
                    'instructions' => 'streams::assignment.instructions.instructions',
36
                    'type'         => 'anomaly.field_type.textarea'
37
                ],
38
                'warning'      => [
39
                    'label'        => 'streams::assignment.warning.name',
40
                    'instructions' => 'streams::assignment.warning.instructions',
41
                    'type'         => 'anomaly.field_type.text'
42
                ],
43
                'required'     => [
44
                    'label'        => 'streams::assignment.required.label',
45
                    'instructions' => 'streams::assignment.required.instructions',
46
                    'type'         => 'anomaly.field_type.boolean'
47
                ],
48
                'unique'       => [
49
                    'label'        => 'streams::assignment.unique.label',
50
                    'instructions' => 'streams::assignment.unique.instructions',
51
                    'type'         => 'anomaly.field_type.boolean'
52
                ],
53
                'translatable' => [
54
                    'label'        => 'streams::assignment.translatable.label',
55
                    'instructions' => 'streams::assignment.translatable.instructions',
56
                    'type'         => 'anomaly.field_type.boolean',
57
                    'warning'      => function (AssignmentFormBuilder $builder) {
58
59
                        $type = $builder->getFieldType();
60
61
                        return $type->getColumnType() == null ? 'streams::assignment.translatable.warning' : null;
62
                    },
63
                    'disabled'     => function (AssignmentFormBuilder $builder) {
64
65
                        $stream = $builder->getStream();
66
67
                        if ($stream && !$stream->isTranslatable()) {
68
                            return true;
69
                        }
70
71
                        $type = $builder->getFieldType();
72
73
                        return $type->getColumnType() == null;
74
                    }
75
                ]
76
            ]
77
        );
78
    }
79
}
80