CropInstanceType   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 73
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A setDefaultOptions() 0 9 1
B buildForm() 0 27 1
A buildView() 0 15 2
1
<?php
2
3
namespace Fenrizbes\CropBundle\Form\Type;
4
5
use Symfony\Component\Form\AbstractType;
6
use Symfony\Component\Form\FormBuilderInterface;
7
use Symfony\Component\Form\FormInterface;
8
use Symfony\Component\Form\FormView;
9
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
10
11
class CropInstanceType extends AbstractType
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    public function getName()
17
    {
18
        return 'crop_instance';
19
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function setDefaultOptions(OptionsResolverInterface $resolver)
25
    {
26
        $resolver
27
            ->setRequired(array(
28
                'width',
29
                'height'
30
            ))
31
        ;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function buildForm(FormBuilderInterface $builder, array $options)
38
    {
39
        $builder
40
            ->add('left', 'hidden', array(
41
                'attr' => array(
42
                    'class' => 'fenrizbes-crop-bundle-instance-left'
43
                )
44
            ))
45
            ->add('top', 'hidden', array(
46
                'attr' => array(
47
                    'class' => 'fenrizbes-crop-bundle-instance-top'
48
                )
49
            ))
50
            ->add('width', 'hidden', array(
51
                'attr' => array(
52
                    'class' => 'fenrizbes-crop-bundle-instance-width'
53
                )
54
            ))
55
            ->add('height', 'hidden', array(
56
                'attr' => array(
57
                    'class' => 'fenrizbes-crop-bundle-instance-height'
58
                )
59
            ))
60
            ->add('min_width', 'hidden')
61
            ->add('min_height', 'hidden')
62
        ;
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function buildView(FormView $view, FormInterface $form, array $options)
69
    {
70
        $data = $form->getData();
71
72
        if (empty($data)) {
73
            $form->setData(array(
74
                'left'       => 0,
75
                'top'        => 0,
76
                'width'      => $options['width'],
77
                'height'     => $options['height'],
78
                'min_width'  => $options['width'],
79
                'min_height' => $options['height']
80
            ));
81
        }
82
    }
83
}