Completed
Push — master ( 219b40...a244a7 )
by Ryo
91:48 queued 48:36
created

DeliveryType::buildForm()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 75
Code Lines 56

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 30
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 56
nc 1
nop 2
dl 0
loc 75
ccs 30
cts 30
cp 1
crap 3
rs 9
c 0
b 0
f 0

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
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
25
namespace Eccube\Form\Type\Admin;
26
27
use Symfony\Component\Form\AbstractType;
28
use Symfony\Component\Form\Extension\Core\Type;
29
use Symfony\Component\Form\FormBuilderInterface;
30
use Symfony\Component\Form\FormError;
31
use Symfony\Component\Form\FormEvents;
32
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
33
use Symfony\Component\Validator\Constraints as Assert;
34
35
class DeliveryType extends AbstractType
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
36
{
37
    /**
38
     * {@inheritdoc}
39
     */
40 6
    public function buildForm(FormBuilderInterface $builder, array $options)
41
    {
42
        $builder
43 6
            ->add('name', 'text', array(
44 6
                'label' => '配送業者名',
45
                'required' => true,
46
                'constraints' => array(
47 6
                    new Assert\NotBlank,
0 ignored issues
show
introduced by
Use parentheses when instantiating classes
Loading history...
48
                ),
49
            ))
50 6
            ->add('service_name', 'text', array(
51 6
                'label' => '名称',
52
                'required' => true,
53
                'constraints' => array(
54 6
                    new Assert\NotBlank(),
55
                ),
56
            ))
57 6
            ->add('description', 'textarea', array(
58 6
                'label' => 'ショップ用メモ欄',
59
                'required' => false,
60
            ))
61 6
            ->add('confirm_url', 'text', array(
62 6
                'label' => '伝票No.URL',
63
                'required' => false,
64
                'constraints' => array(
65 6
                    new Assert\Url(),
66
                ),
67
            ))
68 6
            ->add('product_type', 'product_type', array(
69
                'constraints' => array(
70 6
                    new Assert\NotBlank(),
71
                ),
72
            ))
73
            ->add('payments', 'payment', array(
74 6
                'label' => '支払方法',
75 6
                'expanded' => true,
76 6
                'multiple' => true,
77 6
                'required' => false,
78
                'mapped' => false,
79
            ))
80
            ->add('delivery_times', 'collection', array(
81
                'label' => 'お届け時間',
82 6
                'required' => false,
83 6
                'type' => 'delivery_time',
84 6
                'allow_add' => true,
85
                'allow_delete' => true,
86
                'prototype' => true,
87 6
            ))
88 6
            ->add('free_all', 'price', array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
89
                'label' => false,
90
                'currency' => 'JPY',
91
                'precision' => 0,
92
                'scale' => 0,
93
                'grouping' => true,
94
                'required' => false,
95 6
                'mapped' => false
96 6
            ))
97
            ->add('delivery_fees', 'collection', array(
98
                'label' => '都道府県別設定',
99
                'required' => true,
100
                'type' => 'delivery_fee',
101
                'allow_add' => true,
102
                'allow_delete' => true,
103
                'prototype' => true,
104 6
            ))
105 6
            ->addEventListener(FormEvents::POST_SUBMIT, function($event) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
106
                $form = $event->getForm();
107
                $payments = $form['payments']->getData();
108
109
                if (empty($payments) || count($payments) < 1) {
110
                    $form['payments']->addError(new FormError('支払方法を選択してください。'));
111
                }
112 6
            })
113 4
        ;
114 4
    }
115
116 4
    /**
117
     * {@inheritdoc}
118
     */
119 6
    public function setDefaultOptions(OptionsResolverInterface $resolver)
120
    {
121
        $resolver->setDefaults(array(
122
            'data_class' => 'Eccube\Entity\Delivery',
123
        ));
124
    }
125
126 6
    /**
127
     * {@inheritdoc}
128 6
     */
129 6
    public function getName()
130
    {
131
        return 'delivery';
132
    }
133
}
134