Completed
Push — master ( c616f0...8421f8 )
by Vincenzo
03:02
created
api/tests/ModelsTest.php 1 patch
Indentation   +217 added lines, -217 removed lines patch added patch discarded remove patch
@@ -8,222 +8,222 @@
 block discarded – undo
8 8
 {
9 9
 
10 10
 
11
-    /**
12
-     * @group Player
13
-     */
14
-    public function testGetRandomPlayer()
15
-    {
16
-        $rndF = new \App\Lib\DsManager\Helpers\RandomFiller();
17
-        $player = $rndF->getPlayer(null, $rndF->getLocale());
18
-        $array = $player->toArray();
19
-        $this->assertNotEmpty($array);
20
-
21
-        $newPlayer = \App\Lib\DsManager\Models\Player::fromArray($array);
22
-        $this->assertNotEmpty($newPlayer->toArray());
23
-    }
24
-
25
-    /**
26
-     * @group Coach
27
-     */
28
-    public function testGetRandomCoach()
29
-    {
30
-        $rndF = new \App\Lib\DsManager\Helpers\RandomFiller();
31
-        $coach = $rndF->getCoach();
32
-        $this->assertNotEmpty($coach->toArray());
33
-    }
34
-
35
-    /**
36
-     * @group Coaches
37
-     */
38
-    public function testGetRandomCoaches()
39
-    {
40
-        foreach (\App\Lib\Helpers\Config::get('generic.localesSmall') as $nat) {
41
-            $rndF = new \App\Lib\DsManager\Helpers\RandomFiller($nat);
42
-            $coach = $rndF->getCoach();
43
-            $this->assertNotEmpty($coach->toArray());
44
-        }
45
-    }
46
-
47
-    /**
48
-     * @group Players
49
-     */
50
-    public function testGetRandomPlayers()
51
-    {
52
-        foreach (\App\Lib\Helpers\Config::get('generic.localesSmall') as $nat) {
53
-            $rndF = new \App\Lib\DsManager\Helpers\RandomFiller($nat);
54
-            $player = $rndF->getPlayer();
55
-            $this->assertNotEmpty($player->toArray());
56
-        }
57
-    }
58
-
59
-    /**
60
-     * @group Team
61
-     */
62
-    public function testGetRandomTeam()
63
-    {
64
-        $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
65
-        $team = $rndF->getTeam();
66
-        $this->assertNotEmpty($team);
67
-        $this->assertNotEmpty($team->name);
68
-        $this->assertNotEmpty($team->getAvgSkill());
69
-
70
-        //After Adding a player
71
-        $player = $rndF->getPlayer();
72
-        $this->assertNotEmpty($player->toArray());
73
-        $team->roster[] = $player;
74
-        $this->assertNotEmpty($team->getAvgSkill());
75
-        $this->assertNotEmpty($team->getAvgAge());
76
-
77
-        $this->assertNotEmpty($team->coach->toArray());
78
-
79
-        $teamArray = $team->toArray();
80
-        $this->assertNotEmpty($teamArray);
81
-
82
-        $newTeam = \App\Lib\DsManager\Models\Team::fromArray($teamArray);
83
-        $this->assertNotEmpty($newTeam->toArray());
84
-
85
-    }
86
-
87
-    /**
88
-     * @group Teams
89
-     */
90
-    public function testGetRandomTeams()
91
-    {
92
-        $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
93
-
94
-        for ($i = 1; $i <= 20; $i++) {
95
-            $team = $rndF->getTeam();
96
-            $this->assertNotEmpty($team->name);
97
-            $this->assertNotEmpty($team->nationality);
98
-            $this->assertNotEmpty($team->getAvgSkill());
99
-            $this->assertNotEmpty($team->getAvgAge());
100
-        }
101
-    }
102
-
103
-    /**
104
-     * @group Match
105
-     */
106
-    public function testGetRandomMatch()
107
-    {
108
-        for ($i = 1; $i <= 30; $i++) {
109
-            $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
110
-            $spanish = $rndF->getTeam();
111
-            $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
112
-            $italian = $rndF->getTeam();
113
-            $this->assertNotEmpty($spanish);
114
-            $this->assertNotEmpty($italian);
115
-            $this->assertNotEmpty($italian->name);
116
-            $this->assertNotEmpty($spanish);
117
-            $this->assertNotEmpty($spanish->name);
118
-
119
-            $this->assertNotEmpty($italian->getAvgSkill());
120
-            $this->assertNotEmpty($spanish->getAvgSkill());
121
-            $result = (new \App\Lib\DsManager\Models\Match($italian, $spanish))->simulate()->toArray();
122
-            $this->assertNotEmpty($result);
123
-            $this->assertGreaterThanOrEqual(0, $result['goal_home']);
124
-            $this->assertGreaterThanOrEqual(0, $result['goal_away']);
125
-
126
-        }
127
-    }
128
-
129
-    /**
130
-     * @group Match
131
-     * @group MatchResult
132
-     * @group matchresultoutput
133
-     */
134
-    public function testMatchFromExistingTeams()
135
-    {
136
-        $teamHome = 1;
137
-        $teamAway = 2;
138
-        $homeOrm = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->where(['id' => $teamHome])->first();
139
-        $awayOrm = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->where(['id' => $teamAway])->first();
140
-        $home = \App\Lib\DsManager\Models\Team::fromArray($homeOrm->toArray());
141
-        $away = \App\Lib\DsManager\Models\Team::fromArray($awayOrm->toArray());
142
-
143
-        $match = new \App\Lib\DsManager\Models\Match($home, $away);
144
-        $result = $match->simulate()->toArray();
145
-        $this->assertNotEmpty($result);
146
-        $this->assertGreaterThanOrEqual(0, $result['goal_away']);
147
-        $this->assertGreaterThanOrEqual(0, $result['goal_home']);
148
-        if ($result['goal_home'] > 0) {
149
-            $this->assertNotEmpty($result['info']['scorers']['home']);
150
-            foreach ($result['info']['scorers']['home'] as $scorerHome) {
151
-                $this->assertEquals($scorerHome->team_id, $teamHome);
152
-            }
153
-        } else {
154
-            $this->assertEmpty($result['info']['scorers']['home']);
155
-        }
156
-        if ($result['goal_away'] > 0) {
157
-            $this->assertNotEmpty($result['info']['scorers']['away']);
158
-            foreach ($result['info']['scorers']['away'] as $scorerAway) {
159
-                $this->assertEquals($scorerAway->team_id, $teamAway);
160
-            }
161
-        } else {
162
-            $this->assertEmpty($result['info']['scorers']['away']);
163
-        }
164
-        if ($result['goal_home'] == $result['goal_away']) {
165
-            $this->assertTrue($result['info']['is_draw']);
166
-        } else {
167
-            $this->assertFalse($result['info']['is_draw']);
168
-        }
169
-    }
170
-
171
-    /**
172
-     * @group Matches
173
-     */
174
-    public function testGetRandomMatchesOneTeam()
175
-    {
176
-        $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
177
-        $myTeam = $rndF->getTeam();
178
-        $win = 0;
179
-        $lost = 0;
180
-        $draw = 0;
181
-
182
-        for ($i = 1; $i <= 2; $i++) {
183
-
184
-            $randomLocale = \App\Lib\Helpers\Config::get('generic.localesSmall');
185
-            shuffle($randomLocale);
186
-            $randomLocale = $randomLocale[0];
187
-
188
-            $rndF = new \App\Lib\DsManager\Helpers\RandomFiller($randomLocale);
189
-            $opponent = $rndF->getTeam();
190
-            $result = (new \App\Lib\DsManager\Models\Match($opponent, $myTeam))->simulate()->toArray();
191
-            $this->assertNotEmpty($result);
192
-            $result = $result['info'];
193
-            if (!$result['is_draw']) {
194
-                if ($result['winner']['name'] == $myTeam->name) {
195
-                    $win++;
196
-                } else {
197
-                    $lost++;
198
-                }
199
-            } else {
200
-                $draw++;
201
-            }
202
-        }
203
-        $this->assertGreaterThanOrEqual(0, $win);
204
-        $this->assertGreaterThanOrEqual(0, $lost);
205
-        $this->assertGreaterThanOrEqual(0, $draw);
206
-    }
207
-
208
-    /**
209
-     * @group Module
210
-     */
211
-    public function testModule()
212
-    {
213
-        $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
214
-        $team = $rndF->getTeam();
215
-
216
-        $modules = \App\Lib\Helpers\Config::get("modules.modules");
217
-        $modules = array_keys($modules);
218
-        foreach ($modules as $mod) {
219
-            $module = new \App\Lib\DsManager\Models\Module($mod);
220
-            $this->assertNotEmpty($module);
221
-            $this->assertNotNull($module->isDefensive());
222
-            $this->assertNotNull($module->isBalanced());
223
-            $this->assertNotNull($module->isOffensive());
224
-            $this->assertTrue(is_array($module->getRoleNeeded()));
225
-        }
226
-        $this->assertGreaterThan(0, $team->playersPerRoleArray());
227
-    }
11
+	/**
12
+	 * @group Player
13
+	 */
14
+	public function testGetRandomPlayer()
15
+	{
16
+		$rndF = new \App\Lib\DsManager\Helpers\RandomFiller();
17
+		$player = $rndF->getPlayer(null, $rndF->getLocale());
18
+		$array = $player->toArray();
19
+		$this->assertNotEmpty($array);
20
+
21
+		$newPlayer = \App\Lib\DsManager\Models\Player::fromArray($array);
22
+		$this->assertNotEmpty($newPlayer->toArray());
23
+	}
24
+
25
+	/**
26
+	 * @group Coach
27
+	 */
28
+	public function testGetRandomCoach()
29
+	{
30
+		$rndF = new \App\Lib\DsManager\Helpers\RandomFiller();
31
+		$coach = $rndF->getCoach();
32
+		$this->assertNotEmpty($coach->toArray());
33
+	}
34
+
35
+	/**
36
+	 * @group Coaches
37
+	 */
38
+	public function testGetRandomCoaches()
39
+	{
40
+		foreach (\App\Lib\Helpers\Config::get('generic.localesSmall') as $nat) {
41
+			$rndF = new \App\Lib\DsManager\Helpers\RandomFiller($nat);
42
+			$coach = $rndF->getCoach();
43
+			$this->assertNotEmpty($coach->toArray());
44
+		}
45
+	}
46
+
47
+	/**
48
+	 * @group Players
49
+	 */
50
+	public function testGetRandomPlayers()
51
+	{
52
+		foreach (\App\Lib\Helpers\Config::get('generic.localesSmall') as $nat) {
53
+			$rndF = new \App\Lib\DsManager\Helpers\RandomFiller($nat);
54
+			$player = $rndF->getPlayer();
55
+			$this->assertNotEmpty($player->toArray());
56
+		}
57
+	}
58
+
59
+	/**
60
+	 * @group Team
61
+	 */
62
+	public function testGetRandomTeam()
63
+	{
64
+		$rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
65
+		$team = $rndF->getTeam();
66
+		$this->assertNotEmpty($team);
67
+		$this->assertNotEmpty($team->name);
68
+		$this->assertNotEmpty($team->getAvgSkill());
69
+
70
+		//After Adding a player
71
+		$player = $rndF->getPlayer();
72
+		$this->assertNotEmpty($player->toArray());
73
+		$team->roster[] = $player;
74
+		$this->assertNotEmpty($team->getAvgSkill());
75
+		$this->assertNotEmpty($team->getAvgAge());
76
+
77
+		$this->assertNotEmpty($team->coach->toArray());
78
+
79
+		$teamArray = $team->toArray();
80
+		$this->assertNotEmpty($teamArray);
81
+
82
+		$newTeam = \App\Lib\DsManager\Models\Team::fromArray($teamArray);
83
+		$this->assertNotEmpty($newTeam->toArray());
84
+
85
+	}
86
+
87
+	/**
88
+	 * @group Teams
89
+	 */
90
+	public function testGetRandomTeams()
91
+	{
92
+		$rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
93
+
94
+		for ($i = 1; $i <= 20; $i++) {
95
+			$team = $rndF->getTeam();
96
+			$this->assertNotEmpty($team->name);
97
+			$this->assertNotEmpty($team->nationality);
98
+			$this->assertNotEmpty($team->getAvgSkill());
99
+			$this->assertNotEmpty($team->getAvgAge());
100
+		}
101
+	}
102
+
103
+	/**
104
+	 * @group Match
105
+	 */
106
+	public function testGetRandomMatch()
107
+	{
108
+		for ($i = 1; $i <= 30; $i++) {
109
+			$rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
110
+			$spanish = $rndF->getTeam();
111
+			$rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
112
+			$italian = $rndF->getTeam();
113
+			$this->assertNotEmpty($spanish);
114
+			$this->assertNotEmpty($italian);
115
+			$this->assertNotEmpty($italian->name);
116
+			$this->assertNotEmpty($spanish);
117
+			$this->assertNotEmpty($spanish->name);
118
+
119
+			$this->assertNotEmpty($italian->getAvgSkill());
120
+			$this->assertNotEmpty($spanish->getAvgSkill());
121
+			$result = (new \App\Lib\DsManager\Models\Match($italian, $spanish))->simulate()->toArray();
122
+			$this->assertNotEmpty($result);
123
+			$this->assertGreaterThanOrEqual(0, $result['goal_home']);
124
+			$this->assertGreaterThanOrEqual(0, $result['goal_away']);
125
+
126
+		}
127
+	}
128
+
129
+	/**
130
+	 * @group Match
131
+	 * @group MatchResult
132
+	 * @group matchresultoutput
133
+	 */
134
+	public function testMatchFromExistingTeams()
135
+	{
136
+		$teamHome = 1;
137
+		$teamAway = 2;
138
+		$homeOrm = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->where(['id' => $teamHome])->first();
139
+		$awayOrm = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->where(['id' => $teamAway])->first();
140
+		$home = \App\Lib\DsManager\Models\Team::fromArray($homeOrm->toArray());
141
+		$away = \App\Lib\DsManager\Models\Team::fromArray($awayOrm->toArray());
142
+
143
+		$match = new \App\Lib\DsManager\Models\Match($home, $away);
144
+		$result = $match->simulate()->toArray();
145
+		$this->assertNotEmpty($result);
146
+		$this->assertGreaterThanOrEqual(0, $result['goal_away']);
147
+		$this->assertGreaterThanOrEqual(0, $result['goal_home']);
148
+		if ($result['goal_home'] > 0) {
149
+			$this->assertNotEmpty($result['info']['scorers']['home']);
150
+			foreach ($result['info']['scorers']['home'] as $scorerHome) {
151
+				$this->assertEquals($scorerHome->team_id, $teamHome);
152
+			}
153
+		} else {
154
+			$this->assertEmpty($result['info']['scorers']['home']);
155
+		}
156
+		if ($result['goal_away'] > 0) {
157
+			$this->assertNotEmpty($result['info']['scorers']['away']);
158
+			foreach ($result['info']['scorers']['away'] as $scorerAway) {
159
+				$this->assertEquals($scorerAway->team_id, $teamAway);
160
+			}
161
+		} else {
162
+			$this->assertEmpty($result['info']['scorers']['away']);
163
+		}
164
+		if ($result['goal_home'] == $result['goal_away']) {
165
+			$this->assertTrue($result['info']['is_draw']);
166
+		} else {
167
+			$this->assertFalse($result['info']['is_draw']);
168
+		}
169
+	}
170
+
171
+	/**
172
+	 * @group Matches
173
+	 */
174
+	public function testGetRandomMatchesOneTeam()
175
+	{
176
+		$rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
177
+		$myTeam = $rndF->getTeam();
178
+		$win = 0;
179
+		$lost = 0;
180
+		$draw = 0;
181
+
182
+		for ($i = 1; $i <= 2; $i++) {
183
+
184
+			$randomLocale = \App\Lib\Helpers\Config::get('generic.localesSmall');
185
+			shuffle($randomLocale);
186
+			$randomLocale = $randomLocale[0];
187
+
188
+			$rndF = new \App\Lib\DsManager\Helpers\RandomFiller($randomLocale);
189
+			$opponent = $rndF->getTeam();
190
+			$result = (new \App\Lib\DsManager\Models\Match($opponent, $myTeam))->simulate()->toArray();
191
+			$this->assertNotEmpty($result);
192
+			$result = $result['info'];
193
+			if (!$result['is_draw']) {
194
+				if ($result['winner']['name'] == $myTeam->name) {
195
+					$win++;
196
+				} else {
197
+					$lost++;
198
+				}
199
+			} else {
200
+				$draw++;
201
+			}
202
+		}
203
+		$this->assertGreaterThanOrEqual(0, $win);
204
+		$this->assertGreaterThanOrEqual(0, $lost);
205
+		$this->assertGreaterThanOrEqual(0, $draw);
206
+	}
207
+
208
+	/**
209
+	 * @group Module
210
+	 */
211
+	public function testModule()
212
+	{
213
+		$rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
214
+		$team = $rndF->getTeam();
215
+
216
+		$modules = \App\Lib\Helpers\Config::get("modules.modules");
217
+		$modules = array_keys($modules);
218
+		foreach ($modules as $mod) {
219
+			$module = new \App\Lib\DsManager\Models\Module($mod);
220
+			$this->assertNotEmpty($module);
221
+			$this->assertNotNull($module->isDefensive());
222
+			$this->assertNotNull($module->isBalanced());
223
+			$this->assertNotNull($module->isOffensive());
224
+			$this->assertTrue(is_array($module->getRoleNeeded()));
225
+		}
226
+		$this->assertGreaterThan(0, $team->playersPerRoleArray());
227
+	}
228 228
 
229 229
 }
Please login to merge, or discard this patch.
api/index.php 1 patch
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -10,184 +10,184 @@
 block discarded – undo
10 10
 use \App\Lib\DsManager\Models\Orm\Coach;
11 11
 
12 12
 $configuration = [
13
-    'settings' => [
14
-        'displayErrorDetails' => true,
15
-    ],
13
+	'settings' => [
14
+		'displayErrorDetails' => true,
15
+	],
16 16
 ];
17 17
 $c = new \Slim\Container($configuration);
18 18
 $api = new \Slim\App($c);
19 19
 
20 20
 $api->get('/ping', function ($request, $response, $args) {
21
-    $jsonResp = json_encode(
22
-        [
23
-            "status" => "service up",
24
-            "message" => "in a bottle",
25
-            "config" => \App\Lib\Helpers\Config::get("config1.stuff")
26
-        ]
27
-    );
28
-    return Responder::getJsonResponse($jsonResp, $response);
21
+	$jsonResp = json_encode(
22
+		[
23
+			"status" => "service up",
24
+			"message" => "in a bottle",
25
+			"config" => \App\Lib\Helpers\Config::get("config1.stuff")
26
+		]
27
+	);
28
+	return Responder::getJsonResponse($jsonResp, $response);
29 29
 });
30 30
 
31 31
 $api->get('/players', function ($request, $response, $args) {
32
-    $json = json_encode(Player::all());
33
-    return Responder::getJsonResponse($json, $response);
32
+	$json = json_encode(Player::all());
33
+	return Responder::getJsonResponse($json, $response);
34 34
 });
35 35
 
36 36
 
37 37
 $api->get('/players/{id}', function ($request, $response, $args) {
38
-    return Responder::getJsonResponse(
39
-        Player::findOrFail($args['id']),
40
-        $response
41
-    );
38
+	return Responder::getJsonResponse(
39
+		Player::findOrFail($args['id']),
40
+		$response
41
+	);
42 42
 });
43 43
 
44 44
 $api->get('/coaches', function ($request, $response, $args) {
45
-    return Responder::getJsonResponse(
46
-        Coach::all(),
47
-        $response
48
-    );
45
+	return Responder::getJsonResponse(
46
+		Coach::all(),
47
+		$response
48
+	);
49 49
 });
50 50
 
51 51
 $api->get('/teams', function ($request, $response, $args) {
52
-    return Responder::getJsonResponse(
53
-        Team::all(),
54
-        $response
55
-    );
52
+	return Responder::getJsonResponse(
53
+		Team::all(),
54
+		$response
55
+	);
56 56
 });
57 57
 
58 58
 $api->get('/teams/{id}', function ($request, $response, $args) {
59
-    return Responder::getJsonResponse(
60
-        Team::with(
61
-            'roster',
62
-            'coach'
63
-        )->where(
64
-            [
65
-                'id' => $args['id']
66
-            ]
67
-        )->get(),
68
-        $response
69
-    );
59
+	return Responder::getJsonResponse(
60
+		Team::with(
61
+			'roster',
62
+			'coach'
63
+		)->where(
64
+			[
65
+				'id' => $args['id']
66
+			]
67
+		)->get(),
68
+		$response
69
+	);
70 70
 });
71 71
 
72 72
 $api->get('/teams/{id}/players', function ($request, $response, $args) {
73
-    return Responder::getJsonResponse(
74
-        Team::with(
75
-            'roster'
76
-        )->where(
77
-            [
78
-                'id' => $args['id']
79
-            ]
80
-        )->get(),
81
-        $response
82
-    );
73
+	return Responder::getJsonResponse(
74
+		Team::with(
75
+			'roster'
76
+		)->where(
77
+			[
78
+				'id' => $args['id']
79
+			]
80
+		)->get(),
81
+		$response
82
+	);
83 83
 });
84 84
 
85 85
 $api->get('/teams/{id}/players/{playerId}', function ($request, $response, $args) {
86
-    return Responder::getJsonResponse(
87
-        Player::where(
88
-            [
89
-                'id' => $args['playerId'],
90
-                'team_id' => $args['id']
91
-            ]
92
-        )->get(),
93
-        $response
94
-    );
86
+	return Responder::getJsonResponse(
87
+		Player::where(
88
+			[
89
+				'id' => $args['playerId'],
90
+				'team_id' => $args['id']
91
+			]
92
+		)->get(),
93
+		$response
94
+	);
95 95
 });
96 96
 
97 97
 $api->get('/teams/{id}/coach', function ($request, $response, $args) {
98
-    return Responder::getJsonResponse(
99
-        Team::with(
100
-            'coach'
101
-        )->where(
102
-            [
103
-                'id' => $args['id']
104
-            ]
105
-        )->get(),
106
-        $response
107
-    );
98
+	return Responder::getJsonResponse(
99
+		Team::with(
100
+			'coach'
101
+		)->where(
102
+			[
103
+				'id' => $args['id']
104
+			]
105
+		)->get(),
106
+		$response
107
+	);
108 108
 });
109 109
 
110 110
 $api->get('/matches', function ($request, $response, $args) {
111
-    return Responder::getJsonResponse(
112
-        \App\Lib\DsManager\Models\Orm\Match::with(
113
-            'homeTeam',
114
-            'awayTeam'
115
-        )->get(),
116
-        $response
117
-    );
111
+	return Responder::getJsonResponse(
112
+		\App\Lib\DsManager\Models\Orm\Match::with(
113
+			'homeTeam',
114
+			'awayTeam'
115
+		)->get(),
116
+		$response
117
+	);
118 118
 });
119 119
 
120 120
 $api->get('/matches/{id}', function ($request, $response, $args) {
121
-    return Responder::getJsonResponse(
122
-        \App\Lib\DsManager\Models\Orm\Match::with(
123
-            'homeTeam',
124
-            'homeTeam.roster',
125
-            'homeTeam.coach',
126
-            'awayTeam',
127
-            'awayTeam.roster',
128
-            'awayTeam.coach'
129
-        )->where(
130
-            [
131
-                'id' => $args['id']
132
-            ]
133
-        )->first(),
134
-        $response
135
-    );
121
+	return Responder::getJsonResponse(
122
+		\App\Lib\DsManager\Models\Orm\Match::with(
123
+			'homeTeam',
124
+			'homeTeam.roster',
125
+			'homeTeam.coach',
126
+			'awayTeam',
127
+			'awayTeam.roster',
128
+			'awayTeam.coach'
129
+		)->where(
130
+			[
131
+				'id' => $args['id']
132
+			]
133
+		)->first(),
134
+		$response
135
+	);
136 136
 });
137 137
 
138 138
 $api->get('/matches/{id}/result', function ($request, $response, $args) {
139
-    $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete()
140
-        ->where(
141
-            [
142
-                'id' => $args['id']
143
-            ]
144
-        )->first();
145
-
146
-    return Responder::getJsonResponse(
147
-        $result,
148
-        $response
149
-    );
139
+	$result = \App\Lib\DsManager\Models\Orm\MatchResult::complete()
140
+		->where(
141
+			[
142
+				'id' => $args['id']
143
+			]
144
+		)->first();
145
+
146
+	return Responder::getJsonResponse(
147
+		$result,
148
+		$response
149
+	);
150 150
 });
151 151
 
152 152
 $api->put('/matches/{id}/simulate', function ($request, $response, $args) {
153
-    $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete()
154
-        ->where(
155
-            [
156
-                'id' => $args['id']
157
-            ]
158
-        )->first();
159
-
160
-    if (!empty($result) && !$result->simulated) {
161
-        //simulate match
162
-        $match = \App\Lib\DsManager\Models\Match::fromArray(
163
-            \App\Lib\DsManager\Models\Orm\Match::complete()
164
-                ->where(
165
-                    [
166
-                        'id' => $args['id']
167
-                    ]
168
-                )->first()->toArray()
169
-        );
170
-        $matchResult = $match->simulate()->toArray();
171
-        $result = \App\Lib\DsManager\Models\Orm\MatchResult::where(
172
-            [
173
-                'id' => $args['id']
174
-            ]
175
-        )->update(
176
-            \App\Lib\DsManager\Models\Orm\MatchResult::castAttributes($matchResult)
177
-        );
178
-        if ($result === 1) {
179
-            $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete()
180
-                ->where(
181
-                    [
182
-                        'id' => $args['id']
183
-                    ]
184
-                )->first();
185
-        }
186
-
187
-    }
188
-    return Responder::getJsonResponse(
189
-        $result,
190
-        $response
191
-    );
153
+	$result = \App\Lib\DsManager\Models\Orm\MatchResult::complete()
154
+		->where(
155
+			[
156
+				'id' => $args['id']
157
+			]
158
+		)->first();
159
+
160
+	if (!empty($result) && !$result->simulated) {
161
+		//simulate match
162
+		$match = \App\Lib\DsManager\Models\Match::fromArray(
163
+			\App\Lib\DsManager\Models\Orm\Match::complete()
164
+				->where(
165
+					[
166
+						'id' => $args['id']
167
+					]
168
+				)->first()->toArray()
169
+		);
170
+		$matchResult = $match->simulate()->toArray();
171
+		$result = \App\Lib\DsManager\Models\Orm\MatchResult::where(
172
+			[
173
+				'id' => $args['id']
174
+			]
175
+		)->update(
176
+			\App\Lib\DsManager\Models\Orm\MatchResult::castAttributes($matchResult)
177
+		);
178
+		if ($result === 1) {
179
+			$result = \App\Lib\DsManager\Models\Orm\MatchResult::complete()
180
+				->where(
181
+					[
182
+						'id' => $args['id']
183
+					]
184
+				)->first();
185
+		}
186
+
187
+	}
188
+	return Responder::getJsonResponse(
189
+		$result,
190
+		$response
191
+	);
192 192
 });
193 193
 $api->run();
194 194
\ No newline at end of file
Please login to merge, or discard this patch.
api/Lib/DsManager/Models/Orm/MatchResult.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -8,36 +8,36 @@
 block discarded – undo
8 8
  */
9 9
 class MatchResult extends Match
10 10
 {
11
-    /**
12
-     * @var array
13
-     */
14
-    protected $fillable = [
15
-        'goal_home',
16
-        'goal_away',
17
-        'info',
18
-        'simulated'
19
-    ];
11
+	/**
12
+	 * @var array
13
+	 */
14
+	protected $fillable = [
15
+		'goal_home',
16
+		'goal_away',
17
+		'info',
18
+		'simulated'
19
+	];
20 20
 
21
-    protected $hidden = [
22
-        'home_team_id',
23
-        'away_team_id',
24
-        'created_at',
25
-        'updated_at'
26
-    ];
21
+	protected $hidden = [
22
+		'home_team_id',
23
+		'away_team_id',
24
+		'created_at',
25
+		'updated_at'
26
+	];
27 27
 
28
-    /**
29
-     * @var array
30
-     */
31
-    protected $casts = [
32
-        'info' => 'json',
33
-        'simulated' => 'boolean'
34
-    ];
28
+	/**
29
+	 * @var array
30
+	 */
31
+	protected $casts = [
32
+		'info' => 'json',
33
+		'simulated' => 'boolean'
34
+	];
35 35
 
36
-    public static function castAttributes($attributes = [])
37
-    {
38
-        if (array_key_exists('info', $attributes)) {
39
-            $attributes['info'] = json_encode($attributes['info']);
40
-        }
41
-        return $attributes;
42
-    }
36
+	public static function castAttributes($attributes = [])
37
+	{
38
+		if (array_key_exists('info', $attributes)) {
39
+			$attributes['info'] = json_encode($attributes['info']);
40
+		}
41
+		return $attributes;
42
+	}
43 43
 }
44 44
\ No newline at end of file
Please login to merge, or discard this patch.
api/Lib/DsManager/Models/MatchResult.php 1 patch
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -13,142 +13,142 @@
 block discarded – undo
13 13
  */
14 14
 class MatchResult extends DsManagerModel
15 15
 {
16
-    /**
17
-     * @var
18
-     */
19
-    private $goalHome;
20
-    /**
21
-     * @var
22
-     */
23
-    private $goalAway;
24
-    /**
25
-     * @var Team
26
-     */
27
-    private $homeTeam;
28
-    /**
29
-     * @var Team
30
-     */
31
-    private $awayTeam;
16
+	/**
17
+	 * @var
18
+	 */
19
+	private $goalHome;
20
+	/**
21
+	 * @var
22
+	 */
23
+	private $goalAway;
24
+	/**
25
+	 * @var Team
26
+	 */
27
+	private $homeTeam;
28
+	/**
29
+	 * @var Team
30
+	 */
31
+	private $awayTeam;
32 32
 
33
-    /**
34
-     * MatchResult constructor.
35
-     * @param $goalHome
36
-     * @param $goalAway
37
-     * @param Team $home
38
-     * @param Team $away
39
-     */
40
-    public function __construct($goalHome, $goalAway, Team $home, Team $away)
41
-    {
42
-        $this->goalHome = $goalHome;
43
-        $this->goalAway = $goalAway;
44
-        $this->homeTeam = $home;
45
-        $this->awayTeam = $away;
46
-    }
33
+	/**
34
+	 * MatchResult constructor.
35
+	 * @param $goalHome
36
+	 * @param $goalAway
37
+	 * @param Team $home
38
+	 * @param Team $away
39
+	 */
40
+	public function __construct($goalHome, $goalAway, Team $home, Team $away)
41
+	{
42
+		$this->goalHome = $goalHome;
43
+		$this->goalAway = $goalAway;
44
+		$this->homeTeam = $home;
45
+		$this->awayTeam = $away;
46
+	}
47 47
 
48
-    /**
49
-     * @return array
50
-     */
51
-    public function getWinnerLoser()
52
-    {
53
-        $isDraw = false;
54
-        $winner = null;
55
-        $loser = null;
56
-        if ($this->goalAway == $this->goalHome) {
57
-            $isDraw = true;
58
-            $winner = $this->homeTeam;
59
-            $loser = $this->awayTeam;
60
-        } else if ($this->goalHome > $this->goalAway) {
61
-            $winner = $this->homeTeam;
62
-            $loser = $this->awayTeam;
63
-        } else {
64
-            $winner = $this->awayTeam;
65
-            $loser = $this->homeTeam;
66
-        }
48
+	/**
49
+	 * @return array
50
+	 */
51
+	public function getWinnerLoser()
52
+	{
53
+		$isDraw = false;
54
+		$winner = null;
55
+		$loser = null;
56
+		if ($this->goalAway == $this->goalHome) {
57
+			$isDraw = true;
58
+			$winner = $this->homeTeam;
59
+			$loser = $this->awayTeam;
60
+		} else if ($this->goalHome > $this->goalAway) {
61
+			$winner = $this->homeTeam;
62
+			$loser = $this->awayTeam;
63
+		} else {
64
+			$winner = $this->awayTeam;
65
+			$loser = $this->homeTeam;
66
+		}
67 67
 
68
-        return [
69
-            'is_draw' => $isDraw,
70
-            'winner' => $this->cleanTeam($winner->toArray()),
71
-            'loser' => $this->cleanTeam($loser->toArray())
72
-        ];
73
-    }
68
+		return [
69
+			'is_draw' => $isDraw,
70
+			'winner' => $this->cleanTeam($winner->toArray()),
71
+			'loser' => $this->cleanTeam($loser->toArray())
72
+		];
73
+	}
74 74
 
75
-    /**
76
-     * @return array
77
-     */
78
-    public function toArray()
79
-    {
80
-        $result = [];
81
-        $result["goal_home"] = $this->goalHome;
82
-        $result["goal_away"] = $this->goalAway;
83
-        $result['info'] = $this->getWinnerLoser();
84
-        $result['info']['scorers'] = $this->getScorers();
85
-        $result['simulated'] = true;
86
-        return $result;
87
-    }
75
+	/**
76
+	 * @return array
77
+	 */
78
+	public function toArray()
79
+	{
80
+		$result = [];
81
+		$result["goal_home"] = $this->goalHome;
82
+		$result["goal_away"] = $this->goalAway;
83
+		$result['info'] = $this->getWinnerLoser();
84
+		$result['info']['scorers'] = $this->getScorers();
85
+		$result['simulated'] = true;
86
+		return $result;
87
+	}
88 88
 
89
-    /**
90
-     * @param array $team
91
-     * @return array
92
-     */
93
-    private function cleanTeam(array $team)
94
-    {
95
-        $fieldsToClean = [
96
-            'coach',
97
-            'roster',
98
-        ];
89
+	/**
90
+	 * @param array $team
91
+	 * @return array
92
+	 */
93
+	private function cleanTeam(array $team)
94
+	{
95
+		$fieldsToClean = [
96
+			'coach',
97
+			'roster',
98
+		];
99 99
 
100
-        foreach ($fieldsToClean as $field) {
101
-            if (array_key_exists($field, $team)) {
102
-                unset($team[$field]);
103
-            }
104
-        }
105
-        return $team;
106
-    }
100
+		foreach ($fieldsToClean as $field) {
101
+			if (array_key_exists($field, $team)) {
102
+				unset($team[$field]);
103
+			}
104
+		}
105
+		return $team;
106
+	}
107 107
 
108
-    /**
109
-     * @return array
110
-     */
111
-    private function getScorers()
112
-    {
113
-        $scorers = [
114
-            'home' => [],
115
-            'away' => []
116
-        ];
117
-        for ($i = 0; $i < $this->goalHome; $i++) {
118
-            $scorers['home'][] = $this->pickAScorer($this->homeTeam);
119
-        }
120
-        for ($i = 0; $i < $this->goalAway; $i++) {
121
-            $scorers['away'][] = $this->pickAScorer($this->awayTeam);
122
-        }
123
-        return $scorers;
124
-    }
108
+	/**
109
+	 * @return array
110
+	 */
111
+	private function getScorers()
112
+	{
113
+		$scorers = [
114
+			'home' => [],
115
+			'away' => []
116
+		];
117
+		for ($i = 0; $i < $this->goalHome; $i++) {
118
+			$scorers['home'][] = $this->pickAScorer($this->homeTeam);
119
+		}
120
+		for ($i = 0; $i < $this->goalAway; $i++) {
121
+			$scorers['away'][] = $this->pickAScorer($this->awayTeam);
122
+		}
123
+		return $scorers;
124
+	}
125 125
 
126
-    /**
127
-     * @param Team $team
128
-     * @return Player
129
-     */
130
-    private function pickAScorer(Team $team)
131
-    {
132
-        $player = null;
133
-        if (Randomizer::boolOnPercentage(70)) {
134
-            $roles = Config::get('modules.roles');
135
-            $forwards = array_splice($roles, count($roles) / 2);
136
-            $pos = array_rand($forwards);
137
-            unset($forwards[$pos]);
138
-            $player = $team->getBestPlayerForRole($pos);
139
-            while (empty($player)) {
140
-                if (!empty($forwards)) {
141
-                    $pos = array_rand($forwards);
142
-                    unset($forwards[$pos]);
143
-                    $player = $team->getBestPlayerForRole($pos);
144
-                } else {
145
-                    $player = $team->roster[array_rand($team->roster)];
146
-                }
147
-            }
148
-        } else {
149
-            $player = $team->roster[array_rand($team->roster)];
150
-        }
151
-        return $player;
152
-    }
126
+	/**
127
+	 * @param Team $team
128
+	 * @return Player
129
+	 */
130
+	private function pickAScorer(Team $team)
131
+	{
132
+		$player = null;
133
+		if (Randomizer::boolOnPercentage(70)) {
134
+			$roles = Config::get('modules.roles');
135
+			$forwards = array_splice($roles, count($roles) / 2);
136
+			$pos = array_rand($forwards);
137
+			unset($forwards[$pos]);
138
+			$player = $team->getBestPlayerForRole($pos);
139
+			while (empty($player)) {
140
+				if (!empty($forwards)) {
141
+					$pos = array_rand($forwards);
142
+					unset($forwards[$pos]);
143
+					$player = $team->getBestPlayerForRole($pos);
144
+				} else {
145
+					$player = $team->roster[array_rand($team->roster)];
146
+				}
147
+			}
148
+		} else {
149
+			$player = $team->roster[array_rand($team->roster)];
150
+		}
151
+		return $player;
152
+	}
153 153
 
154 154
 }
155 155
\ No newline at end of file
Please login to merge, or discard this patch.