Conditions | 1 |
Paths | 1 |
Total Lines | 59 |
Code Lines | 39 |
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 |
||
31 | protected function build($builder) |
||
32 | { |
||
33 | $builder |
||
34 | ->add('player', new AdvancedModelType('player'), [ |
||
35 | 'constraints' => [ |
||
36 | new NotBlank() |
||
37 | ], |
||
38 | 'disabled' => $this->isEdit(), |
||
39 | 'required' => true, |
||
40 | ]) |
||
41 | ->add('expiration', DateType::class, [ |
||
42 | 'data' => \TimeDate::now(), |
||
43 | 'label' => 'Expiration Date', |
||
44 | 'required' => false, |
||
45 | ]) |
||
46 | ->add('is_permanent', CheckboxType::class, [ |
||
47 | 'label' => 'Permanent Ban', |
||
48 | 'required' => false, |
||
49 | 'attr' => [ |
||
50 | 'data-help-message' => 'When checked, no expiration date needs to be set and will be ignored', |
||
51 | ], |
||
52 | ]) |
||
53 | ->add('reason', TextareaType::class, [ |
||
54 | 'constraints' => [ |
||
55 | new NotBlank() |
||
56 | ], |
||
57 | 'required' => true, |
||
58 | ]) |
||
59 | ->add('is_soft_ban', CheckboxType::class, [ |
||
60 | 'label' => 'Soft Ban', |
||
61 | 'required' => false, |
||
62 | 'attr' => [ |
||
63 | 'data-help-message' => "A soft ban will not affect a player's permissions on this site; e.g. a mute", |
||
64 | ], |
||
65 | ]) |
||
66 | ->add('server_message', TextType::class, [ |
||
67 | 'required' => false, |
||
68 | 'constraints' => [ |
||
69 | new Length([ |
||
70 | 'max' => 150, |
||
71 | ]), |
||
72 | ], |
||
73 | 'attr' => [ |
||
74 | 'data-help-message' => 'The ban message that will appear on match servers', |
||
75 | ], |
||
76 | ]) |
||
77 | ->add('ip_addresses', new IpType(), [ |
||
78 | 'label' => 'IP Addresses', |
||
79 | 'required' => false, |
||
80 | 'attr' => [ |
||
81 | 'data-help-message' => 'The IP addresses that will be banned on match servers. Use commas to separate multiple IPs.', |
||
82 | ], |
||
83 | ]) |
||
84 | ; |
||
85 | |||
86 | return $builder->add('submit', SubmitType::class, [ |
||
87 | 'label' => 'Enter Ban', |
||
88 | ]); |
||
89 | } |
||
90 | |||
160 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: