DurationType::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @author Rafał Muszyński <[email protected]>
5
 * @copyright 2015 Sourcefabric z.ú.
6
 * @license http://www.gnu.org/licenses/gpl-3.0.txt
7
 */
8
namespace Newscoop\PaywallBundle\Form\Type;
9
10
use Symfony\Component\Form\AbstractType;
11
use Symfony\Component\Form\FormBuilderInterface;
12
use Symfony\Component\Validator\Constraints as Assert;
13
14
class DurationType extends AbstractType
15
{
16
    public function buildForm(FormBuilderInterface $builder, array $options)
17
    {
18
        $builder
19
        ->add('value', 'integer', array(
20
            'constraints' => array(
21
                new Assert\NotBlank(array(
22
                    'message' => 'paywall.errors.period.blank',
23
                )),
24
                new Assert\Range(array(
25
                    'min' => 1,
26
                    'max' => 9999,
27
                    'minMessage' => 'paywall.errors.period.max',
28
                    'maxMessage' => 'paywall.errors.period.min',
29
                )),
30
            ),
31
            'required' => true,
32
        ))
33
        ->add('attribute', 'choice', array(
34
            'label' => 'paywall.step1.form.label.duration',
35
            'error_bubbling' => true,
36
            'invalid_message' => 'paywall.step1.form.error.duration',
37
            'choices' => array(
38
                'month' => 'paywall.label.months',
39
                'day' => 'paywall.label.days',
40
            ),
41
            'required' => true,
42
        ))
43
        ->add('discount', 'entity', array(
44
            'label' => 'Discount',
45
            'empty_value' => 'Choose a discount',
46
            'property' => 'name',
47
            'class' => 'NewscoopPaywallBundle:Discount',
48
            'required' => false,
49
        ));
50
    }
51
52
    public function getName()
53
    {
54
        return 'durationForm';
55
    }
56
}
57