Completed
Push — master ( 635aa4...d2c914 )
by Tomáš
02:02
created
src/TournamentGenerator/Utilis/FilterComparator.php 1 patch
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -52,7 +52,9 @@  discard block
 block discarded – undo
52 52
 	private static function calcSum(\TournamentGenerator\Team $team, array $groupsId) {
53 53
 		$sum = 0;
54 54
 		foreach ($groupsId as $id) {
55
-			if (isset($team->groupResults[$id])) $sum += $team->groupResults[$id][self::$what];
55
+			if (isset($team->groupResults[$id])) {
56
+				$sum += $team->groupResults[$id][self::$what];
57
+			}
56 58
 		}
57 59
 		return $sum;
58 60
 	}
@@ -62,12 +64,16 @@  discard block
 block discarded – undo
62 64
 			$games = $team->getGames(null, reset($groupsId));
63 65
 			foreach ($games as $game) {
64 66
 				$results = $game->getResults()[$team->getId()];
65
-				if (($results[self::$what] > $max || $max === null)) $max = $results[self::$what];
67
+				if (($results[self::$what] > $max || $max === null)) {
68
+					$max = $results[self::$what];
69
+				}
66 70
 			}
67 71
 			return $max;
68 72
 		}
69 73
 		foreach ($groupsId as $id) {
70
-			if (isset($team->groupResults[$id]) && ($team->groupResults[$id][self::$what] > $max || $max === null)) $max = $team->groupResults[$id][self::$what];
74
+			if (isset($team->groupResults[$id]) && ($team->groupResults[$id][self::$what] > $max || $max === null)) {
75
+				$max = $team->groupResults[$id][self::$what];
76
+			}
71 77
 		}
72 78
 		return $max;
73 79
 	}
@@ -77,12 +83,16 @@  discard block
 block discarded – undo
77 83
 			$games = $team->getGames(null, reset($groupsId));
78 84
 			foreach ($games as $game) {
79 85
 				$results = $game->getResults()[$team->getId()];
80
-				if (($results[self::$what] < $min || $min === null)) $min = $results[self::$what];
86
+				if (($results[self::$what] < $min || $min === null)) {
87
+					$min = $results[self::$what];
88
+				}
81 89
 			}
82 90
 			return $min;
83 91
 		}
84 92
 		foreach ($groupsId as $id) {
85
-			if (isset($team->groupResults[$id]) && ($team->groupResults[$id][self::$what] < $min || $min === null)) $min = $team->groupResults[$id][self::$what];
93
+			if (isset($team->groupResults[$id]) && ($team->groupResults[$id][self::$what] < $min || $min === null)) {
94
+				$min = $team->groupResults[$id][self::$what];
95
+			}
86 96
 		}
87 97
 		return $min;
88 98
 	}
Please login to merge, or discard this patch.
src/TournamentGenerator/TeamFilter.php 1 patch
Braces   +25 added lines, -9 removed lines patch added patch discarded remove patch
@@ -44,11 +44,17 @@  discard block
 block discarded – undo
44 44
 	private $groups = [];
45 45
 
46 46
 	function __construct(string $what = 'points', string $how = '>', $val = 0, array $groups = []){
47
-		if (!in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) throw new \Exception('Trying to filter unexisting type ('.$what.')');
47
+		if (!in_array(strtolower($what), ['points', 'score', 'wins', 'draws', 'losses', 'second', 'third', 'team', 'notprogressed', 'progressed'])) {
48
+			throw new \Exception('Trying to filter unexisting type ('.$what.')');
49
+		}
48 50
 		$this->what = strtolower($what);
49
-		if (!in_array($how, ['>', '<', '>=', '<=', '=', '!='])) throw new \Exception('Trying to filter with unexisting operator ('.$how.')');
51
+		if (!in_array($how, ['>', '<', '>=', '<=', '=', '!='])) {
52
+			throw new \Exception('Trying to filter with unexisting operator ('.$how.')');
53
+		}
50 54
 		$this->how = $how;
51
-		if (!(gettype($val) === 'integer' && strtolower($what) !== 'team') && !($val instanceof Team && strtolower($what) === 'team')) throw new \Exception('Unsupported filter value type ('.gettype($val).')');
55
+		if (!(gettype($val) === 'integer' && strtolower($what) !== 'team') && !($val instanceof Team && strtolower($what) === 'team')) {
56
+			throw new \Exception('Unsupported filter value type ('.gettype($val).')');
57
+		}
52 58
 		$this->val = $val;
53 59
 		$this->groups = array_map(function($a) { return $a->getId(); }, array_filter($groups, function($a) {return ($a instanceof Group);}));
54 60
 	}
@@ -57,11 +63,17 @@  discard block
 block discarded – undo
57 63
 	}
58 64
 
59 65
 	public function validate(Team $team, $groupsId, string $operation = 'sum', Group $from = null) {
60
-		if (count($this->groups) > 0) $groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR);
66
+		if (count($this->groups) > 0) {
67
+			$groupsId = array_unique(array_merge($this->groups, (gettype($groupsId) === 'array' ? $groupsId : [$groupsId])), SORT_REGULAR);
68
+		}
61 69
 
62
-		if ($this->what == 'team') return ($this->how === '!=' ? !$this->validateTeam($team) : $this->validateTeam($team));
63
-		elseif ($this->what == 'notprogressed') return !$this->validateProgressed($team, $from);
64
-		elseif ($this->what == 'progressed') return $this->validateProgressed($team, $from);
70
+		if ($this->what == 'team') {
71
+			return ($this->how === '!=' ? !$this->validateTeam($team) : $this->validateTeam($team));
72
+		} elseif ($this->what == 'notprogressed') {
73
+			return !$this->validateProgressed($team, $from);
74
+		} elseif ($this->what == 'progressed') {
75
+			return $this->validateProgressed($team, $from);
76
+		}
65 77
 
66 78
 		return $this->validateCalc($team, $groupsId, $operation);
67 79
 	}
@@ -70,11 +82,15 @@  discard block
 block discarded – undo
70 82
 		return $this->val === $team;
71 83
 	}
72 84
 	private function validateProgressed(Team $team, Group $from = null) {
73
-		if ($from === null) throw new \Exception('Group $from was not defined.');
85
+		if ($from === null) {
86
+			throw new \Exception('Group $from was not defined.');
87
+		}
74 88
 		return $from->isProgressed($team);
75 89
 	}
76 90
 	private function validateCalc(Team $team, array $groupsId, string $operation = 'sum') {
77
-		if (gettype($groupsId) === 'array' && !in_array(strtolower($operation), ['sum', 'avg', 'max', 'min'])) throw new \Exception('Unknown operation of '.$operation.'. Only "sum", "avg", "min", "max" possible.');
91
+		if (gettype($groupsId) === 'array' && !in_array(strtolower($operation), ['sum', 'avg', 'max', 'min'])) {
92
+			throw new \Exception('Unknown operation of '.$operation.'. Only "sum", "avg", "min", "max" possible.');
93
+		}
78 94
 
79 95
 		return Utilis\FilterComparator::compare($operation, $this->val, $this->how, $this->what, $team, $groupsId);
80 96
 
Please login to merge, or discard this patch.