@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | /** |
24 | 24 | * @inheritdoc |
25 | 25 | */ |
26 | - public function getClassFormDefinition(array $fields=[]) |
|
26 | + public function getClassFormDefinition(array $fields = []) |
|
27 | 27 | { |
28 | 28 | // if there is no definition return an empty form |
29 | 29 | if (empty($this->definition)) |
@@ -133,19 +133,19 @@ discard block |
||
133 | 133 | protected function convertRenderablesToFields($key, $renderables) { |
134 | 134 | if (!isset($renderables[$key])) { |
135 | 135 | dd("Key $key doesn't exist in the form definition", $renderables); |
136 | - throw new \RuntimeException("Key $key doesn't exist in the form definition");} |
|
136 | + throw new \RuntimeException("Key $key doesn't exist in the form definition"); } |
|
137 | 137 | $rend = $renderables[$key]; |
138 | - $field=[]; |
|
138 | + $field = []; |
|
139 | 139 | if (!empty($rend['type'])) { |
140 | 140 | $field = []; |
141 | - switch($rend['type']) { |
|
141 | + switch ($rend['type']) { |
|
142 | 142 | case 'FormComponent': |
143 | 143 | if (isset($rend['items'])) |
144 | 144 | $field['fields'] = $this->addItems($rend['items'], $renderables); |
145 | 145 | break; |
146 | 146 | case 'ClassComponent': |
147 | 147 | $classDefinition = isset($rend['definition']) ? $rend['definition'] : []; |
148 | - if (count($rend['items'])>0) { |
|
148 | + if (count($rend['items']) > 0) { |
|
149 | 149 | $field['fields'] = []; |
150 | 150 | $field['label'] = ''; |
151 | 151 | if (isset($classDefinition['showLabel']) && $classDefinition['showLabel']) |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | $field['allowRemove'] = $allowChangeOfRepeats; |
218 | 218 | |
219 | 219 | // now set the template header part |
220 | - $field['template']['class'] = "neon\\core\\form\\Form"; |
|
220 | + $field['template']['class'] = "neon\\core\\form\\Form"; |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * so we know what object it belongs to if set |
226 | 226 | * @return array |
227 | 227 | */ |
228 | - protected function createHiddenField($name, $value=null) |
|
228 | + protected function createHiddenField($name, $value = null) |
|
229 | 229 | { |
230 | 230 | return [ |
231 | 231 | 'class' => "neon\\core\\form\\fields\\Hidden", |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | protected function createFieldName($field) |
239 | 239 | { |
240 | 240 | $uuid = isset($field['id']) ? $field['id'] : Hash::uuid64(); |
241 | - return str_replace(['-','_'],['a','Z'], $uuid); |
|
241 | + return str_replace(['-', '_'], ['a', 'Z'], $uuid); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | } |
245 | 245 | \ No newline at end of file |
@@ -26,8 +26,9 @@ discard block |
||
26 | 26 | public function getClassFormDefinition(array $fields=[]) |
27 | 27 | { |
28 | 28 | // if there is no definition return an empty form |
29 | - if (empty($this->definition)) |
|
30 | - return []; |
|
29 | + if (empty($this->definition)) { |
|
30 | + return []; |
|
31 | + } |
|
31 | 32 | |
32 | 33 | // TODO - NJ20180426 - see if we can get Phoebe to listen to $fields |
33 | 34 | |
@@ -55,8 +56,9 @@ discard block |
||
55 | 56 | */ |
56 | 57 | public function editClass($changes) |
57 | 58 | { |
58 | - if (isset($changes['definition'])) |
|
59 | - $changes['definition'] = $this->prepareDefinition($changes['definition']); |
|
59 | + if (isset($changes['definition'])) { |
|
60 | + $changes['definition'] = $this->prepareDefinition($changes['definition']); |
|
61 | + } |
|
60 | 62 | parent::editClass($changes); |
61 | 63 | } |
62 | 64 | |
@@ -84,8 +86,9 @@ discard block |
||
84 | 86 | { |
85 | 87 | $definition = $this->definition; |
86 | 88 | $applicationDataPhoebeUuids = []; |
87 | - foreach ($ddsClassTypes as $ct) |
|
88 | - $applicationDataPhoebeUuids[$ct] = null; |
|
89 | + foreach ($ddsClassTypes as $ct) { |
|
90 | + $applicationDataPhoebeUuids[$ct] = null; |
|
91 | + } |
|
89 | 92 | foreach ($definition['renderables'] as $k=>$r) { |
90 | 93 | if ($r['type'] == 'ClassComponent' && in_array($r['class_type'], $ddsClassTypes)) { |
91 | 94 | $applicationDataPhoebeUuids[$r['class_type']] = $k; |
@@ -125,8 +128,9 @@ discard block |
||
125 | 128 | $fields = $this->convertRenderablesToFields($definition['rootNode'], $definition['renderables']); |
126 | 129 | $form['fields'] = $fields['fields']; |
127 | 130 | // apply any overrides to the form |
128 | - if ($this->_overrides) |
|
129 | - $form = array_replace_recursive($form, $this->_overrides); |
|
131 | + if ($this->_overrides) { |
|
132 | + $form = array_replace_recursive($form, $this->_overrides); |
|
133 | + } |
|
130 | 134 | return $form; |
131 | 135 | } |
132 | 136 | |
@@ -140,23 +144,27 @@ discard block |
||
140 | 144 | $field = []; |
141 | 145 | switch($rend['type']) { |
142 | 146 | case 'FormComponent': |
143 | - if (isset($rend['items'])) |
|
144 | - $field['fields'] = $this->addItems($rend['items'], $renderables); |
|
147 | + if (isset($rend['items'])) { |
|
148 | + $field['fields'] = $this->addItems($rend['items'], $renderables); |
|
149 | + } |
|
145 | 150 | break; |
146 | 151 | case 'ClassComponent': |
147 | 152 | $classDefinition = isset($rend['definition']) ? $rend['definition'] : []; |
148 | 153 | if (count($rend['items'])>0) { |
149 | 154 | $field['fields'] = []; |
150 | 155 | $field['label'] = ''; |
151 | - if (isset($classDefinition['showLabel']) && $classDefinition['showLabel']) |
|
152 | - $field['label'] = isset($classDefinition['label']) ? $classDefinition['label'] : $rend['label']; |
|
156 | + if (isset($classDefinition['showLabel']) && $classDefinition['showLabel']) { |
|
157 | + $field['label'] = isset($classDefinition['label']) ? $classDefinition['label'] : $rend['label']; |
|
158 | + } |
|
153 | 159 | $field['description'] = ''; |
154 | - if (isset($classDefinition['showDescription']) && $classDefinition['showDescription']) |
|
155 | - $field['description'] = isset($classDefinition['description']) ? $classDefinition['description'] : $rend['description']; |
|
160 | + if (isset($classDefinition['showDescription']) && $classDefinition['showDescription']) { |
|
161 | + $field['description'] = isset($classDefinition['description']) ? $classDefinition['description'] : $rend['description']; |
|
162 | + } |
|
156 | 163 | if ($this->isRepeater($rend)) { |
157 | 164 | $this->addRepeaterHeader($field, $rend['definition'], $key); |
158 | - if (isset($classDefinition['showLabel']) && $classDefinition['showLabel']) |
|
159 | - $field['template']['label'] = isset($classDefinition['label']) ? $classDefinition['label'] : $rend['label']; |
|
165 | + if (isset($classDefinition['showLabel']) && $classDefinition['showLabel']) { |
|
166 | + $field['template']['label'] = isset($classDefinition['label']) ? $classDefinition['label'] : $rend['label']; |
|
167 | + } |
|
160 | 168 | $field['template']['fields'] = $this->addItems($rend['items'], $renderables); |
161 | 169 | $field['template']['fields'][] = $this->createHiddenField('_renderable', $key); |
162 | 170 | $field['template']['fields'][] = $this->createHiddenField('_classType', $rend['class_type']); |
@@ -191,10 +199,11 @@ discard block |
||
191 | 199 | $order = 1; |
192 | 200 | foreach ($items as $rKey) { |
193 | 201 | $subField = $this->convertRenderablesToFields($rKey, $renderables, 1); |
194 | - if (isset($subField[$rKey])) |
|
195 | - $field[$rKey] = $subField[$rKey]; |
|
196 | - else |
|
197 | - $field[$rKey] = $subField; |
|
202 | + if (isset($subField[$rKey])) { |
|
203 | + $field[$rKey] = $subField[$rKey]; |
|
204 | + } else { |
|
205 | + $field[$rKey] = $subField; |
|
206 | + } |
|
198 | 207 | $field[$rKey]['order'] = $order++; |
199 | 208 | } |
200 | 209 | return $field; |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | { |
19 | 19 | use PhoebeTrait; |
20 | 20 | |
21 | - public function __construct($config=[]) |
|
21 | + public function __construct($config = []) |
|
22 | 22 | { |
23 | 23 | $path = '\neon\phoebe\services\adapters\appforms'; |
24 | 24 | $config['phoebeType'] = 'applicationForm'; |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | parent::__construct($config); |
29 | 29 | } |
30 | 30 | |
31 | - public function getClass($classType, $version=null, $classOverrideCriteria=[]) |
|
31 | + public function getClass($classType, $version = null, $classOverrideCriteria = []) |
|
32 | 32 | { |
33 | 33 | $class = parent::getClass($classType, $version, $classOverrideCriteria); |
34 | 34 | // update member definitions with the latest from the database and |
@@ -33,8 +33,9 @@ discard block |
||
33 | 33 | $class = parent::getClass($classType, $version, $classOverrideCriteria); |
34 | 34 | // update member definitions with the latest from the database and |
35 | 35 | // override again with the changes that were defined before |
36 | - if ($class) |
|
37 | - $class->definition = $this->updateDefinitionFromDds($class->definition); |
|
36 | + if ($class) { |
|
37 | + $class->definition = $this->updateDefinitionFromDds($class->definition); |
|
38 | + } |
|
38 | 39 | return $class; |
39 | 40 | } |
40 | 41 | |
@@ -55,8 +56,9 @@ discard block |
||
55 | 56 | { |
56 | 57 | $object = parent::getObject($objectId); |
57 | 58 | // update the data from Daedalus if required |
58 | - if ($object) |
|
59 | - $object->updateFromDds(); |
|
59 | + if ($object) { |
|
60 | + $object->updateFromDds(); |
|
61 | + } |
|
60 | 62 | return $object; |
61 | 63 | } |
62 | 64 |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * values can be changed if they were changed in the Daedalus definition |
29 | 29 | * @param type $definition |
30 | 30 | */ |
31 | - protected function updateDefinitionFromDds($definition, $includeAll=false) |
|
31 | + protected function updateDefinitionFromDds($definition, $includeAll = false) |
|
32 | 32 | { |
33 | 33 | if (!empty($definition['renderables'])) { |
34 | 34 | $classes = $this->getDdsClassDefinitions($definition); |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | } |
163 | 163 | } |
164 | 164 | } |
165 | - if (count($newClassTypes)>0) { |
|
165 | + if (count($newClassTypes) > 0) { |
|
166 | 166 | $newClasses = $this->ddsPhoebe()->getClasses($newClassTypes); |
167 | 167 | foreach ($newClasses as $newClass) { |
168 | 168 | $requestedClasses[$newClass->class_type] = $newClass; |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | if (!isset($memberDefinition['definition'][$key]) || ($memberDefinition['definition'][$key] != $value)) |
186 | 186 | $differences[$key] = $value; |
187 | 187 | } |
188 | - $renderable['changes']=$differences; |
|
188 | + $renderable['changes'] = $differences; |
|
189 | 189 | } |
190 | 190 | } |
191 | 191 | } |
@@ -198,10 +198,10 @@ discard block |
||
198 | 198 | protected function sanitiseDefinition(&$definition) |
199 | 199 | { |
200 | 200 | /** Remove Orphaned Renderables **/ |
201 | - $items = [ $definition['rootNode'] ]; |
|
201 | + $items = [$definition['rootNode']]; |
|
202 | 202 | foreach ($definition['renderables'] as $renderable) { |
203 | 203 | if (isset($renderable['items'])) { |
204 | - $items = array_merge($items,$renderable['items']); |
|
204 | + $items = array_merge($items, $renderable['items']); |
|
205 | 205 | } |
206 | 206 | } |
207 | 207 | // remove renderables not linked via rootNode |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | $uuid64s[] = Hash::uuid2uuid64($key); |
229 | 229 | } |
230 | 230 | $serialised = str_replace($keys, $uuid64s, $serialised); |
231 | - $definition = json_decode($serialised,true); |
|
231 | + $definition = json_decode($serialised, true); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | private function ddsPhoebe() |
@@ -54,8 +54,9 @@ discard block |
||
54 | 54 | */ |
55 | 55 | protected function replaceDefinitionFromDds($definition) |
56 | 56 | { |
57 | - if (empty($definition)) |
|
58 | - return []; |
|
57 | + if (empty($definition)) { |
|
58 | + return []; |
|
59 | + } |
|
59 | 60 | |
60 | 61 | $classes = $this->getDdsClassDefinitions($definition); |
61 | 62 | foreach ($definition['renderables'] as &$renderable) { |
@@ -100,8 +101,9 @@ discard block |
||
100 | 101 | $parentClassId = null; |
101 | 102 | if (isset($r['parentClassId'])) { |
102 | 103 | $parentClassId = $r['parentClassId']; |
103 | - if (!in_array($r['parentClassId'], $renderableKeys)) |
|
104 | - $parentClassId = $this->findParentClassIdFromType($r['parentClassId'], $definition['renderables']); |
|
104 | + if (!in_array($r['parentClassId'], $renderableKeys)) { |
|
105 | + $parentClassId = $this->findParentClassIdFromType($r['parentClassId'], $definition['renderables']); |
|
106 | + } |
|
105 | 107 | } |
106 | 108 | $r['relations'] = [ |
107 | 109 | [ |
@@ -117,8 +119,9 @@ discard block |
||
117 | 119 | protected function findParentClassIdFromType($type, $renderables) |
118 | 120 | { |
119 | 121 | foreach ($renderables as $r) { |
120 | - if ($this->isClass($r) && $r['class_type'] == $type) |
|
121 | - return $r['id']; |
|
122 | + if ($this->isClass($r) && $r['class_type'] == $type) { |
|
123 | + return $r['id']; |
|
124 | + } |
|
122 | 125 | } |
123 | 126 | // can't find it so return the original so as not to break anything |
124 | 127 | return $type; |
@@ -169,8 +172,9 @@ discard block |
||
169 | 172 | } |
170 | 173 | } |
171 | 174 | $definitions = []; |
172 | - foreach ($requiredClassTypes as $rct) |
|
173 | - $definitions[$rct] = isset($requestedClasses[$rct]) ? $requestedClasses[$rct]->definition : null; |
|
175 | + foreach ($requiredClassTypes as $rct) { |
|
176 | + $definitions[$rct] = isset($requestedClasses[$rct]) ? $requestedClasses[$rct]->definition : null; |
|
177 | + } |
|
174 | 178 | return $definitions; |
175 | 179 | } |
176 | 180 | |
@@ -182,8 +186,9 @@ discard block |
||
182 | 186 | $memberDefinition = $classes[$renderable['class_type']]['fields'][$renderable['member_ref']]; |
183 | 187 | $differences = []; |
184 | 188 | foreach ($renderDefinition as $key=>$value) { |
185 | - if (!isset($memberDefinition['definition'][$key]) || ($memberDefinition['definition'][$key] != $value)) |
|
186 | - $differences[$key] = $value; |
|
189 | + if (!isset($memberDefinition['definition'][$key]) || ($memberDefinition['definition'][$key] != $value)) { |
|
190 | + $differences[$key] = $value; |
|
191 | + } |
|
187 | 192 | } |
188 | 193 | $renderable['changes']=$differences; |
189 | 194 | } |
@@ -233,8 +238,9 @@ discard block |
||
233 | 238 | |
234 | 239 | private function ddsPhoebe() |
235 | 240 | { |
236 | - if (!$this->_ddsPhoebe) |
|
237 | - $this->_ddsPhoebe = neon('phoebe')->getIPhoebeType('daedalus'); |
|
241 | + if (!$this->_ddsPhoebe) { |
|
242 | + $this->_ddsPhoebe = neon('phoebe')->getIPhoebeType('daedalus'); |
|
243 | + } |
|
238 | 244 | return $this->_ddsPhoebe; |
239 | 245 | } |
240 | 246 | private $_ddsPhoebe = null; |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | /** |
122 | 122 | * @inheritdoc |
123 | 123 | */ |
124 | - public function setOverride($overrideUuid, $force=false) |
|
124 | + public function setOverride($overrideUuid, $force = false) |
|
125 | 125 | { |
126 | 126 | // don't override an override unless forced to do so |
127 | 127 | if (!$force && $this->override_uuid) |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | /** |
151 | 151 | * @inheritdoc |
152 | 152 | */ |
153 | - public function listHistory(&$paginator=[]) |
|
153 | + public function listHistory(&$paginator = []) |
|
154 | 154 | { |
155 | 155 | // check the inputs |
156 | 156 | $paginator = $this->createPaginator($paginator); |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | $query = ObjectHistoryModel::find() |
159 | 159 | ->where(['object_uuid' => $this->uuid]); |
160 | 160 | |
161 | - if ($paginator['start']==0) |
|
161 | + if ($paginator['start'] == 0) |
|
162 | 162 | $paginator['total'] = $query->count(); |
163 | 163 | |
164 | 164 | // and get the results |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | $hmodel->override_uuid = $this->override_uuid; |
238 | 238 | $hmodel->serialised_data = $this->serialised_data; |
239 | 239 | if (!$hmodel->save()) |
240 | - throw new \RuntimeException("Failed to save the history of the object. Model errors were ".print_r($hmodel->errors,true)); |
|
240 | + throw new \RuntimeException("Failed to save the history of the object. Model errors were ".print_r($hmodel->errors, true)); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | } |
244 | 244 | \ No newline at end of file |
@@ -42,15 +42,17 @@ discard block |
||
42 | 42 | // NOTE - changes are only saved into $this->data and not |
43 | 43 | // to the phoebe object in general. |
44 | 44 | |
45 | - if (empty($changes) || $changes == $this->data) |
|
46 | - return true; |
|
45 | + if (empty($changes) || $changes == $this->data) { |
|
46 | + return true; |
|
47 | + } |
|
47 | 48 | |
48 | 49 | // Get the associated class object |
49 | 50 | $classType = $this->getClassType(); |
50 | 51 | $class = $this->getClassModel($classType); |
51 | 52 | |
52 | - if (!$class) |
|
53 | - throw new \RuntimeException("Class of type '$classType' not found. Can't save objects of unknown types"); |
|
53 | + if (!$class) { |
|
54 | + throw new \RuntimeException("Class of type '$classType' not found. Can't save objects of unknown types"); |
|
55 | + } |
|
54 | 56 | |
55 | 57 | // save the history object |
56 | 58 | if ($class->object_history) { |
@@ -58,15 +60,17 @@ discard block |
||
58 | 60 | } |
59 | 61 | |
60 | 62 | // update the version if the class is not version locked |
61 | - if (!$class->version_locked) |
|
62 | - $this->version = $class->version; |
|
63 | + if (!$class->version_locked) { |
|
64 | + $this->version = $class->version; |
|
65 | + } |
|
63 | 66 | |
64 | 67 | // merge the changes and save the model |
65 | 68 | $this->data = $changes; |
66 | 69 | $this->updated = date('Y-m-d H:i:s'); |
67 | 70 | $model = $this->getModel(); |
68 | - if (!$model->save()) |
|
69 | - return $model->errors; |
|
71 | + if (!$model->save()) { |
|
72 | + return $model->errors; |
|
73 | + } |
|
70 | 74 | return true; |
71 | 75 | } |
72 | 76 | |
@@ -124,8 +128,9 @@ discard block |
||
124 | 128 | public function setOverride($overrideUuid, $force=false) |
125 | 129 | { |
126 | 130 | // don't override an override unless forced to do so |
127 | - if (!$force && $this->override_uuid) |
|
128 | - return false; |
|
131 | + if (!$force && $this->override_uuid) { |
|
132 | + return false; |
|
133 | + } |
|
129 | 134 | |
130 | 135 | // Get the associated class object and check the override applies to this class |
131 | 136 | if ($this->getClassOverrideModel($overrideUuid, $this->version)) { |
@@ -158,8 +163,9 @@ discard block |
||
158 | 163 | $query = ObjectHistoryModel::find() |
159 | 164 | ->where(['object_uuid' => $this->uuid]); |
160 | 165 | |
161 | - if ($paginator['start']==0) |
|
162 | - $paginator['total'] = $query->count(); |
|
166 | + if ($paginator['start']==0) { |
|
167 | + $paginator['total'] = $query->count(); |
|
168 | + } |
|
163 | 169 | |
164 | 170 | // and get the results |
165 | 171 | return $query->offset($paginator['start']) |
@@ -236,8 +242,9 @@ discard block |
||
236 | 242 | $hmodel->version = $this->version; |
237 | 243 | $hmodel->override_uuid = $this->override_uuid; |
238 | 244 | $hmodel->serialised_data = $this->serialised_data; |
239 | - if (!$hmodel->save()) |
|
240 | - throw new \RuntimeException("Failed to save the history of the object. Model errors were ".print_r($hmodel->errors,true)); |
|
245 | + if (!$hmodel->save()) { |
|
246 | + throw new \RuntimeException("Failed to save the history of the object. Model errors were ".print_r($hmodel->errors,true)); |
|
247 | + } |
|
241 | 248 | } |
242 | 249 | |
243 | 250 | } |
244 | 251 | \ No newline at end of file |
@@ -70,10 +70,11 @@ discard block |
||
70 | 70 | public function beforeSave($insert) |
71 | 71 | { |
72 | 72 | // data can only be an array and are stored as JSON |
73 | - if (is_array($this->data) && count($this->data)) |
|
74 | - $this->serialised_data = json_encode($this->data); |
|
75 | - else |
|
76 | - $this->serialised_data = null; |
|
73 | + if (is_array($this->data) && count($this->data)) { |
|
74 | + $this->serialised_data = json_encode($this->data); |
|
75 | + } else { |
|
76 | + $this->serialised_data = null; |
|
77 | + } |
|
77 | 78 | return parent::beforeSave($insert); |
78 | 79 | } |
79 | 80 | |
@@ -83,8 +84,9 @@ discard block |
||
83 | 84 | public function afterFind() |
84 | 85 | { |
85 | 86 | // return data as decoded json or null |
86 | - if (is_string($this->serialised_data)) |
|
87 | - $this->data = json_decode($this->serialised_data, true); |
|
87 | + if (is_string($this->serialised_data)) { |
|
88 | + $this->data = json_decode($this->serialised_data, true); |
|
89 | + } |
|
88 | 90 | parent::afterFind(); |
89 | 91 | } |
90 | 92 | |
@@ -101,14 +103,17 @@ discard block |
||
101 | 103 | } |
102 | 104 | $query = PhoebeObject::find()->select(['phoebe_object.uuid', 'phoebe_class.label']) |
103 | 105 | ->leftJoin('phoebe_class', 'phoebe_class.phoebe_type=phoebe_object.phoebe_type AND phoebe_class.class_type=phoebe_object.class_type'); |
104 | - if (!empty($query)) |
|
105 | - $query->where(['like', 'phoebe_class.label', $query]); |
|
106 | - if (count($filters)) |
|
107 | - $query->andWhere($filters); |
|
106 | + if (!empty($query)) { |
|
107 | + $query->where(['like', 'phoebe_class.label', $query]); |
|
108 | + } |
|
109 | + if (count($filters)) { |
|
110 | + $query->andWhere($filters); |
|
111 | + } |
|
108 | 112 | $objects = $query->orderBy('phoebe_class.label')->asArray()->all(); |
109 | 113 | $results = []; |
110 | - foreach ($objects as $object) |
|
111 | - $results[$object['uuid']] = "$object[label]: $object[uuid]"; |
|
114 | + foreach ($objects as $object) { |
|
115 | + $results[$object['uuid']] = "$object[label]: $object[uuid]"; |
|
116 | + } |
|
112 | 117 | return $results; |
113 | 118 | } |
114 | 119 | } |
@@ -121,7 +121,7 @@ |
||
121 | 121 | /** |
122 | 122 | * @inheritdoc |
123 | 123 | */ |
124 | - public function toArray(array $fields=[], array $expand=[], $recursive=true) |
|
124 | + public function toArray(array $fields = [], array $expand = [], $recursive = true) |
|
125 | 125 | { |
126 | 126 | $data = parent::toArray($fields, $expand, $recursive); |
127 | 127 | unset($data['serialised_overrides']); |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | { |
100 | 100 | // active_from must be set |
101 | 101 | // overrides can only be an array and are stored as JSON or already JSON |
102 | - if (is_array($this->overrides) && count($this->overrides)) |
|
103 | - $this->serialised_overrides = json_encode($this->overrides); |
|
104 | - else { |
|
102 | + if (is_array($this->overrides) && count($this->overrides)) { |
|
103 | + $this->serialised_overrides = json_encode($this->overrides); |
|
104 | + } else { |
|
105 | 105 | $this->serialised_overrides = null; |
106 | 106 | } |
107 | 107 | return parent::beforeSave($insert); |
@@ -113,8 +113,9 @@ discard block |
||
113 | 113 | public function afterFind() |
114 | 114 | { |
115 | 115 | // return overrides as decoded json or null |
116 | - if (is_string($this->serialised_overrides)) |
|
117 | - $this->overrides = json_decode($this->serialised_overrides, true); |
|
116 | + if (is_string($this->serialised_overrides)) { |
|
117 | + $this->overrides = json_decode($this->serialised_overrides, true); |
|
118 | + } |
|
118 | 119 | parent::afterFind(); |
119 | 120 | } |
120 | 121 |
@@ -103,7 +103,7 @@ |
||
103 | 103 | parent::afterFind(); |
104 | 104 | } |
105 | 105 | |
106 | - public function toArray(array $fields=[], array $expand=[], $recursive=true) |
|
106 | + public function toArray(array $fields = [], array $expand = [], $recursive = true) |
|
107 | 107 | { |
108 | 108 | $data = parent::toArray($fields, $expand, $recursive); |
109 | 109 | unset($data['serialised_definition']); |
@@ -84,9 +84,9 @@ discard block |
||
84 | 84 | public function beforeSave($insert) |
85 | 85 | { |
86 | 86 | // definition can only be an array and are stored as JSON or already JSON |
87 | - if (is_array($this->definition) && count($this->definition)) |
|
88 | - $this->serialised_definition = json_encode($this->definition); |
|
89 | - else { |
|
87 | + if (is_array($this->definition) && count($this->definition)) { |
|
88 | + $this->serialised_definition = json_encode($this->definition); |
|
89 | + } else { |
|
90 | 90 | $this->serialised_definition = null; |
91 | 91 | } |
92 | 92 | return parent::beforeSave($insert); |
@@ -98,8 +98,9 @@ discard block |
||
98 | 98 | public function afterFind() |
99 | 99 | { |
100 | 100 | // return definition as decoded json or null |
101 | - if (is_string($this->serialised_definition)) |
|
102 | - $this->definition = json_decode($this->serialised_definition, true); |
|
101 | + if (is_string($this->serialised_definition)) { |
|
102 | + $this->definition = json_decode($this->serialised_definition, true); |
|
103 | + } |
|
103 | 104 | parent::afterFind(); |
104 | 105 | } |
105 | 106 | |
@@ -120,14 +121,17 @@ discard block |
||
120 | 121 | public static function listClassTypes($query, $filters) |
121 | 122 | { |
122 | 123 | $query = PhoebeClass::find()->select(['class_type', 'label']); |
123 | - if (!empty($query)) |
|
124 | - $query->where(['like', 'label', $query]); |
|
125 | - if (count($filters)) |
|
126 | - $query->where($filters); |
|
124 | + if (!empty($query)) { |
|
125 | + $query->where(['like', 'label', $query]); |
|
126 | + } |
|
127 | + if (count($filters)) { |
|
128 | + $query->where($filters); |
|
129 | + } |
|
127 | 130 | $classes = $query->orderBy('label')->asArray()->all(); |
128 | 131 | $results = []; |
129 | - foreach ($classes as $class) |
|
130 | - $results[$class['class_type']] = $class['label']; |
|
132 | + foreach ($classes as $class) { |
|
133 | + $results[$class['class_type']] = $class['label']; |
|
134 | + } |
|
131 | 135 | return $results; |
132 | 136 | } |
133 | 137 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | ] |
61 | 61 | ]; |
62 | 62 | foreach ($additionalColumns as $column) { |
63 | - switch($column) { |
|
63 | + switch ($column) { |
|
64 | 64 | case 'data': |
65 | 65 | $definition['serialised_data'] = [ |
66 | 66 | 'class' => 'neon\core\grid\column\DefinitionColumn', |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | // if we are locking objects to versions then an increase in version needs to |
97 | 97 | // result in a new row in the phoebeClass relation regardless of changes |
98 | 98 | $hasChanges = false; |
99 | - $newModel=false; |
|
99 | + $newModel = false; |
|
100 | 100 | try { |
101 | 101 | if ($model->version_locked && isset($changes['version']) && $changes['version'] != $model->version) { |
102 | 102 | $newModel = true; |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | $model->attributes = array_merge($oldAttrs, $changes); |
105 | 105 | $model->updated = date('Y-m-d H:i:s'); |
106 | 106 | if (!$model->save()) |
107 | - throw new \RuntimeException('Save failed with the following errors '.print_r($model->errors,true)); |
|
107 | + throw new \RuntimeException('Save failed with the following errors '.print_r($model->errors, true)); |
|
108 | 108 | $this->setModel($model); |
109 | 109 | $hasChanges = true; |
110 | 110 | } else { |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | if ($hasChanges) { |
119 | 119 | $model->updated = date('Y-m-d H:i:s'); |
120 | 120 | if (!$model->save()) { |
121 | - throw new \RuntimeException('Save failed with the following errors: '.print_r($model->errors,true)); |
|
121 | + throw new \RuntimeException('Save failed with the following errors: '.print_r($model->errors, true)); |
|
122 | 122 | } |
123 | 123 | } |
124 | 124 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | { |
140 | 140 | $model = $this->getModel(); |
141 | 141 | $oldAttrs = $model->attributes; |
142 | - if (($result=$this->modelDelete()) === true) { |
|
142 | + if (($result = $this->modelDelete()) === true) { |
|
143 | 143 | $newAttrs = $model->attributes; |
144 | 144 | $this->createEditClassMigration($newAttrs, $oldAttrs, false); |
145 | 145 | } |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | { |
154 | 154 | $model = $this->getModel(); |
155 | 155 | $oldAttrs = $model->attributes; |
156 | - if (($result=$this->modelUndelete()) === true) { |
|
156 | + if (($result = $this->modelUndelete()) === true) { |
|
157 | 157 | $newAttrs = $model->attributes; |
158 | 158 | $this->createEditClassMigration($newAttrs, $oldAttrs, false); |
159 | 159 | } |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | * Set any overrides onto the class |
200 | 200 | * @var array |
201 | 201 | */ |
202 | - protected $_overrides=null; |
|
202 | + protected $_overrides = null; |
|
203 | 203 | |
204 | 204 | /** |
205 | 205 | * @inheritdoc |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | /** |
259 | 259 | * @inheritdoc |
260 | 260 | */ |
261 | - public function findOverride($filters=[]) |
|
261 | + public function findOverride($filters = []) |
|
262 | 262 | { |
263 | 263 | return $this->findClassOverride($filters); |
264 | 264 | } |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | /** |
287 | 287 | * @inheritdoc |
288 | 288 | */ |
289 | - public function addOverride($label, $selector='', $activeFrom=null, $activeTo=null, $isActive=true) |
|
289 | + public function addOverride($label, $selector = '', $activeFrom = null, $activeTo = null, $isActive = true) |
|
290 | 290 | { |
291 | 291 | $uuid = Hash::uuid64(); |
292 | 292 | $model = $this->getModel(); |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | ); |
321 | 321 | |
322 | 322 | // nothing to see here move along |
323 | - if (count($changes)===0) |
|
323 | + if (count($changes) === 0) |
|
324 | 324 | return true; |
325 | 325 | // ok now do the edit |
326 | 326 | $override = $this->getClassOverrideModel($uuid); |
@@ -103,8 +103,9 @@ discard block |
||
103 | 103 | $model = new ClassModel(); |
104 | 104 | $model->attributes = array_merge($oldAttrs, $changes); |
105 | 105 | $model->updated = date('Y-m-d H:i:s'); |
106 | - if (!$model->save()) |
|
107 | - throw new \RuntimeException('Save failed with the following errors '.print_r($model->errors,true)); |
|
106 | + if (!$model->save()) { |
|
107 | + throw new \RuntimeException('Save failed with the following errors '.print_r($model->errors,true)); |
|
108 | + } |
|
108 | 109 | $this->setModel($model); |
109 | 110 | $hasChanges = true; |
110 | 111 | } else { |
@@ -127,8 +128,9 @@ discard block |
||
127 | 128 | $model->attributes = $oldAttrs; |
128 | 129 | return $errors; |
129 | 130 | } |
130 | - if ($hasChanges) |
|
131 | - $this->createEditClassMigration($model->attributes, $oldAttrs, $newModel); |
|
131 | + if ($hasChanges) { |
|
132 | + $this->createEditClassMigration($model->attributes, $oldAttrs, $newModel); |
|
133 | + } |
|
132 | 134 | return $hasChanges; |
133 | 135 | } |
134 | 136 | |
@@ -216,10 +218,11 @@ discard block |
||
216 | 218 | { |
217 | 219 | if ($overrideUuid) { |
218 | 220 | $override = $this->getOverride($overrideUuid); |
219 | - if (isset($override['overrides'])) |
|
220 | - $this->applyClassOverrideByDefinition($override['overrides']); |
|
221 | - else |
|
222 | - $this->applyClassOverrideByDefinition([]); |
|
221 | + if (isset($override['overrides'])) { |
|
222 | + $this->applyClassOverrideByDefinition($override['overrides']); |
|
223 | + } else { |
|
224 | + $this->applyClassOverrideByDefinition([]); |
|
225 | + } |
|
223 | 226 | } |
224 | 227 | } |
225 | 228 | |
@@ -250,8 +253,9 @@ discard block |
||
250 | 253 | 'deleted' => 0 |
251 | 254 | ])->asArray()->all(); |
252 | 255 | $list = []; |
253 | - foreach ($overrides as $o) |
|
254 | - $list[$o['uuid']] = $o['label']; |
|
256 | + foreach ($overrides as $o) { |
|
257 | + $list[$o['uuid']] = $o['label']; |
|
258 | + } |
|
255 | 259 | return $list; |
256 | 260 | } |
257 | 261 | |
@@ -303,8 +307,9 @@ discard block |
||
303 | 307 | $override->created = date('Y-m-d H:i:s'); |
304 | 308 | $override->deleted = 0; |
305 | 309 | $override->overrides = []; |
306 | - if ($override->save()) |
|
307 | - return $uuid; |
|
310 | + if ($override->save()) { |
|
311 | + return $uuid; |
|
312 | + } |
|
308 | 313 | return $override->errors; |
309 | 314 | } |
310 | 315 | |
@@ -320,18 +325,21 @@ discard block |
||
320 | 325 | ); |
321 | 326 | |
322 | 327 | // nothing to see here move along |
323 | - if (count($changes)===0) |
|
324 | - return true; |
|
328 | + if (count($changes)===0) { |
|
329 | + return true; |
|
330 | + } |
|
325 | 331 | // ok now do the edit |
326 | 332 | $override = $this->getClassOverrideModel($uuid); |
327 | 333 | if ($override) { |
328 | 334 | foreach ($changes as $key=>$value) { |
329 | - if ($key == 'active_from') |
|
330 | - $value = $this->setDateToNowOnEmpty($value); |
|
335 | + if ($key == 'active_from') { |
|
336 | + $value = $this->setDateToNowOnEmpty($value); |
|
337 | + } |
|
331 | 338 | $override->$key = $value; |
332 | 339 | } |
333 | - if ($override->save()) |
|
334 | - return true; |
|
340 | + if ($override->save()) { |
|
341 | + return true; |
|
342 | + } |
|
335 | 343 | return $override->errors; |
336 | 344 | } |
337 | 345 | return false; |
@@ -367,8 +375,9 @@ discard block |
||
367 | 375 | public function destroyOverride($uuid) |
368 | 376 | { |
369 | 377 | $override = $this->getClassOverrideModel($uuid); |
370 | - if ($override) |
|
371 | - $override->delete(); |
|
378 | + if ($override) { |
|
379 | + $override->delete(); |
|
380 | + } |
|
372 | 381 | } |
373 | 382 | |
374 | 383 | |
@@ -383,8 +392,9 @@ discard block |
||
383 | 392 | public function getDefinition() |
384 | 393 | { |
385 | 394 | $definition = $this->getModel()->definition; |
386 | - if ($this->_overrides) |
|
387 | - $definition = array_replace_recursive($definition, $this->_overrides); |
|
395 | + if ($this->_overrides) { |
|
396 | + $definition = array_replace_recursive($definition, $this->_overrides); |
|
397 | + } |
|
388 | 398 | return $definition; |
389 | 399 | } |
390 | 400 | |
@@ -399,8 +409,9 @@ discard block |
||
399 | 409 | $classType = $this->getClassType(); |
400 | 410 | |
401 | 411 | // don't do this unless we know definitely what we are |
402 | - if (!$phoebeType || !$classType) |
|
403 | - return; |
|
412 | + if (!$phoebeType || !$classType) { |
|
413 | + return; |
|
414 | + } |
|
404 | 415 | |
405 | 416 | // clear out any override objects |
406 | 417 | OverridesModel::deleteAll([ |
@@ -430,8 +441,9 @@ discard block |
||
430 | 441 | protected function createEditClassMigration($newAttrs, $oldAttrs, $newModel) |
431 | 442 | { |
432 | 443 | // check to make sure the changes are real and need to be saved as a migration |
433 | - if (!($newModel || $this->hasChanges($newAttrs, $oldAttrs))) |
|
434 | - return; |
|
444 | + if (!($newModel || $this->hasChanges($newAttrs, $oldAttrs))) { |
|
445 | + return; |
|
446 | + } |
|
435 | 447 | |
436 | 448 | $up = $this->getTableRowReplaceSql('phoebe_class', $newAttrs); |
437 | 449 | $down = ''; |
@@ -30,12 +30,12 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * @inheritdoc |
32 | 32 | */ |
33 | - public function listClasses(&$paginator=[], $filters=[], $orderBy=[], $includeDeleted=false) |
|
33 | + public function listClasses(&$paginator = [], $filters = [], $orderBy = [], $includeDeleted = false) |
|
34 | 34 | { |
35 | 35 | // check the inputs |
36 | 36 | $paginator = $this->createPaginator($paginator); |
37 | - $orderBy = count($orderBy)>0 ? $orderBy : 'label ASC'; |
|
38 | - $filters = array_intersect_key($filters, array_flip(['class_type','label','description','module'])); |
|
37 | + $orderBy = count($orderBy) > 0 ? $orderBy : 'label ASC'; |
|
38 | + $filters = array_intersect_key($filters, array_flip(['class_type', 'label', 'description', 'module'])); |
|
39 | 39 | if (isset($filters['class_type'])) |
40 | 40 | $filters['class_type'] = $this->canonicaliseRef($filters['class_type']); |
41 | 41 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | $query->select($select); |
64 | 64 | foreach ($filters as $key=>$value) |
65 | 65 | $query->andWhere(['like', "p1.$key", $value]); |
66 | - if ($paginator['start']==0) |
|
66 | + if ($paginator['start'] == 0) |
|
67 | 67 | $paginator['total'] = $query->count(); |
68 | 68 | |
69 | 69 | // and get the results |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | /** |
83 | 83 | * @inheritdoc |
84 | 84 | */ |
85 | - public function addClass(&$classType, $module='') |
|
85 | + public function addClass(&$classType, $module = '') |
|
86 | 86 | { |
87 | 87 | $classType = $this->canonicaliseRef($classType); |
88 | 88 | if (empty($classType)) |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | /** |
107 | 107 | * @inheritdoc |
108 | 108 | */ |
109 | - public function getClass($classType, $version=null, $classOverrideCriteria=[]) |
|
109 | + public function getClass($classType, $version = null, $classOverrideCriteria = []) |
|
110 | 110 | { |
111 | 111 | $classType = $this->canonicaliseRef($classType); |
112 | 112 | if (empty($classType)) |
@@ -161,20 +161,20 @@ discard block |
||
161 | 161 | /** |
162 | 162 | * @inheritdoc |
163 | 163 | */ |
164 | - public function listObjects($classType, &$paginator=[], $filters=[], $orderBy=[], $additionalFields=[]) |
|
164 | + public function listObjects($classType, &$paginator = [], $filters = [], $orderBy = [], $additionalFields = []) |
|
165 | 165 | { |
166 | 166 | |
167 | 167 | // check the inputs |
168 | 168 | $classType = $this->canonicaliseRef($classType); |
169 | 169 | $paginator = $this->createPaginator($paginator); |
170 | - $orderBy = count($orderBy)>0 ? $orderBy : 'created DESC'; |
|
171 | - $filters = array_intersect_key($filters, array_flip(['version','created','updated'])); |
|
170 | + $orderBy = count($orderBy) > 0 ? $orderBy : 'created DESC'; |
|
171 | + $filters = array_intersect_key($filters, array_flip(['version', 'created', 'updated'])); |
|
172 | 172 | |
173 | 173 | $query = ObjectModel::find()->where([ |
174 | 174 | 'phoebe_type' => $this->getPhoebeType(), |
175 | 175 | 'class_type' => $classType |
176 | 176 | ]); |
177 | - $select = ['uuid','phoebe_type','class_type','version','created','updated']; |
|
177 | + $select = ['uuid', 'phoebe_type', 'class_type', 'version', 'created', 'updated']; |
|
178 | 178 | |
179 | 179 | if (in_array('data', $additionalFields)) |
180 | 180 | $select[] = 'serialised_data'; |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | |
188 | 188 | foreach ($filters as $key=>$value) |
189 | 189 | $query->andWhere(['=', $key, $value]); |
190 | - if ($paginator['start']==0) |
|
190 | + if ($paginator['start'] == 0) |
|
191 | 191 | $paginator['total'] = $query->count(); |
192 | 192 | // and get the results |
193 | 193 | return $query->offset($paginator['start']) |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | /** |
201 | 201 | * @inheritdoc |
202 | 202 | */ |
203 | - public function addObject($classType, $classOverrideCriteria=[]) |
|
203 | + public function addObject($classType, $classOverrideCriteria = []) |
|
204 | 204 | { |
205 | 205 | $class = $this->getClassFromType($classType); |
206 | 206 | |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | * created automatically or if false then it is left as null. |
308 | 308 | * @return neon\phoebe\services\adapters\common\models\PhoebeObject |
309 | 309 | */ |
310 | - protected function createPhoebeObjectModel($classType, $uuid=null) |
|
310 | + protected function createPhoebeObjectModel($classType, $uuid = null) |
|
311 | 311 | { |
312 | 312 | // create a model for the class |
313 | 313 | $model = new ObjectModel(); |
@@ -36,8 +36,9 @@ discard block |
||
36 | 36 | $paginator = $this->createPaginator($paginator); |
37 | 37 | $orderBy = count($orderBy)>0 ? $orderBy : 'label ASC'; |
38 | 38 | $filters = array_intersect_key($filters, array_flip(['class_type','label','description','module'])); |
39 | - if (isset($filters['class_type'])) |
|
40 | - $filters['class_type'] = $this->canonicaliseRef($filters['class_type']); |
|
39 | + if (isset($filters['class_type'])) { |
|
40 | + $filters['class_type'] = $this->canonicaliseRef($filters['class_type']); |
|
41 | + } |
|
41 | 42 | |
42 | 43 | /* |
43 | 44 | * This slightly unusual query according to MySQL is an efficient way to find the highest version of |
@@ -61,10 +62,12 @@ discard block |
||
61 | 62 | $query->andWhere(['p1.deleted'=>0]); |
62 | 63 | } |
63 | 64 | $query->select($select); |
64 | - foreach ($filters as $key=>$value) |
|
65 | - $query->andWhere(['like', "p1.$key", $value]); |
|
66 | - if ($paginator['start']==0) |
|
67 | - $paginator['total'] = $query->count(); |
|
65 | + foreach ($filters as $key=>$value) { |
|
66 | + $query->andWhere(['like', "p1.$key", $value]); |
|
67 | + } |
|
68 | + if ($paginator['start']==0) { |
|
69 | + $paginator['total'] = $query->count(); |
|
70 | + } |
|
68 | 71 | |
69 | 72 | // and get the results |
70 | 73 | $results = $query->offset($paginator['start']) |
@@ -74,8 +77,9 @@ discard block |
||
74 | 77 | |
75 | 78 | // finally index them by the class_type as this is useful for changes in other classes |
76 | 79 | $return = []; |
77 | - foreach ($results as $r) |
|
78 | - $return[$r['class_type']] = $r; |
|
80 | + foreach ($results as $r) { |
|
81 | + $return[$r['class_type']] = $r; |
|
82 | + } |
|
79 | 83 | return $return; |
80 | 84 | } |
81 | 85 | |
@@ -85,8 +89,9 @@ discard block |
||
85 | 89 | public function addClass(&$classType, $module='') |
86 | 90 | { |
87 | 91 | $classType = $this->canonicaliseRef($classType); |
88 | - if (empty($classType)) |
|
89 | - throw new \RuntimeException("Invalid classType $classType"); |
|
92 | + if (empty($classType)) { |
|
93 | + throw new \RuntimeException("Invalid classType $classType"); |
|
94 | + } |
|
90 | 95 | |
91 | 96 | // create a model for the class |
92 | 97 | $model = $this->createPhoebeClassModel($classType, $module); |
@@ -94,8 +99,9 @@ discard block |
||
94 | 99 | try { |
95 | 100 | if ($model->save()) { |
96 | 101 | $class = $this->createIPhoebeClass($model); |
97 | - } else |
|
98 | - throw new \Exception('Errors on save'); |
|
102 | + } else { |
|
103 | + throw new \Exception('Errors on save'); |
|
104 | + } |
|
99 | 105 | } catch (\Exception $e) { |
100 | 106 | throw new \RuntimeException('Failed to create model. Exception was "'.$e->getMessage().'". Model errors were '.print_r($model->errors, true)); |
101 | 107 | } |
@@ -109,16 +115,18 @@ discard block |
||
109 | 115 | public function getClass($classType, $version=null, $classOverrideCriteria=[]) |
110 | 116 | { |
111 | 117 | $classType = $this->canonicaliseRef($classType); |
112 | - if (empty($classType)) |
|
113 | - return null; |
|
118 | + if (empty($classType)) { |
|
119 | + return null; |
|
120 | + } |
|
114 | 121 | |
115 | 122 | $model = $this->getClassModel($classType, $version); |
116 | 123 | if ($model) { |
117 | 124 | $class = $this->createIPhoebeClass($model); |
118 | 125 | if ($classOverrideCriteria !== false) { |
119 | 126 | $override = $class->findClassOverride($classOverrideCriteria); |
120 | - if ($override) |
|
121 | - $class->applyClassOverrideByDefinition($override['overrides']); |
|
127 | + if ($override) { |
|
128 | + $class->applyClassOverrideByDefinition($override['overrides']); |
|
129 | + } |
|
122 | 130 | } |
123 | 131 | return $class; |
124 | 132 | } |
@@ -132,8 +140,9 @@ discard block |
||
132 | 140 | { |
133 | 141 | $models = $this->getClassModels($classTypes); |
134 | 142 | $classes = array(); |
135 | - foreach ($models as $type => $model) |
|
136 | - $classes[$type] = $model ? $this->createIPhoebeClass($model) : null; |
|
143 | + foreach ($models as $type => $model) { |
|
144 | + $classes[$type] = $model ? $this->createIPhoebeClass($model) : null; |
|
145 | + } |
|
137 | 146 | return $classes; |
138 | 147 | } |
139 | 148 | |
@@ -176,8 +185,9 @@ discard block |
||
176 | 185 | ]); |
177 | 186 | $select = ['uuid','phoebe_type','class_type','version','created','updated']; |
178 | 187 | |
179 | - if (in_array('data', $additionalFields)) |
|
180 | - $select[] = 'serialised_data'; |
|
188 | + if (in_array('data', $additionalFields)) { |
|
189 | + $select[] = 'serialised_data'; |
|
190 | + } |
|
181 | 191 | if (in_array('deleted', $additionalFields)) { |
182 | 192 | $select[] = 'deleted'; |
183 | 193 | } else { |
@@ -185,10 +195,12 @@ discard block |
||
185 | 195 | } |
186 | 196 | $query->select($select); |
187 | 197 | |
188 | - foreach ($filters as $key=>$value) |
|
189 | - $query->andWhere(['=', $key, $value]); |
|
190 | - if ($paginator['start']==0) |
|
191 | - $paginator['total'] = $query->count(); |
|
198 | + foreach ($filters as $key=>$value) { |
|
199 | + $query->andWhere(['=', $key, $value]); |
|
200 | + } |
|
201 | + if ($paginator['start']==0) { |
|
202 | + $paginator['total'] = $query->count(); |
|
203 | + } |
|
192 | 204 | // and get the results |
193 | 205 | return $query->offset($paginator['start']) |
194 | 206 | ->limit($paginator['length']) |
@@ -215,13 +227,15 @@ discard block |
||
215 | 227 | // work out what class override needs to be applied |
216 | 228 | if ($classOverrideCriteria !== false) { |
217 | 229 | $override = $phoebeObject->findClassOverride($classOverrideCriteria, ['uuid']); |
218 | - if ($override) |
|
219 | - $model->override_uuid = $override['uuid']; |
|
230 | + if ($override) { |
|
231 | + $model->override_uuid = $override['uuid']; |
|
232 | + } |
|
220 | 233 | $model->save(); |
221 | 234 | } |
222 | 235 | return $phoebeObject; |
223 | - } else |
|
224 | - throw new \Exception('Errors on save'); |
|
236 | + } else { |
|
237 | + throw new \Exception('Errors on save'); |
|
238 | + } |
|
225 | 239 | } catch (\Exception $e) { |
226 | 240 | throw new \RuntimeException('Failed to create model. Exception was "'.$e->getMessage().'". Model errors were '.print_r($model->errors, true)); |
227 | 241 | } |
@@ -252,13 +266,15 @@ discard block |
||
252 | 266 | protected function getClassFromType($classType) |
253 | 267 | { |
254 | 268 | $classType = $this->canonicaliseRef($classType); |
255 | - if (empty($classType)) |
|
256 | - throw new \RuntimeException("Invalid classType '$classType'"); |
|
269 | + if (empty($classType)) { |
|
270 | + throw new \RuntimeException("Invalid classType '$classType'"); |
|
271 | + } |
|
257 | 272 | |
258 | 273 | // check a class of this classType exists |
259 | 274 | $class = $this->getClassModel($classType); |
260 | - if (!$class) |
|
261 | - throw new \RuntimeException("No class of type '$classType' available"); |
|
275 | + if (!$class) { |
|
276 | + throw new \RuntimeException("No class of type '$classType' available"); |
|
277 | + } |
|
262 | 278 | return $class; |
263 | 279 | } |
264 | 280 |