| Conditions | 7 |
| Paths | 4 |
| Total Lines | 28 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 19 |
| CRAP Score | 7.0422 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 40 | 2 | public function __toArray() |
|
| 41 | { |
||
| 42 | 2 | $array = [ |
|
| 43 | 2 | 'fields' => [], |
|
| 44 | 2 | 'actions' => [], |
|
| 45 | 2 | ]; |
|
| 46 | 2 | foreach ($this->fields as $field) { |
|
| 47 | 2 | $array['fields'][] = $field->__toArray(); |
|
| 48 | } |
||
| 49 | 2 | usort($array['fields'], function ($fieldA, $fieldB) { |
|
| 50 | 1 | if ((bool)$fieldA['required'] !== (bool)$fieldB['required']) { |
|
| 51 | 1 | if ((bool)$fieldA['required']) { |
|
| 52 | return -1; |
||
| 53 | } else { |
||
| 54 | 1 | return 1; |
|
| 55 | } |
||
| 56 | } |
||
| 57 | 1 | $aOrder = Form::fieldsOrder($fieldA); |
|
| 58 | 1 | $bOrder = Form::fieldsOrder($fieldB); |
|
| 59 | 1 | if ($aOrder === $bOrder) { |
|
| 60 | return strcmp($fieldA['name'], $fieldB['name']); |
||
| 61 | } |
||
| 62 | 1 | return ($aOrder < $bOrder) ? -1 : 1; |
|
| 63 | 2 | }); |
|
| 64 | 2 | foreach ($this->actions as $action) { |
|
| 65 | 1 | $array['actions'][] = $action->__toArray(); |
|
| 66 | } |
||
| 67 | 2 | return $array; |
|
| 68 | } |
||
| 106 |