Conditions | 26 |
Paths | 32 |
Total Lines | 138 |
Code Lines | 100 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
50 | public function buildView(FormView $view, FormInterface $form, array $options) |
||
51 | { |
||
52 | if (count($options['constraints']) > 0) { |
||
53 | $view->vars['attr']['data-val'] = 'true'; |
||
54 | |||
55 | $label = $this->trans($options['label']); |
||
56 | |||
57 | /** @var Constraint $constraint */ |
||
58 | foreach ($options['constraints'] as $constraint) { |
||
59 | switch (get_class($constraint)) { |
||
60 | case 'Symfony\Component\Validator\Constraints\Required': |
||
61 | $view->vars['attr']['data-val-required'] = $this->trans( |
||
62 | 'The \'{{ field_name }}\' field is required.', |
||
63 | array('{{ field_name }}' => $label) |
||
64 | ); |
||
65 | break; |
||
66 | case 'Symfony\Component\Validator\Constraints\Regex': |
||
67 | $view->vars['attr']['data-val-regex'] = $this->trans( |
||
68 | 'The \'{{ field_name }}\' value is not valid', |
||
69 | array('{{ field_name }}' => $label) |
||
70 | ); |
||
71 | $view->vars['attr']['data-val-regex-pattern'] = $constraint->htmlPattern; |
||
72 | break; |
||
73 | case 'Symfony\Component\Validator\Constraints\Range': |
||
74 | if (!empty($constraint->min)) { |
||
75 | $view->vars['attr']['data-val-range-min'] = $constraint->min; |
||
76 | $view->vars['attr']['data-val-range'] = $this->trans( |
||
77 | 'The field \'{{ field_name }}\' value should be {{ limit }} or more.', |
||
78 | array( |
||
79 | '{{ field_name }}' => $label, |
||
80 | '{{ limit }}' => $constraint->min |
||
81 | ) |
||
82 | ); |
||
83 | } |
||
84 | if (!empty($constraint->max)) { |
||
85 | $view->vars['attr']['data-val-range-max'] = $constraint->max; |
||
86 | $view->vars['attr']['data-val-range'] = $this->trans( |
||
87 | 'The field \'{{ field_name }}\' value should be {{ limit }} or less.', |
||
88 | array( |
||
89 | '{{ field_name }}' => $label, |
||
90 | '{{ limit }}' => $constraint->max |
||
91 | ) |
||
92 | ); |
||
93 | } |
||
94 | |||
95 | if (!empty($constraint->min) && !empty($constraint->max)) { |
||
96 | $view->vars['attr']['data-val-range'] = $this->trans( |
||
97 | 'The field \'{{ field_name }}\' value should be in range {{ min }} to {{ max }}.', |
||
98 | array( |
||
99 | '{{ field_name }}' => $label, |
||
100 | '{{ min }}' => $constraint->min, |
||
101 | '{{ max }}' => $constraint->max |
||
102 | ) |
||
103 | ); |
||
104 | } |
||
105 | break; |
||
106 | case 'Symfony\Component\Validator\Constraints\Length': |
||
107 | if (!empty($constraint->min)) { |
||
108 | $view->vars['attr']['data-val-length-min'] = $constraint->min; |
||
109 | $view->vars['attr']['data-val-length'] = $this->trans( |
||
110 | 'The field \'{{ field_name }}\' should have {{ limit }} or more.', |
||
111 | array( |
||
112 | '{{ field_name }}' => $label, |
||
113 | '{{ limit }}' => $constraint->min |
||
114 | ) |
||
115 | ); |
||
116 | } |
||
117 | |||
118 | if (!empty($constraint->max)) { |
||
119 | $view->vars['attr']['data-val-length-max'] = $constraint->max; |
||
120 | $view->vars['attr']['data-val-length'] = $this->trans( |
||
121 | 'The field \'{{ field_name }}\' should have {{ limit }} or less.', |
||
122 | array( |
||
123 | '{{ field_name }}' => $label, |
||
124 | '{{ limit }}' => $constraint->max |
||
125 | ) |
||
126 | ); |
||
127 | } |
||
128 | |||
129 | if (!empty($constraint->min) && !empty($constraint->max)) { |
||
130 | $view->vars['attr']['data-val-length'] = $this->trans( |
||
131 | 'The field \'{{ field_name }}\' should have from {{ min }} to {{ max }} characters.', |
||
132 | array( |
||
133 | '{{ field_name }}' => $label, |
||
134 | '{{ min }}' => $constraint->min, |
||
135 | '{{ max }}' => $constraint->max |
||
136 | ) |
||
137 | ); |
||
138 | } |
||
139 | break; |
||
140 | case 'Symfony\Component\Validator\Constraints\Type': |
||
141 | switch ($constraint->type) { |
||
142 | case 'integer': |
||
143 | case 'int': |
||
144 | case 'long': |
||
145 | $view->vars['attr']['data-val-digits'] = $this->trans( |
||
146 | 'The \'{{ field_name }}\' field value is not a valid integer.', |
||
147 | array('{{ field_name }}' => $label) |
||
148 | ); |
||
149 | break; |
||
150 | case 'float': |
||
151 | case 'numeric': |
||
152 | case 'real': |
||
153 | $view->vars['attr']['data-val-number'] = $this->trans( |
||
154 | 'The \'{{ field_name }}\' field value is not a valid number.', |
||
155 | array('{{ field_name }}' => $label) |
||
156 | ); |
||
157 | break; |
||
158 | } |
||
159 | break; |
||
160 | case 'Symfony\Component\Validator\Constraints\Date': |
||
161 | $view->vars['attr']['data-val-date'] = $this->trans( |
||
162 | 'The \'{{ field_name }}\' field value is not a valid date.', |
||
163 | array('{{ field_name }}' => $label) |
||
164 | ); |
||
165 | break; |
||
166 | case 'Symfony\Component\Validator\Constraints\Email': |
||
167 | $view->vars['attr']['data-val-email'] = $this->trans( |
||
168 | 'The \'{{ field_name }}\' field value is not a valid email address.', |
||
169 | array('{{ field_name }}' => $label) |
||
170 | ); |
||
171 | break; |
||
172 | case 'Symfony\Component\Validator\Constraints\CardScheme': |
||
173 | $view->vars['attr']['data-val-creditcard'] = $this->trans( |
||
174 | 'The \'{{ field_name }}\' field value is not a valid credit card number.', |
||
175 | array('{{ field_name }}' => $label) |
||
176 | ); |
||
177 | break; |
||
178 | case 'Symfony\Component\Validator\Constraints\Url': |
||
179 | $view->vars['attr']['data-val-url'] = $this->trans( |
||
180 | 'The \'{{ field_name }}\' field value is not a valid url.', |
||
181 | array('{{ field_name }}' => $label) |
||
182 | ); |
||
183 | break; |
||
184 | } |
||
185 | } |
||
186 | } |
||
187 | } |
||
188 | |||
236 | } |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.