Completed
Push — master ( 98a062...441031 )
by Ryan
10:10
created

AssignmentFormFields::handle()   B

Complexity

Conditions 4
Paths 1

Size

Total Lines 60
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

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