@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | $member = $storage[$memberRef]; |
113 | 113 | // handle some storage differences |
114 | 114 | $columnCheck = substr($member['column'], 0, 4); |
115 | - if ($columnCheck=='CHAR' || $columnCheck=='UUID') { |
|
115 | + if ($columnCheck == 'CHAR' || $columnCheck == 'UUID') { |
|
116 | 116 | $size = (isset($member['definition']['size'])) ? $member['definition']['size'] : 150; |
117 | 117 | $member['column'] = str_replace($columnCheck, "CHAR($size)", $member['column']); |
118 | 118 | } |
@@ -161,10 +161,10 @@ discard block |
||
161 | 161 | * @return [] array of ['member_ref']=>['data_type_ref', 'column', 'index'] |
162 | 162 | * where column is the db column type |
163 | 163 | */ |
164 | - protected function getMemberStorage($classType, $memberRef=null) |
|
164 | + protected function getMemberStorage($classType, $memberRef = null) |
|
165 | 165 | { |
166 | 166 | $boundValues = []; |
167 | - $query =<<<EOQ |
|
167 | + $query = <<<EOQ |
|
168 | 168 | SELECT `m`.`member_ref`, `s`.`type`, d.`definition` FROM dds_member m |
169 | 169 | JOIN `dds_data_type` d ON `m`.`data_type_ref`=d.`data_type_ref` |
170 | 170 | JOIN `dds_storage` s ON `d`.`storage_ref`=s.`storage_ref` |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | $memberStorage[$r['member_ref']] = [ |
184 | 184 | 'column' => $this->getColumnType($r['type']), |
185 | 185 | 'index' => $this->getIndexType($r['type']), |
186 | - 'definition' => empty($r['definition']) ? null : json_decode($r['definition'],true) |
|
186 | + 'definition' => empty($r['definition']) ? null : json_decode($r['definition'], true) |
|
187 | 187 | ]; |
188 | 188 | } |
189 | 189 | return $memberStorage; |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | case 'BINARY_LONG': $type = 'LONGBLOB'; break; |
211 | 211 | case 'CHAR': $type = 'CHAR'; break; |
212 | 212 | case 'UUID': $type = 'UUID'; break; |
213 | - default: $type="UNKNOWN STORAGE TYPE $storageType"; break; |
|
213 | + default: $type = "UNKNOWN STORAGE TYPE $storageType"; break; |
|
214 | 214 | } |
215 | 215 | $collation = $this->getCollation($storageType); |
216 | 216 | if ($collation) |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | * @throws InvalidArgumentException if class not found and $throwException is true |
286 | 286 | * @return bool whether or not found |
287 | 287 | */ |
288 | - protected function findClass($classType, &$class=null, $throwException=false) |
|
288 | + protected function findClass($classType, &$class = null, $throwException = false) |
|
289 | 289 | { |
290 | 290 | $ct = $this->canonicaliseRef($classType); |
291 | 291 | if (empty(self::$_classCache[$ct])) { |
@@ -334,13 +334,13 @@ discard block |
||
334 | 334 | /** |
335 | 335 | * @see IDdsClassManagement::listMembers |
336 | 336 | */ |
337 | - protected function listMembersForClass($classType, $includeDeleted=false, $keyBy='member_ref') |
|
337 | + protected function listMembersForClass($classType, $includeDeleted = false, $keyBy = 'member_ref') |
|
338 | 338 | { |
339 | 339 | if (!is_string($classType)) |
340 | 340 | throw new InvalidArgumentException('The class type $classType parameter should be a string'); |
341 | 341 | $select = ['member_ref', 'label', 'data_type_ref', 'description', 'choices', 'map_field', 'link_class']; |
342 | 342 | if (!empty($keyBy) && !in_array($keyBy, $select)) |
343 | - throw new InvalidArgumentException('Parameter keyBy must be empty or one of ' .print_r($select, true)); |
|
343 | + throw new InvalidArgumentException('Parameter keyBy must be empty or one of '.print_r($select, true)); |
|
344 | 344 | |
345 | 345 | // see if we have a cached version or getting from the database |
346 | 346 | if (empty(static::$_classMembersCache[$classType][$includeDeleted])) { |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | */ |
392 | 392 | protected function setClassMapMemberCache($classType, $member) |
393 | 393 | { |
394 | - static::$_classMemberMapCache[$classType]=$member; |
|
394 | + static::$_classMemberMapCache[$classType] = $member; |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | /** |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | * @param DdsDataType &$dataType |
401 | 401 | * @return bool whether or not found |
402 | 402 | */ |
403 | - protected function findDataType($dataTypeRef, &$dataType=null) |
|
403 | + protected function findDataType($dataTypeRef, &$dataType = null) |
|
404 | 404 | { |
405 | 405 | $dataType = DdsDataType::findOne(['data_type_ref'=>$dataTypeRef]); |
406 | 406 | return ($dataType !== null); |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | * @param char $separator the single character separator to split the string into its parts |
455 | 455 | * @return string the canonicalised result |
456 | 456 | */ |
457 | - protected function canonicaliseRefByParts($ref, $separator= '.') |
|
457 | + protected function canonicaliseRefByParts($ref, $separator = '.') |
|
458 | 458 | { |
459 | 459 | $parts = explode($separator, $ref); |
460 | 460 | $canons = []; |
@@ -468,7 +468,7 @@ discard block |
||
468 | 468 | * @param $ref |
469 | 469 | * @return string |
470 | 470 | */ |
471 | - protected function quoteField($ref, $ddsObjectAlias='o') |
|
471 | + protected function quoteField($ref, $ddsObjectAlias = 'o') |
|
472 | 472 | { |
473 | 473 | if (in_array($ref, ['_uuid', '_created', '_updated', '_class_ref'])) { |
474 | 474 | return "`$ddsObjectAlias`.`$ref`"; |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | try { |
489 | 489 | $this->canonicaliseFiltersRecursive($filters); |
490 | 490 | } catch (InvalidArgumentException $ex) { |
491 | - throw new InvalidArgumentException($ex->getMessage(). ' Filters passed in: ' .print_r($filters, true)); |
|
491 | + throw new InvalidArgumentException($ex->getMessage().' Filters passed in: '.print_r($filters, true)); |
|
492 | 492 | } |
493 | 493 | return $filters; |
494 | 494 | } |
@@ -503,7 +503,7 @@ discard block |
||
503 | 503 | protected function canonicaliseFiltersRecursive(&$filters) |
504 | 504 | { |
505 | 505 | // is this a filter clause or set of filter clauses?? |
506 | - if (!is_array($filters) || count($filters)==0) |
|
506 | + if (!is_array($filters) || count($filters) == 0) |
|
507 | 507 | return; |
508 | 508 | |
509 | 509 | // recursively descend until one finds a filter clause |
@@ -514,9 +514,9 @@ discard block |
||
514 | 514 | } |
515 | 515 | // so canonicalise a filter clause |
516 | 516 | if (array_key_exists(0, $filters)) |
517 | - $this->canonicaliseFilter($filters[0],0); |
|
517 | + $this->canonicaliseFilter($filters[0], 0); |
|
518 | 518 | if (array_key_exists(1, $filters)) |
519 | - $this->canonicaliseFilter($filters[1],1); |
|
519 | + $this->canonicaliseFilter($filters[1], 1); |
|
520 | 520 | |
521 | 521 | // Handle nulls passed as values |
522 | 522 | // ['field', '=', null] and ['field', '!=', null] |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | } |
546 | 546 | if ($key === 1) { |
547 | 547 | // accept only these operators |
548 | - switch(strtolower($item)) { |
|
548 | + switch (strtolower($item)) { |
|
549 | 549 | case '=': case '!=': |
550 | 550 | case '<': case '<=': |
551 | 551 | case '>': case '>=': |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | { |
581 | 581 | // check there are no integer keys as this means not all keys are in the logic |
582 | 582 | foreach ($keys as $k) { |
583 | - if ((int)$k === $k) { |
|
583 | + if ((int) $k === $k) { |
|
584 | 584 | throw new InvalidArgumentException( |
585 | 585 | 'Daedalus: You have provided a logic string to the query, but it looks like not all filter clauses have a logic name added to them. All filter clauses need to represented in the logic statement.' |
586 | 586 | ); |
@@ -593,8 +593,8 @@ discard block |
||
593 | 593 | ['AND', 'and', 'NOT', 'not', 'OR', 'or', ' ', ')', '('], |
594 | 594 | '', $subLogic |
595 | 595 | ); |
596 | - if (strlen($subLogic)>0) |
|
597 | - throw new InvalidArgumentException("Daedalus: Invalid logic operator provided. Maybe you haven't defined all keys or have other logic than 'AND', 'OR', 'NOT' and '(',')' characters in your logic? You have defined the keys as ".print_r($keys, true). ' for a logic statement of ' .print_r($logic, true). ' The remaining characters are ' .print_r($subLogic, true)); |
|
596 | + if (strlen($subLogic) > 0) |
|
597 | + throw new InvalidArgumentException("Daedalus: Invalid logic operator provided. Maybe you haven't defined all keys or have other logic than 'AND', 'OR', 'NOT' and '(',')' characters in your logic? You have defined the keys as ".print_r($keys, true).' for a logic statement of '.print_r($logic, true).' The remaining characters are '.print_r($subLogic, true)); |
|
598 | 598 | return $logic; |
599 | 599 | } |
600 | 600 | |
@@ -630,7 +630,7 @@ discard block |
||
630 | 630 | switch ($drn) { |
631 | 631 | case 'ASC': case 'DESC': |
632 | 632 | // allow -ve key starts for nulls last in MySql |
633 | - if (strpos($k,'-') === 0) |
|
633 | + if (strpos($k, '-') === 0) |
|
634 | 634 | $canon['-'.$this->quoteField($k)] = $drn; |
635 | 635 | else |
636 | 636 | $canon[$this->quoteField($k)] = $drn; |
@@ -654,10 +654,10 @@ discard block |
||
654 | 654 | protected function canonicaliseLimit($limit, &$total, &$calculateTotal) |
655 | 655 | { |
656 | 656 | $canon = []; |
657 | - $total=null; |
|
657 | + $total = null; |
|
658 | 658 | $calculateTotal = false; |
659 | 659 | if (is_array($limit)) { |
660 | - $canon = ['start'=>0,'length'=>self::MAX_LENGTH]; |
|
660 | + $canon = ['start'=>0, 'length'=>self::MAX_LENGTH]; |
|
661 | 661 | foreach ($limit as $k=>$v) { |
662 | 662 | $key = strtolower($k); |
663 | 663 | switch ($key) { |
@@ -670,7 +670,7 @@ discard block |
||
670 | 670 | case 'total': |
671 | 671 | // $v can be truthy or the previous integer |
672 | 672 | $total = is_numeric($v) ? (int) $v : null; |
673 | - $calculateTotal = ($v===true || $v==='true'); |
|
673 | + $calculateTotal = ($v === true || $v === 'true'); |
|
674 | 674 | break; |
675 | 675 | } |
676 | 676 | } |
@@ -685,14 +685,14 @@ discard block |
||
685 | 685 | * @param [] $row the row of data to be converted |
686 | 686 | * @param string $classTypeKey the key in the data that will give the class type |
687 | 687 | */ |
688 | - protected function convertFromDBToPHP(&$row, $links=[], $classTypeKey='_class_type') |
|
688 | + protected function convertFromDBToPHP(&$row, $links = [], $classTypeKey = '_class_type') |
|
689 | 689 | { |
690 | 690 | $classType = $row[$classTypeKey]; |
691 | 691 | $members = $this->getClassMembers($classType); |
692 | 692 | // now process only the member defined fields: |
693 | 693 | foreach ($row as $key => &$value) { |
694 | 694 | if (isset($members[$key])) { |
695 | - $memberLinks = isset($links[$key])?$links[$key]:[]; |
|
695 | + $memberLinks = isset($links[$key]) ? $links[$key] : []; |
|
696 | 696 | $this->doConversionFromDBToPHP($members[$key], $value, $memberLinks); |
697 | 697 | } |
698 | 698 | } |
@@ -704,9 +704,9 @@ discard block |
||
704 | 704 | * @param string $dataType the data type ref of the value |
705 | 705 | * @param mixed $value the value returned by the database |
706 | 706 | */ |
707 | - protected function doConversionFromDBToPHP($member, &$value, $memberLinks=[]) |
|
707 | + protected function doConversionFromDBToPHP($member, &$value, $memberLinks = []) |
|
708 | 708 | { |
709 | - switch($member['data_type_ref']) { |
|
709 | + switch ($member['data_type_ref']) { |
|
710 | 710 | case 'choice': |
711 | 711 | // silently ignore deleted old choice as no longer valid |
712 | 712 | if (is_array($member['choices']) && isset($member['choices'][$value])) { |
@@ -769,7 +769,7 @@ discard block |
||
769 | 769 | protected function doConversionFromPHPToDB($member, &$value, &$links) |
770 | 770 | { |
771 | 771 | $links = null; |
772 | - switch($member['data_type_ref']) { |
|
772 | + switch ($member['data_type_ref']) { |
|
773 | 773 | case 'choice': |
774 | 774 | // convert from the value array to the key if the array |
775 | 775 | // the array was returned |
@@ -805,7 +805,7 @@ discard block |
||
805 | 805 | * @param array $dataTypes add to restrict members to certain types |
806 | 806 | * @return array the members |
807 | 807 | */ |
808 | - protected function getClassMembers($classType, array $dataTypes=[]) |
|
808 | + protected function getClassMembers($classType, array $dataTypes = []) |
|
809 | 809 | { |
810 | 810 | static $_classMembers = []; |
811 | 811 | if (!array_key_exists($classType, $_classMembers)) { |
@@ -838,7 +838,7 @@ discard block |
||
838 | 838 | */ |
839 | 839 | protected function getTableFromClassType($classType) |
840 | 840 | { |
841 | - return 'ddt_' .$this->canonicaliseRef($classType); |
|
841 | + return 'ddt_'.$this->canonicaliseRef($classType); |
|
842 | 842 | } |
843 | 843 | |
844 | 844 | /** |
@@ -884,11 +884,11 @@ discard block |
||
884 | 884 | $fields = []; |
885 | 885 | $values = []; |
886 | 886 | foreach ($row as $f=>$v) { |
887 | - $fields[]=$f; |
|
887 | + $fields[] = $f; |
|
888 | 888 | $values[] = $this->pdoQuote($v); |
889 | 889 | } |
890 | 890 | if (count($fields)) |
891 | - return "REPLACE INTO `$table` (`".(implode('`,`',$fields)).'`) VALUES ('.(implode(',', $values)). ');'; |
|
891 | + return "REPLACE INTO `$table` (`".(implode('`,`', $fields)).'`) VALUES ('.(implode(',', $values)).');'; |
|
892 | 892 | return null; |
893 | 893 | } |
894 | 894 |
@@ -100,8 +100,9 @@ discard block |
||
100 | 100 | $tableName = $this->getTableFromClassType($classType); |
101 | 101 | $upSql = $this->getDropTableSql($classType); |
102 | 102 | $downSql = $this->getCreateTableSql($tableName); |
103 | - foreach ($upSql as $up) |
|
104 | - neon()->db->createCommand($up)->execute(); |
|
103 | + foreach ($upSql as $up) { |
|
104 | + neon()->db->createCommand($up)->execute(); |
|
105 | + } |
|
105 | 106 | $this->storeMigration($upSql, $downSql); |
106 | 107 | } |
107 | 108 | |
@@ -213,8 +214,9 @@ discard block |
||
213 | 214 | default: $type="UNKNOWN STORAGE TYPE $storageType"; break; |
214 | 215 | } |
215 | 216 | $collation = $this->getCollation($storageType); |
216 | - if ($collation) |
|
217 | - return "$type $collation DEFAULT NULL "; |
|
217 | + if ($collation) { |
|
218 | + return "$type $collation DEFAULT NULL "; |
|
219 | + } |
|
218 | 220 | return "$type DEFAULT NULL "; |
219 | 221 | } |
220 | 222 | |
@@ -292,8 +294,9 @@ discard block |
||
292 | 294 | self::$_classCache[$ct] = DdsClass::findOne(['class_type' => $ct]); |
293 | 295 | } |
294 | 296 | $class = self::$_classCache[$ct]; |
295 | - if (!$class && $throwException) |
|
296 | - throw new InvalidArgumentException('Unknown class type "'.$ct.'"'); |
|
297 | + if (!$class && $throwException) { |
|
298 | + throw new InvalidArgumentException('Unknown class type "'.$ct.'"'); |
|
299 | + } |
|
297 | 300 | return ($class !== null); |
298 | 301 | } |
299 | 302 | |
@@ -336,32 +339,38 @@ discard block |
||
336 | 339 | */ |
337 | 340 | protected function listMembersForClass($classType, $includeDeleted=false, $keyBy='member_ref') |
338 | 341 | { |
339 | - if (!is_string($classType)) |
|
340 | - throw new InvalidArgumentException('The class type $classType parameter should be a string'); |
|
342 | + if (!is_string($classType)) { |
|
343 | + throw new InvalidArgumentException('The class type $classType parameter should be a string'); |
|
344 | + } |
|
341 | 345 | $select = ['member_ref', 'label', 'data_type_ref', 'description', 'choices', 'map_field', 'link_class']; |
342 | - if (!empty($keyBy) && !in_array($keyBy, $select)) |
|
343 | - throw new InvalidArgumentException('Parameter keyBy must be empty or one of ' .print_r($select, true)); |
|
346 | + if (!empty($keyBy) && !in_array($keyBy, $select)) { |
|
347 | + throw new InvalidArgumentException('Parameter keyBy must be empty or one of ' .print_r($select, true)); |
|
348 | + } |
|
344 | 349 | |
345 | 350 | // see if we have a cached version or getting from the database |
346 | 351 | if (empty(static::$_classMembersCache[$classType][$includeDeleted])) { |
347 | 352 | $query = DdsMember::find()->where(['class_type' => $classType]); |
348 | - if ($includeDeleted) |
|
349 | - $select[] = 'deleted'; |
|
350 | - else |
|
351 | - $query->andWhere(['deleted' => 0]); |
|
353 | + if ($includeDeleted) { |
|
354 | + $select[] = 'deleted'; |
|
355 | + } else { |
|
356 | + $query->andWhere(['deleted' => 0]); |
|
357 | + } |
|
352 | 358 | $rows = $query->select($select)->orderBy('created')->asArray()->all(); |
353 | - foreach ($rows as $k=>$r) |
|
354 | - $rows[$k]['choices'] = json_decode($r['choices'], true); |
|
359 | + foreach ($rows as $k=>$r) { |
|
360 | + $rows[$k]['choices'] = json_decode($r['choices'], true); |
|
361 | + } |
|
355 | 362 | static::$_classMembersCache[$classType][$includeDeleted] = $rows; |
356 | 363 | } |
357 | 364 | |
358 | - if (empty($keyBy)) |
|
359 | - return static::$_classMembersCache[$classType][$includeDeleted]; |
|
365 | + if (empty($keyBy)) { |
|
366 | + return static::$_classMembersCache[$classType][$includeDeleted]; |
|
367 | + } |
|
360 | 368 | |
361 | 369 | // key by a particular ref |
362 | 370 | $results = []; |
363 | - foreach (static::$_classMembersCache[$classType][$includeDeleted] as $r) |
|
364 | - $results[$r[$keyBy]] = $r; |
|
371 | + foreach (static::$_classMembersCache[$classType][$includeDeleted] as $r) { |
|
372 | + $results[$r[$keyBy]] = $r; |
|
373 | + } |
|
365 | 374 | |
366 | 375 | return $results; |
367 | 376 | } |
@@ -458,8 +467,9 @@ discard block |
||
458 | 467 | { |
459 | 468 | $parts = explode($separator, $ref); |
460 | 469 | $canons = []; |
461 | - foreach ($parts as $p) |
|
462 | - $canons[] = $this->canonicaliseRef($p); |
|
470 | + foreach ($parts as $p) { |
|
471 | + $canons[] = $this->canonicaliseRef($p); |
|
472 | + } |
|
463 | 473 | return implode($separator, $canons); |
464 | 474 | } |
465 | 475 | |
@@ -483,8 +493,9 @@ discard block |
||
483 | 493 | */ |
484 | 494 | protected function canonicaliseFilters($filters) |
485 | 495 | { |
486 | - if (!is_array($filters)) |
|
487 | - return []; |
|
496 | + if (!is_array($filters)) { |
|
497 | + return []; |
|
498 | + } |
|
488 | 499 | try { |
489 | 500 | $this->canonicaliseFiltersRecursive($filters); |
490 | 501 | } catch (InvalidArgumentException $ex) { |
@@ -503,20 +514,24 @@ discard block |
||
503 | 514 | protected function canonicaliseFiltersRecursive(&$filters) |
504 | 515 | { |
505 | 516 | // is this a filter clause or set of filter clauses?? |
506 | - if (!is_array($filters) || count($filters)==0) |
|
507 | - return; |
|
517 | + if (!is_array($filters) || count($filters)==0) { |
|
518 | + return; |
|
519 | + } |
|
508 | 520 | |
509 | 521 | // recursively descend until one finds a filter clause |
510 | 522 | if (is_array($filters[0])) { |
511 | - foreach ($filters as &$f) |
|
512 | - $this->canonicaliseFiltersRecursive($f); |
|
523 | + foreach ($filters as &$f) { |
|
524 | + $this->canonicaliseFiltersRecursive($f); |
|
525 | + } |
|
513 | 526 | return; |
514 | 527 | } |
515 | 528 | // so canonicalise a filter clause |
516 | - if (array_key_exists(0, $filters)) |
|
517 | - $this->canonicaliseFilter($filters[0],0); |
|
518 | - if (array_key_exists(1, $filters)) |
|
519 | - $this->canonicaliseFilter($filters[1],1); |
|
529 | + if (array_key_exists(0, $filters)) { |
|
530 | + $this->canonicaliseFilter($filters[0],0); |
|
531 | + } |
|
532 | + if (array_key_exists(1, $filters)) { |
|
533 | + $this->canonicaliseFilter($filters[1],1); |
|
534 | + } |
|
520 | 535 | |
521 | 536 | // Handle nulls passed as values |
522 | 537 | // ['field', '=', null] and ['field', '!=', null] |
@@ -593,8 +608,9 @@ discard block |
||
593 | 608 | ['AND', 'and', 'NOT', 'not', 'OR', 'or', ' ', ')', '('], |
594 | 609 | '', $subLogic |
595 | 610 | ); |
596 | - if (strlen($subLogic)>0) |
|
597 | - throw new InvalidArgumentException("Daedalus: Invalid logic operator provided. Maybe you haven't defined all keys or have other logic than 'AND', 'OR', 'NOT' and '(',')' characters in your logic? You have defined the keys as ".print_r($keys, true). ' for a logic statement of ' .print_r($logic, true). ' The remaining characters are ' .print_r($subLogic, true)); |
|
611 | + if (strlen($subLogic)>0) { |
|
612 | + throw new InvalidArgumentException("Daedalus: Invalid logic operator provided. Maybe you haven't defined all keys or have other logic than 'AND', 'OR', 'NOT' and '(',')' characters in your logic? You have defined the keys as ".print_r($keys, true). ' for a logic statement of ' .print_r($logic, true). ' The remaining characters are ' .print_r($subLogic, true)); |
|
613 | + } |
|
598 | 614 | return $logic; |
599 | 615 | } |
600 | 616 | |
@@ -630,10 +646,11 @@ discard block |
||
630 | 646 | switch ($drn) { |
631 | 647 | case 'ASC': case 'DESC': |
632 | 648 | // allow -ve key starts for nulls last in MySql |
633 | - if (strpos($k,'-') === 0) |
|
634 | - $canon['-'.$this->quoteField($k)] = $drn; |
|
635 | - else |
|
636 | - $canon[$this->quoteField($k)] = $drn; |
|
649 | + if (strpos($k,'-') === 0) { |
|
650 | + $canon['-'.$this->quoteField($k)] = $drn; |
|
651 | + } else { |
|
652 | + $canon[$this->quoteField($k)] = $drn; |
|
653 | + } |
|
637 | 654 | break; |
638 | 655 | case 'RAND': |
639 | 656 | $canon['RAND'] = 'RAND'; |
@@ -721,14 +738,16 @@ discard block |
||
721 | 738 | if (!empty($choices) && is_array($choices)) { |
722 | 739 | foreach ($choices as $choice) { |
723 | 740 | // silently ignore deleted old choice as no longer valid |
724 | - if (isset($member['choices'][$choice])) |
|
725 | - $value[] = ['key'=>$choice, 'value'=>$member['choices'][$choice]]; |
|
741 | + if (isset($member['choices'][$choice])) { |
|
742 | + $value[] = ['key'=>$choice, 'value'=>$member['choices'][$choice]]; |
|
743 | + } |
|
726 | 744 | } |
727 | 745 | } |
728 | 746 | break; |
729 | 747 | case 'boolean': |
730 | - if ($value === NULL) |
|
731 | - return; |
|
748 | + if ($value === NULL) { |
|
749 | + return; |
|
750 | + } |
|
732 | 751 | $value = !!$value; |
733 | 752 | break; |
734 | 753 | case 'json': $value = json_decode($value, true); break; |
@@ -753,8 +772,9 @@ discard block |
||
753 | 772 | $itemLinks = null; |
754 | 773 | if (isset($members[$key])) { |
755 | 774 | $this->doConversionFromPHPToDB($members[$key], $value, $itemLinks); |
756 | - if ($itemLinks !== null) |
|
757 | - $links[$key] = $itemLinks; |
|
775 | + if ($itemLinks !== null) { |
|
776 | + $links[$key] = $itemLinks; |
|
777 | + } |
|
758 | 778 | } |
759 | 779 | } |
760 | 780 | } |
@@ -773,16 +793,18 @@ discard block |
||
773 | 793 | case 'choice': |
774 | 794 | // convert from the value array to the key if the array |
775 | 795 | // the array was returned |
776 | - if (is_array($value) && isset($value['key'])) |
|
777 | - $value = $value['key']; |
|
796 | + if (is_array($value) && isset($value['key'])) { |
|
797 | + $value = $value['key']; |
|
798 | + } |
|
778 | 799 | break; |
779 | 800 | case 'choice_multiple': |
780 | 801 | $value = json_encode($value); |
781 | 802 | break; |
782 | 803 | case 'boolean': |
783 | 804 | // check for null values |
784 | - if ($value === null) |
|
785 | - return; |
|
805 | + if ($value === null) { |
|
806 | + return; |
|
807 | + } |
|
786 | 808 | // convert from truthy to database 1 or 0 |
787 | 809 | $value = $value ? 1 : 0; |
788 | 810 | break; |
@@ -814,19 +836,22 @@ discard block |
||
814 | 836 | // make sure model afterFind has been run |
815 | 837 | $members = DdsMember::find()->where(['class_type'=>$classType])->all(); |
816 | 838 | $membersByRef = []; |
817 | - foreach ($members as $member) |
|
818 | - $membersByRef[$member['member_ref']] = $member->attributes; |
|
839 | + foreach ($members as $member) { |
|
840 | + $membersByRef[$member['member_ref']] = $member->attributes; |
|
841 | + } |
|
819 | 842 | $_classMembers[$classType] = $membersByRef; |
820 | 843 | } catch (Exception $e) { |
821 | 844 | throw new InvalidArgumentException("Error attempting to get members for $classType."); |
822 | 845 | } |
823 | 846 | } |
824 | - if (empty($dataTypes)) |
|
825 | - return $_classMembers[$classType]; |
|
847 | + if (empty($dataTypes)) { |
|
848 | + return $_classMembers[$classType]; |
|
849 | + } |
|
826 | 850 | $dataMembers = []; |
827 | 851 | foreach ($_classMembers[$classType] as $k=>$m) { |
828 | - if (in_array($m['data_type_ref'], $dataTypes)) |
|
829 | - $dataMembers[$k] = $m; |
|
852 | + if (in_array($m['data_type_ref'], $dataTypes)) { |
|
853 | + $dataMembers[$k] = $m; |
|
854 | + } |
|
830 | 855 | } |
831 | 856 | return $dataMembers; |
832 | 857 | } |
@@ -879,16 +904,18 @@ discard block |
||
879 | 904 | */ |
880 | 905 | protected function getTableRowReplaceSql($table, $row) |
881 | 906 | { |
882 | - if (!is_array($row)) |
|
883 | - $row = $row->toArray(); |
|
907 | + if (!is_array($row)) { |
|
908 | + $row = $row->toArray(); |
|
909 | + } |
|
884 | 910 | $fields = []; |
885 | 911 | $values = []; |
886 | 912 | foreach ($row as $f=>$v) { |
887 | 913 | $fields[]=$f; |
888 | 914 | $values[] = $this->pdoQuote($v); |
889 | 915 | } |
890 | - if (count($fields)) |
|
891 | - return "REPLACE INTO `$table` (`".(implode('`,`',$fields)).'`) VALUES ('.(implode(',', $values)). ');'; |
|
916 | + if (count($fields)) { |
|
917 | + return "REPLACE INTO `$table` (`".(implode('`,`',$fields)).'`) VALUES ('.(implode(',', $values)). ');'; |
|
918 | + } |
|
892 | 919 | return null; |
893 | 920 | } |
894 | 921 | |
@@ -899,10 +926,12 @@ discard block |
||
899 | 926 | */ |
900 | 927 | private function pdoQuote($value) |
901 | 928 | { |
902 | - if (is_array($value)) |
|
903 | - $value = json_encode($value); |
|
904 | - if (is_null($value)) |
|
905 | - return 'null'; |
|
929 | + if (is_array($value)) { |
|
930 | + $value = json_encode($value); |
|
931 | + } |
|
932 | + if (is_null($value)) { |
|
933 | + return 'null'; |
|
934 | + } |
|
906 | 935 | return neon()->db->pdo->quote($value); |
907 | 936 | } |
908 | 937 | |
@@ -937,8 +966,9 @@ discard block |
||
937 | 966 | protected function areUUIDs(array $candidates) |
938 | 967 | { |
939 | 968 | foreach ($candidates as $candidate) { |
940 | - if (!$this->isUUID($candidate)) |
|
941 | - return false; |
|
969 | + if (!$this->isUUID($candidate)) { |
|
970 | + return false; |
|
971 | + } |
|
942 | 972 | } |
943 | 973 | return true; |
944 | 974 | } |