| Conditions | 3 |
| Paths | 2 |
| Total Lines | 71 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 32 | protected function build($builder) |
||
| 33 | { |
||
| 34 | $builder |
||
| 35 | ->add('name', TextType::class, array( |
||
| 36 | 'constraints' => [ |
||
| 37 | new NotBlank(), |
||
| 38 | new Length([ |
||
| 39 | 'min' => 2, |
||
| 40 | 'max' => 40, |
||
| 41 | ]), |
||
| 42 | ], |
||
| 43 | 'data' => $this->editing->getName(), |
||
| 44 | 'required' => true, |
||
| 45 | )) |
||
| 46 | ->add('alias', TextType::class, array( |
||
| 47 | 'constraints' => [ |
||
| 48 | new Length([ |
||
| 49 | 'max' => 40, |
||
| 50 | ]), |
||
| 51 | new UniqueAlias('Map', $this->editing), |
||
| 52 | new Type([ |
||
| 53 | 'type' => 'alpha' |
||
| 54 | ]), |
||
| 55 | ], |
||
| 56 | 'data' => $this->editing->getAlias(), |
||
| 57 | 'required' => true |
||
| 58 | )) |
||
| 59 | ->add('description', TextareaType::class, array( |
||
| 60 | 'constraints' => [ |
||
| 61 | new NotBlank(), |
||
| 62 | new Length([ |
||
| 63 | 'min' => 10 |
||
| 64 | ]), |
||
| 65 | ], |
||
| 66 | 'data' => $this->editing->getDescription(), |
||
| 67 | 'required' => true, |
||
| 68 | )) |
||
| 69 | ->add('avatar', FileType::class, array( |
||
| 70 | 'constraints' => new Image(array( |
||
| 71 | 'minWidth' => 60, |
||
| 72 | 'minHeight' => 60, |
||
| 73 | 'maxSize' => '8M' |
||
| 74 | )), |
||
| 75 | 'required' => ($this->editing === null || $this->editing->hasAvatar()) |
||
| 76 | )) |
||
| 77 | ->add('shot_count', IntegerType::class, [ |
||
| 78 | 'data' => $this->editing->getShotCount(), |
||
| 79 | 'label' => 'Max shot count', |
||
| 80 | 'required' => true, |
||
| 81 | ]) |
||
| 82 | ->add('jumping', CheckboxType::class, [ |
||
| 83 | 'data' => $this->editing->isJumpingEnabled(), |
||
| 84 | 'label' => 'Map allows jumping', |
||
| 85 | 'required' => false, |
||
| 86 | ]) |
||
| 87 | ->add('ricochet', CheckboxType::class, [ |
||
| 88 | 'data' => $this->editing->isRicochetEnabled(), |
||
| 89 | 'label' => 'Map allows ricochet', |
||
| 90 | 'required' => false, |
||
| 91 | ]) |
||
| 92 | ; |
||
| 93 | |||
| 94 | if ($this->editing) { |
||
| 95 | // We are editing the map, not creating it |
||
| 96 | $builder->add('delete_avatar', SubmitType::class); |
||
| 97 | } |
||
| 98 | |||
| 99 | return $builder->add('submit', SubmitType::class, [ |
||
| 100 | 'label' => 'Save' |
||
| 101 | ]); |
||
| 102 | } |
||
| 103 | |||
| 145 |