浏览代码

[Form] CS related changes

Victor Berchet 14 年之前
父节点
当前提交
42698608cb

+ 13 - 11
src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php

@@ -32,8 +32,10 @@ class EntityType extends AbstractType
     public function buildForm(FormBuilder $builder, array $options)
     {
         if ($options['multiple']) {
-            $builder->addEventSubscriber(new MergeCollectionListener())
-                ->prependClientTransformer(new EntitiesToArrayTransformer($options['choice_list']));
+            $builder
+                ->addEventSubscriber(new MergeCollectionListener())
+                ->prependClientTransformer(new EntitiesToArrayTransformer($options['choice_list']))
+            ;
         } else {
             $builder->prependClientTransformer(new EntityToIdTransformer($options['choice_list']));
         }
@@ -42,16 +44,16 @@ class EntityType extends AbstractType
     public function getDefaultOptions(array $options)
     {
         $defaultOptions = array(
-            'multiple' => false,
-            'expanded' => false,
-            'em' => $this->em,
-            'class' => null,
-            'property' => null,
-            'query_builder' => null,
-            'choices' => array(),
+            'multiple'          => false,
+            'expanded'          => false,
+            'em'                => $this->em,
+            'class'             => null,
+            'property'          => null,
+            'query_builder'     => null,
+            'choices'           => array(),
             'preferred_choices' => array(),
-            'multiple' => false,
-            'expanded' => false,
+            'multiple'          => false,
+            'expanded'          => false,
         );
 
         $options = array_replace($defaultOptions, $options);

+ 4 - 2
src/Symfony/Component/Form/Extension/Core/Type/CheckboxType.php

@@ -21,8 +21,10 @@ class CheckboxType extends AbstractType
 {
     public function buildForm(FormBuilder $builder, array $options)
     {
-        $builder->appendClientTransformer(new BooleanToStringTransformer())
-            ->setAttribute('value', $options['value']);
+        $builder
+            ->appendClientTransformer(new BooleanToStringTransformer())
+            ->setAttribute('value', $options['value'])
+        ;
     }
 
     public function buildView(FormView $view, FormInterface $form)

+ 20 - 16
src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

@@ -46,15 +46,15 @@ class ChoiceType extends AbstractType
 
             foreach ($options['choices'] as $choice => $value) {
                 if ($options['multiple']) {
-                    $builder->add((string)$choice, 'checkbox', array(
-                        'value' => $choice,
-                        'label' => $value,
+                    $builder->add((string) $choice, 'checkbox', array(
+                        'value'     => $choice,
+                        'label'     => $value,
                         // The user can check 0 or more checkboxes. If required
                         // is true, he is required to check all of them.
-                        'required' => false,
+                        'required'  => false,
                     ));
                 } else {
-                    $builder->add((string)$choice, 'radio', array(
+                    $builder->add((string) $choice, 'radio', array(
                         'value' => $choice,
                         'label' => $value,
                     ));
@@ -62,17 +62,21 @@ class ChoiceType extends AbstractType
             }
         }
 
-        $builder->setAttribute('choice_list', $options['choice_list'])
+        $builder
+            ->setAttribute('choice_list', $options['choice_list'])
             ->setAttribute('preferred_choices', $options['preferred_choices'])
             ->setAttribute('multiple', $options['multiple'])
-            ->setAttribute('expanded', $options['expanded']);
+            ->setAttribute('expanded', $options['expanded'])
+        ;
 
         if ($options['expanded']) {
             if ($options['multiple']) {
                 $builder->appendClientTransformer(new ArrayToBooleanChoicesTransformer($options['choice_list']));
             } else {
-                $builder->appendClientTransformer(new ScalarToBooleanChoicesTransformer($options['choice_list']));
-                $builder->addEventSubscriber(new FixRadioInputListener(), 10);
+                $builder
+                    ->appendClientTransformer(new ScalarToBooleanChoicesTransformer($options['choice_list']))
+                    ->addEventSubscriber(new FixRadioInputListener(), 10)
+                ;
             }
         } else {
             if ($options['multiple']) {
@@ -110,14 +114,14 @@ class ChoiceType extends AbstractType
         $expanded = isset($options['expanded']) && $options['expanded'];
 
         return array(
-            'multiple' => false,
-            'expanded' => false,
-            'choice_list' => null,
-            'choices' => array(),
+            'multiple'          => false,
+            'expanded'          => false,
+            'choice_list'       => null,
+            'choices'           => array(),
             'preferred_choices' => array(),
-            'csrf_protection' => false,
-            'empty_data' => $multiple || $expanded ? array() : '',
-            'error_bubbling' => false,
+            'csrf_protection'   => false,
+            'empty_data'        => $multiple || $expanded ? array() : '',
+            'error_bubbling'    => false,
         );
     }
 

+ 15 - 9
src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php

@@ -24,16 +24,22 @@ class CollectionType extends AbstractType
         if ($options['allow_add'] && $options['prototype']) {
             $builder->add('$$name$$', $options['type'], array(
                 'property_path' => false,
-                'required' => false,
+                'required'      => false,
             ));
         }
 
-        $listener = new ResizeFormListener($builder->getFormFactory(),
-                $options['type'], $options['allow_add'], $options['allow_delete']);
+        $listener = new ResizeFormListener(
+            $builder->getFormFactory(),
+            $options['type'],
+            $options['allow_add'],
+            $options['allow_delete']
+        );
 
-        $builder->addEventSubscriber($listener)
+        $builder
+            ->addEventSubscriber($listener)
             ->setAttribute('allow_add', $options['allow_add'])
-            ->setAttribute('allow_delete', $options['allow_delete']);
+            ->setAttribute('allow_delete', $options['allow_delete'])
+        ;
     }
 
     public function buildView(FormView $view, FormInterface $form)
@@ -45,10 +51,10 @@ class CollectionType extends AbstractType
     public function getDefaultOptions(array $options)
     {
         return array(
-            'allow_add' => false,
-            'allow_delete' => false,
-            'prototype'  => true,
-            'type' => 'text',
+            'allow_add'     => false,
+            'allow_delete'  => false,
+            'prototype'     => true,
+            'type'          => 'text',
         );
     }
 

+ 23 - 21
src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php

@@ -66,7 +66,8 @@ class DateTimeType extends AbstractType
             $timeParts[] = 'second';
         }
 
-        $builder->appendClientTransformer(new DataTransformerChain(array(
+        $builder
+            ->appendClientTransformer(new DataTransformerChain(array(
                 new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], $parts),
                 new ArrayToPartsTransformer(array(
                     'date' => array('year', 'month', 'day'),
@@ -74,7 +75,8 @@ class DateTimeType extends AbstractType
                 )),
             )))
             ->add('date', 'date', $dateOptions)
-            ->add('time', 'time', $timeOptions);
+            ->add('time', 'time', $timeOptions)
+        ;
 
         if ($options['input'] === 'string') {
             $builder->appendNormTransformer(new ReversedTransformer(
@@ -94,52 +96,52 @@ class DateTimeType extends AbstractType
     public function getDefaultOptions(array $options)
     {
         return array(
-            'input' => 'datetime',
-            'with_seconds' => false,
+            'input'         => 'datetime',
+            'with_seconds'  => false,
             'data_timezone' => null,
             'user_timezone' => null,
             // Don't modify \DateTime classes by reference, we treat
             // them like immutable value objects
-            'by_reference' => false,
-            'date_pattern' => null,
-            'date_widget' => null,
-            'date_format' => null,
-            'time_pattern' => null,
-            'time_widget' => null,
+            'by_reference'  => false,
+            'date_pattern'  => null,
+            'date_widget'   => null,
+            'date_format'   => null,
+            'time_pattern'  => null,
+            'time_widget'   => null,
             /* Defaults for date field */
-            'years' => range(date('Y') - 5, date('Y') + 5),
-            'months' => range(1, 12),
-            'days' => range(1, 31),
+            'years'         => range(date('Y') - 5, date('Y') + 5),
+            'months'        => range(1, 12),
+            'days'          => range(1, 31),
             /* Defaults for time field */
-            'hours' => range(0, 23),
-            'minutes' => range(0, 59),
-            'seconds' => range(0, 59),
-            'with_seconds' => false,
+            'hours'         => range(0, 23),
+            'minutes'       => range(0, 59),
+            'seconds'       => range(0, 59),
+            'with_seconds'  => false,
         );
     }
 
     public function getAllowedOptionValues(array $options)
     {
         return array(
-            'input' => array(
+            'input'         => array(
                 'datetime',
                 'string',
                 'timestamp',
                 'array',
             ),
-            'date_widget' => array(
+            'date_widget'   => array(
                 null, // inherit default from DateType
                 'text',
                 'choice',
             ),
-            'date_format' => array(
+            'date_format'   => array(
                 null, // inherit default from DateType
                 \IntlDateFormatter::FULL,
                 \IntlDateFormatter::LONG,
                 \IntlDateFormatter::MEDIUM,
                 \IntlDateFormatter::SHORT,
              ),
-            'time_widget' => array(
+            'time_widget'   => array(
                 null, // inherit default from TimeType
                 'text',
                 'choice',

+ 20 - 17
src/Symfony/Component/Form/Extension/Core/Type/DateType.php

@@ -60,10 +60,12 @@ class DateType extends AbstractType
                 );
             }
 
-            $builder->add('year', $widget, $yearOptions)
+            $builder
+                ->add('year', $widget, $yearOptions)
                 ->add('month', $widget, $monthOptions)
                 ->add('day', $widget, $dayOptions)
-                ->appendClientTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], array('year', 'month', 'day')));
+                ->appendClientTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], array('year', 'month', 'day')))
+            ;
         }
 
         if ($options['input'] === 'string') {
@@ -84,7 +86,8 @@ class DateType extends AbstractType
 
         $builder
             ->setAttribute('formatter', $formatter)
-            ->setAttribute('widget', $options['widget']);
+            ->setAttribute('widget', $options['widget'])
+        ;
     }
 
     public function buildViewBottomUp(FormView $view, FormInterface $form)
@@ -111,37 +114,37 @@ class DateType extends AbstractType
     public function getDefaultOptions(array $options)
     {
         return array(
-            'years' => range(date('Y') - 5, date('Y') + 5),
-            'months' => range(1, 12),
-            'days' => range(1, 31),
-            'widget' => 'choice',
-            'input' => 'datetime',
-            'pattern' => null,
-            'format' => \IntlDateFormatter::MEDIUM,
-            'data_timezone' => null,
-            'user_timezone' => null,
-            'csrf_protection' => false,
+            'years'             => range(date('Y') - 5, date('Y') + 5),
+            'months'            => range(1, 12),
+            'days'              => range(1, 31),
+            'widget'            => 'choice',
+            'input'             => 'datetime',
+            'pattern'           => null,
+            'format'            => \IntlDateFormatter::MEDIUM,
+            'data_timezone'     => null,
+            'user_timezone'     => null,
+            'csrf_protection'   => false,
             // Don't modify \DateTime classes by reference, we treat
             // them like immutable value objects
-            'by_reference' => false,
+            'by_reference'      => false,
         );
     }
 
     public function getAllowedOptionValues(array $options)
     {
         return array(
-            'input' => array(
+            'input'     => array(
                 'datetime',
                 'string',
                 'timestamp',
                 'array',
             ),
-            'widget' => array(
+            'widget'    => array(
                 'single-text',
                 'text',
                 'choice',
             ),
-            'format' => array(
+            'format'    => array(
                 \IntlDateFormatter::FULL,
                 \IntlDateFormatter::LONG,
                 \IntlDateFormatter::MEDIUM,

+ 15 - 13
src/Symfony/Component/Form/Extension/Core/Type/FieldType.php

@@ -35,7 +35,8 @@ class FieldType extends AbstractType
             $options['property_path'] = new PropertyPath($options['property_path']);
         }
 
-        $builder->setRequired($options['required'])
+        $builder
+            ->setRequired($options['required'])
             ->setReadOnly($options['read_only'])
             ->setErrorBubbling($options['error_bubbling'])
             ->setEmptyData($options['empty_data'])
@@ -45,7 +46,8 @@ class FieldType extends AbstractType
             ->setAttribute('max_length', $options['max_length'])
             ->setAttribute('label', $options['label'] ?: $this->humanize($builder->getName()))
             ->setData($options['data'])
-            ->addValidator(new DefaultValidator());
+            ->addValidator(new DefaultValidator())
+        ;
 
         if ($options['trim']) {
             $builder->addEventSubscriber(new TrimListener());
@@ -87,17 +89,17 @@ class FieldType extends AbstractType
     public function getDefaultOptions(array $options)
     {
         $defaultOptions = array(
-            'data' => null,
-            'data_class' => null,
-            'trim' => true,
-            'required' => true,
-            'read_only' => false,
-            'max_length' => null,
-            'property_path' => null,
-            'by_reference' => true,
-            'error_bubbling' => false,
-            'error_mapping' => array(),
-            'label' => null,
+            'data'              => null,
+            'data_class'        => null,
+            'trim'              => true,
+            'required'          => true,
+            'read_only'         => false,
+            'max_length'        => null,
+            'property_path'     => null,
+            'by_reference'      => true,
+            'error_bubbling'    => false,
+            'error_mapping'     => array(),
+            'label'             => null,
         );
 
         $class = isset($options['data_class']) ? $options['data_class'] : null;

+ 4 - 3
src/Symfony/Component/Form/Extension/Core/Type/FileType.php

@@ -44,7 +44,8 @@ class FileType extends AbstractType
             ->add('file', 'field')
             ->add('token', 'hidden')
             ->add('name', 'hidden')
-            ->add('originalName', 'hidden');
+            ->add('originalName', 'hidden')
+        ;
     }
 
     public function buildViewBottomUp(FormView $view, FormInterface $form)
@@ -56,8 +57,8 @@ class FileType extends AbstractType
     public function getDefaultOptions(array $options)
     {
         return array(
-            'type' => 'string',
-            'csrf_protection' => false,
+            'type'              => 'string',
+            'csrf_protection'   => false,
         );
     }
 

+ 2 - 2
src/Symfony/Component/Form/Extension/Core/Type/FormType.php

@@ -42,10 +42,10 @@ class FormType extends AbstractType
     public function getDefaultOptions(array $options)
     {
         $defaultOptions = array(
-            'virtual' => false,
+            'virtual'           => false,
             // Errors in forms bubble by default, so that form errors will
             // end up as global errors in the root form
-            'error_bubbling' => true,
+            'error_bubbling'    => true,
         );
 
         if (empty($options['data_class'])) {

+ 8 - 3
src/Symfony/Component/Form/Extension/Core/Type/IntegerType.php

@@ -19,15 +19,20 @@ class IntegerType extends AbstractType
 {
     public function buildForm(FormBuilder $builder, array $options)
     {
-        $builder->appendClientTransformer(new IntegerToLocalizedStringTransformer($options['precision'], $options['grouping'], $options['rounding_mode']));
+        $builder->appendClientTransformer(
+            new IntegerToLocalizedStringTransformer(
+                $options['precision'],
+                $options['grouping'],
+                $options['rounding_mode']
+        ));
     }
 
     public function getDefaultOptions(array $options)
     {
         return array(
             // default precision is locale specific (usually around 3)
-            'precision' => null,
-            'grouping' => false,
+            'precision'     => null,
+            'grouping'      => false,
             // Integer cast rounds towards 0, so do the same when displaying fractions
             'rounding_mode' => \NumberFormatter::ROUND_DOWN,
         );

+ 12 - 5
src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php

@@ -23,8 +23,15 @@ class MoneyType extends AbstractType
 
     public function buildForm(FormBuilder $builder, array $options)
     {
-        $builder->appendClientTransformer(new MoneyToLocalizedStringTransformer($options['precision'], $options['grouping'], null, $options['divisor']))
-            ->setAttribute('currency', $options['currency']);
+        $builder
+            ->appendClientTransformer(new MoneyToLocalizedStringTransformer(
+                $options['precision'],
+                $options['grouping'],
+                null,
+                $options['divisor']
+            ))
+            ->setAttribute('currency', $options['currency'])
+        ;
     }
 
     public function buildView(FormView $view, FormInterface $form)
@@ -36,9 +43,9 @@ class MoneyType extends AbstractType
     {
         return array(
             'precision' => 2,
-            'grouping' => false,
-            'divisor' => 1,
-            'currency' => 'EUR',
+            'grouping'  => false,
+            'divisor'   => 1,
+            'currency'  => 'EUR',
         );
     }
 

+ 7 - 3
src/Symfony/Component/Form/Extension/Core/Type/NumberType.php

@@ -19,15 +19,19 @@ class NumberType extends AbstractType
 {
     public function buildForm(FormBuilder $builder, array $options)
     {
-        $builder->appendClientTransformer(new NumberToLocalizedStringTransformer($options['precision'], $options['grouping'], $options['rounding_mode']));
+        $builder->appendClientTransformer(new NumberToLocalizedStringTransformer(
+            $options['precision'],
+            $options['grouping'],
+            $options['rounding_mode']
+        ));
     }
 
     public function getDefaultOptions(array $options)
     {
         return array(
             // default precision is locale specific (usually around 3)
-            'precision' => null,
-            'grouping' => false,
+            'precision'     => null,
+            'grouping'      => false,
             'rounding_mode' => \NumberFormatter::ROUND_HALFUP,
         );
     }

+ 1 - 1
src/Symfony/Component/Form/Extension/Core/Type/PercentType.php

@@ -26,7 +26,7 @@ class PercentType extends AbstractType
     {
         return array(
             'precision' => 0,
-            'type' => 'fractional',
+            'type'      => 'fractional',
         );
     }
 

+ 4 - 2
src/Symfony/Component/Form/Extension/Core/Type/RadioType.php

@@ -21,8 +21,10 @@ class RadioType extends AbstractType
 {
     public function buildForm(FormBuilder $builder, array $options)
     {
-        $builder->appendClientTransformer(new BooleanToStringTransformer())
-            ->setAttribute('value', $options['value']);
+        $builder
+            ->appendClientTransformer(new BooleanToStringTransformer())
+            ->setAttribute('value', $options['value'])
+        ;
     }
 
     public function buildView(FormView $view, FormInterface $form)

+ 10 - 8
src/Symfony/Component/Form/Extension/Core/Type/RepeatedType.php

@@ -19,23 +19,25 @@ class RepeatedType extends AbstractType
 {
     public function buildForm(FormBuilder $builder, array $options)
     {
-        $builder->appendClientTransformer(new ValueToDuplicatesTransformer(array(
+        $builder
+            ->appendClientTransformer(new ValueToDuplicatesTransformer(array(
                 $options['first_name'],
                 $options['second_name'],
             )))
             ->add($options['first_name'], $options['type'], $options['options'])
-            ->add($options['second_name'], $options['type'], $options['options']);
+            ->add($options['second_name'], $options['type'], $options['options'])
+        ;
     }
 
     public function getDefaultOptions(array $options)
     {
         return array(
-            'type' => 'text',
-            'options' => array(),
-            'first_name' => 'first',
-            'second_name' => 'second',
-            'csrf_protection' => false,
-            'error_bubbling' => false,
+            'type'              => 'text',
+            'options'           => array(),
+            'first_name'        => 'first',
+            'second_name'       => 'second',
+            'csrf_protection'   => false,
+            'error_bubbling'    => false,
         );
     }
 

+ 19 - 13
src/Symfony/Component/Form/Extension/Core/Type/TimeType.php

@@ -66,9 +66,15 @@ class TimeType extends AbstractType
         }
 
         $builder
-            ->appendClientTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], $parts, $options['widget'] === 'text'))
+            ->appendClientTransformer(new DateTimeToArrayTransformer(
+                $options['data_timezone'],
+                $options['user_timezone'],
+                $parts,
+                $options['widget'] === 'text'
+            ))
             ->setAttribute('widget', $options['widget'])
-            ->setAttribute('with_seconds', $options['with_seconds']);
+            ->setAttribute('with_seconds', $options['with_seconds'])
+        ;
     }
 
     public function buildView(FormView $view, FormInterface $form)
@@ -80,19 +86,19 @@ class TimeType extends AbstractType
     public function getDefaultOptions(array $options)
     {
         return array(
-            'hours' => range(0, 23),
-            'minutes' => range(0, 59),
-            'seconds' => range(0, 59),
-            'widget' => 'choice',
-            'input' => 'datetime',
-            'with_seconds' => false,
-            'pattern' => null,
-            'data_timezone' => null,
-            'user_timezone' => null,
-            'csrf_protection' => false,
+            'hours'             => range(0, 23),
+            'minutes'           => range(0, 59),
+            'seconds'           => range(0, 59),
+            'widget'            => 'choice',
+            'input'             => 'datetime',
+            'with_seconds'      => false,
+            'pattern'           => null,
+            'data_timezone'     => null,
+            'user_timezone'     => null,
+            'csrf_protection'   => false,
             // Don't modify \DateTime classes by reference, we treat
             // them like immutable value objects
-            'by_reference' => false,
+            'by_reference'      => false,
         );
     }