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