Conditions | 3 |
Paths | 2 |
Total Lines | 101 |
Code Lines | 70 |
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 |
||
35 | protected function build($builder) |
||
36 | { |
||
37 | $builder |
||
38 | ->add('name', TextType::class, array( |
||
39 | 'constraints' => [ |
||
40 | new NotBlank(), |
||
41 | new Length([ |
||
42 | 'min' => 2, |
||
43 | 'max' => 40, |
||
44 | ]), |
||
45 | ], |
||
46 | 'data' => $this->editing->getName(), |
||
47 | 'required' => true, |
||
48 | )) |
||
49 | ->add('alias', TextType::class, array( |
||
50 | 'constraints' => [ |
||
51 | new Length([ |
||
52 | 'max' => 40, |
||
53 | ]), |
||
54 | new UniqueAlias('Map', $this->editing), |
||
55 | new Type([ |
||
56 | 'type' => 'alpha' |
||
57 | ]), |
||
58 | ], |
||
59 | 'data' => $this->editing->getAlias(), |
||
60 | 'label' => 'Mapchange Configuration Name', |
||
61 | 'required' => true |
||
62 | )) |
||
63 | ->add('description', TextareaType::class, array( |
||
64 | 'constraints' => [ |
||
65 | new NotBlank(), |
||
66 | new Length([ |
||
67 | 'min' => 10 |
||
68 | ]), |
||
69 | ], |
||
70 | 'data' => $this->editing->getDescription(), |
||
71 | 'required' => true, |
||
72 | )) |
||
73 | ->add('world_size', IntegerType::class, [ |
||
74 | 'constraints' => [ |
||
75 | new GreaterThanOrEqual([ |
||
76 | 'value' => 200 |
||
77 | ]), |
||
78 | ], |
||
79 | 'data' => $this->editing->getWorldSize(), |
||
80 | 'label' => 'BZDB _worldSize', |
||
81 | 'required' => true, |
||
82 | ]) |
||
83 | ->add('randomly_generated', CheckboxType::class, [ |
||
84 | 'data' => $this->editing->isRandomlyGenerated(), |
||
85 | 'label' => 'Map is randomly generated', |
||
86 | 'required' => false, |
||
87 | ]) |
||
88 | ->add('avatar', FileType::class, array( |
||
89 | 'constraints' => new Image(array( |
||
90 | 'minWidth' => 60, |
||
91 | 'minHeight' => 60, |
||
92 | 'maxSize' => '8M' |
||
93 | )), |
||
94 | 'required' => ($this->editing === null || $this->editing->hasAvatar()) |
||
95 | )) |
||
96 | ->add('shot_count', IntegerType::class, [ |
||
97 | 'constraints' => [ |
||
98 | new GreaterThan([ |
||
99 | 'value' => 0 |
||
100 | ]), |
||
101 | ], |
||
102 | 'data' => $this->editing->getShotCount(), |
||
103 | 'label' => 'Max shot count', |
||
104 | 'required' => true, |
||
105 | ]) |
||
106 | ->add('jumping', CheckboxType::class, [ |
||
107 | 'data' => $this->editing->isJumpingEnabled(), |
||
108 | 'label' => 'Map allows jumping', |
||
109 | 'required' => false, |
||
110 | ]) |
||
111 | ->add('ricochet', CheckboxType::class, [ |
||
112 | 'data' => $this->editing->isRicochetEnabled(), |
||
113 | 'label' => 'Map allows ricochet', |
||
114 | 'required' => false, |
||
115 | ]) |
||
116 | ->add('game_mode', ChoiceType::class, [ |
||
117 | 'choices' => [ |
||
118 | \Map::GAME_MODE_CTF => 'CTF', |
||
119 | \Map::GAME_MODE_AHOD => 'AHOD', |
||
120 | ], |
||
121 | 'data' => $this->editing->getGameMode(), |
||
122 | 'multiple' => false, |
||
123 | 'label' => 'Game Mode', |
||
124 | ]) |
||
125 | ; |
||
126 | |||
127 | if ($this->editing) { |
||
128 | // We are editing the map, not creating it |
||
129 | $builder->add('delete_avatar', SubmitType::class); |
||
130 | } |
||
131 | |||
132 | return $builder->add('submit', SubmitType::class, [ |
||
133 | 'label' => 'Save' |
||
134 | ]); |
||
135 | } |
||
136 | |||
184 |