| Conditions | 4 |
| Paths | 4 |
| Total Lines | 20 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | 10 | public function process(FormRuleProcessorContext $processContext, FormRuleContextBuilder $formRuleContext) |
|
| 23 | { |
||
| 24 | 10 | $view = $processContext->getView(); |
|
| 25 | 10 | if (!isset($view->vars['required'])) { |
|
| 26 | 1 | return; |
|
| 27 | } |
||
| 28 | |||
| 29 | // Check if the field is really required according to HTML validation |
||
| 30 | // (aka the required for symfony form means it needs to be submitted but maybe null or "") |
||
| 31 | 9 | $constraints = $processContext->getConstraints(); |
|
| 32 | 9 | foreach ($constraints as $constraint) { |
|
| 33 | 8 | if (in_array(get_class($constraint), static::$requiredConstraintClasses, true)) { |
|
| 34 | 6 | $view->vars['required'] = true; |
|
| 35 | |||
| 36 | 6 | return; |
|
| 37 | } |
||
| 38 | 6 | } |
|
| 39 | |||
| 40 | 3 | $view->vars['required'] = false; |
|
| 41 | 3 | } |
|
| 42 | } |
||
| 43 |