Passed
Push — 2.7.8 ( ...b6addd )
by Neill
20:32
created
neon/core/helpers/Iterator.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -99,9 +99,9 @@
 block discarded – undo
99 99
 	 * or if you force it to return a total (this should be
100 100
 	 * avoided if possible as counts are very expensive operations)
101 101
 	 */
102
-	public function returnTotal(bool $force=false)
102
+	public function returnTotal(bool $force = false)
103 103
 	{
104
-		$this->_returnTotal=($force? true : ($this->_start == 0));
104
+		$this->_returnTotal = ($force ? true : ($this->_start == 0));
105 105
 	}
106 106
 
107 107
 	/**
Please login to merge, or discard this patch.
neon/daedalus/services/ddsManager/DdsCore.php 1 patch
Braces   +94 added lines, -64 removed lines patch added patch discarded remove patch
@@ -100,8 +100,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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 'ASC_L':
639 656
 						$canon[$k] = 'ASC';
@@ -727,14 +744,16 @@  discard block
 block discarded – undo
727 744
 				if (!empty($choices) && is_array($choices)) {
728 745
 					foreach ($choices as $choice) {
729 746
 						// silently ignore deleted old choice as no longer valid
730
-						if (isset($member['choices'][$choice]))
731
-							$value[] = ['key'=>$choice, 'value'=>$member['choices'][$choice]];
747
+						if (isset($member['choices'][$choice])) {
748
+													$value[] = ['key'=>$choice, 'value'=>$member['choices'][$choice]];
749
+						}
732 750
 					}
733 751
 				}
734 752
 			break;
735 753
 			case 'boolean':
736
-				if ($value === NULL)
737
-					return;
754
+				if ($value === NULL) {
755
+									return;
756
+				}
738 757
 				$value = !!$value;
739 758
 			break;
740 759
 			case 'json': $value = json_decode($value, true); break;
@@ -759,8 +778,9 @@  discard block
 block discarded – undo
759 778
 			$itemLinks = null;
760 779
 			if (isset($members[$key])) {
761 780
 				$this->doConversionFromPHPToDB($members[$key], $value, $itemLinks);
762
-				if ($itemLinks !== null)
763
-					$links[$key] = $itemLinks;
781
+				if ($itemLinks !== null) {
782
+									$links[$key] = $itemLinks;
783
+				}
764 784
 			}
765 785
 		}
766 786
 	}
@@ -779,16 +799,18 @@  discard block
 block discarded – undo
779 799
 			case 'choice':
780 800
 				// convert from the value array to the key if the array
781 801
 				// the array was returned
782
-				if (is_array($value) && isset($value['key']))
783
-					$value = $value['key'];
802
+				if (is_array($value) && isset($value['key'])) {
803
+									$value = $value['key'];
804
+				}
784 805
 			break;
785 806
 			case 'choice_multiple':
786 807
 				$value = json_encode($value);
787 808
 			break;
788 809
 			case 'boolean':
789 810
 				// check for null values
790
-				if ($value === null)
791
-					return;
811
+				if ($value === null) {
812
+									return;
813
+				}
792 814
 				// convert from truthy to database 1 or 0
793 815
 				$value = $value ? 1 : 0;
794 816
 			break;
@@ -820,19 +842,22 @@  discard block
 block discarded – undo
820 842
 				// make sure model afterFind has been run
821 843
 				$members = DdsMember::find()->where(['class_type'=>$classType])->all();
822 844
 				$membersByRef = [];
823
-				foreach ($members as $member)
824
-					$membersByRef[$member['member_ref']] = $member->attributes;
845
+				foreach ($members as $member) {
846
+									$membersByRef[$member['member_ref']] = $member->attributes;
847
+				}
825 848
 				$_classMembers[$classType] = $membersByRef;
826 849
 			} catch (Exception $e) {
827 850
 				throw new InvalidArgumentException("Error attempting to get members for $classType.");
828 851
 			}
829 852
 		}
830
-		if (empty($dataTypes))
831
-			return $_classMembers[$classType];
853
+		if (empty($dataTypes)) {
854
+					return $_classMembers[$classType];
855
+		}
832 856
 		$dataMembers = [];
833 857
 		foreach ($_classMembers[$classType] as $k=>$m) {
834
-			if (in_array($m['data_type_ref'], $dataTypes))
835
-				$dataMembers[$k] = $m;
858
+			if (in_array($m['data_type_ref'], $dataTypes)) {
859
+							$dataMembers[$k] = $m;
860
+			}
836 861
 		}
837 862
 		return $dataMembers;
838 863
 	}
@@ -885,16 +910,18 @@  discard block
 block discarded – undo
885 910
 	 */
886 911
 	protected function getTableRowReplaceSql($table, $row)
887 912
 	{
888
-		if (!is_array($row))
889
-			$row = $row->toArray();
913
+		if (!is_array($row)) {
914
+					$row = $row->toArray();
915
+		}
890 916
 		$fields = [];
891 917
 		$values = [];
892 918
 		foreach ($row as $f=>$v) {
893 919
 			$fields[]=$f;
894 920
 			$values[] = $this->pdoQuote($v);
895 921
 		}
896
-		if (count($fields))
897
-			return "REPLACE INTO `$table` (`".(implode('`,`',$fields)).'`) VALUES ('.(implode(',', $values)). ');';
922
+		if (count($fields)) {
923
+					return "REPLACE INTO `$table` (`".(implode('`,`',$fields)).'`) VALUES ('.(implode(',', $values)). ');';
924
+		}
898 925
 		return null;
899 926
 	}
900 927
 
@@ -905,10 +932,12 @@  discard block
 block discarded – undo
905 932
 	 */
906 933
 	private function pdoQuote($value)
907 934
 	{
908
-		if (is_array($value))
909
-			$value = json_encode($value);
910
-		if (is_null($value))
911
-			return 'null';
935
+		if (is_array($value)) {
936
+					$value = json_encode($value);
937
+		}
938
+		if (is_null($value)) {
939
+					return 'null';
940
+		}
912 941
 		return neon()->db->pdo->quote($value);
913 942
 	}
914 943
 
@@ -943,8 +972,9 @@  discard block
 block discarded – undo
943 972
 	protected function areUUIDs(array $candidates)
944 973
 	{
945 974
 		foreach ($candidates as $candidate) {
946
-			if (!$this->isUUID($candidate))
947
-				return false;
975
+			if (!$this->isUUID($candidate)) {
976
+							return false;
977
+			}
948 978
 		}
949 979
 		return true;
950 980
 	}
Please login to merge, or discard this patch.