Completed
Push — master ( 898da4...b65b7b )
by Vincenzo
03:00
created
api/Lib/DsManager/Models/MatchResult.php 2 patches
Unused Use Statements   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,8 +2,8 @@
 block discarded – undo
2 2
 
3 3
 namespace App\Lib\DsManager\Models;
4 4
 
5
-use App\Lib\DsManager\Helpers\Randomizer;
6
-use App\Lib\DsManager\Models\Common\DsManagerModel;
5
+use App\Lib\DsManager\Helpers\Randomizer;
6
+use App\Lib\DsManager\Models\Common\DsManagerModel;
7 7
 use App\Lib\Helpers\Config;
8 8
 
9 9
 
Please login to merge, or discard this patch.
Indentation   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -13,143 +13,143 @@
 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
-            'isDraw' => $isDraw,
70
-            'winner' => $this->cleanTeam($winner->toArray()),
71
-            'loser' => $this->cleanTeam($loser->toArray())
72
-        ];
73
-    }
68
+		return [
69
+			'isDraw' => $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['info'] = json_encode($result['info']);
86
-        $result['simulated'] = true;
87
-        return $result;
88
-    }
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['info'] = json_encode($result['info']);
86
+		$result['simulated'] = true;
87
+		return $result;
88
+	}
89 89
 
90
-    /**
91
-     * @param array $team
92
-     * @return array
93
-     */
94
-    private function cleanTeam(array $team)
95
-    {
96
-        $fieldsToClean = [
97
-            'coach',
98
-            'roster',
99
-        ];
90
+	/**
91
+	 * @param array $team
92
+	 * @return array
93
+	 */
94
+	private function cleanTeam(array $team)
95
+	{
96
+		$fieldsToClean = [
97
+			'coach',
98
+			'roster',
99
+		];
100 100
 
101
-        foreach ($fieldsToClean as $field) {
102
-            if (array_key_exists($field, $team)) {
103
-                unset($team[$field]);
104
-            }
105
-        }
106
-        return $team;
107
-    }
101
+		foreach ($fieldsToClean as $field) {
102
+			if (array_key_exists($field, $team)) {
103
+				unset($team[$field]);
104
+			}
105
+		}
106
+		return $team;
107
+	}
108 108
 
109
-    /**
110
-     * @return array
111
-     */
112
-    private function getScorers()
113
-    {
114
-        $scorers = [
115
-            'home' => [],
116
-            'away' => []
117
-        ];
118
-        for ($i = 0; $i < $this->goalHome; $i++) {
119
-            $scorers['home'][] = $this->pickAScorer($this->homeTeam);
120
-        }
121
-        for ($i = 0; $i < $this->goalAway; $i++) {
122
-            $scorers['away'][] = $this->pickAScorer($this->awayTeam);
123
-        }
124
-        return $scorers;
125
-    }
109
+	/**
110
+	 * @return array
111
+	 */
112
+	private function getScorers()
113
+	{
114
+		$scorers = [
115
+			'home' => [],
116
+			'away' => []
117
+		];
118
+		for ($i = 0; $i < $this->goalHome; $i++) {
119
+			$scorers['home'][] = $this->pickAScorer($this->homeTeam);
120
+		}
121
+		for ($i = 0; $i < $this->goalAway; $i++) {
122
+			$scorers['away'][] = $this->pickAScorer($this->awayTeam);
123
+		}
124
+		return $scorers;
125
+	}
126 126
 
127
-    /**
128
-     * @param Team $team
129
-     * @return Player
130
-     */
131
-    private function pickAScorer(Team $team)
132
-    {
133
-        $player = null;
134
-        if (Randomizer::boolOnPercentage(70)) {
135
-            $roles = Config::get('modules.roles');
136
-            $forwards = array_splice($roles, count($roles) / 2);
137
-            $pos = array_rand($forwards);
138
-            unset($forwards[$pos]);
139
-            $player = $team->getBestPlayerForRole($pos);
140
-            while (empty($player)) {
141
-                if (!empty($forwards)) {
142
-                    $pos = array_rand($forwards);
143
-                    unset($forwards[$pos]);
144
-                    $player = $team->getBestPlayerForRole($pos);
145
-                } else {
146
-                    $player = $team->roster[array_rand($team->roster)];
147
-                }
148
-            }
149
-        } else {
150
-            $player = $team->roster[array_rand($team->roster)];
151
-        }
152
-        return $player;
153
-    }
127
+	/**
128
+	 * @param Team $team
129
+	 * @return Player
130
+	 */
131
+	private function pickAScorer(Team $team)
132
+	{
133
+		$player = null;
134
+		if (Randomizer::boolOnPercentage(70)) {
135
+			$roles = Config::get('modules.roles');
136
+			$forwards = array_splice($roles, count($roles) / 2);
137
+			$pos = array_rand($forwards);
138
+			unset($forwards[$pos]);
139
+			$player = $team->getBestPlayerForRole($pos);
140
+			while (empty($player)) {
141
+				if (!empty($forwards)) {
142
+					$pos = array_rand($forwards);
143
+					unset($forwards[$pos]);
144
+					$player = $team->getBestPlayerForRole($pos);
145
+				} else {
146
+					$player = $team->roster[array_rand($team->roster)];
147
+				}
148
+			}
149
+		} else {
150
+			$player = $team->roster[array_rand($team->roster)];
151
+		}
152
+		return $player;
153
+	}
154 154
 
155 155
 }
156 156
\ No newline at end of file
Please login to merge, or discard this patch.
api/database/seeds/BMatchesSeeder.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -3,20 +3,20 @@
 block discarded – undo
3 3
 
4 4
 class BMatchesSeeder
5 5
 {
6
-    function run()
7
-    {
8
-        $teams = \App\Lib\DsManager\Models\Orm\Team::all()->toArray();
9
-        $halfTheTeams = count($teams) / 2;
10
-        $chunks = array_chunk($teams, $halfTheTeams);
11
-        $teamsSlice1 = $chunks[0];
12
-        $teamsSlice2 = $chunks[1];
13
-        for ($i = 0; $i < $halfTheTeams; $i++) {
14
-            \App\Lib\DsManager\Models\Orm\Match::create(
15
-                [
16
-                    'home_team_id' => $teamsSlice1[$i]['id'],
17
-                    'away_team_id' => $teamsSlice2[$i]['id']
18
-                ]
19
-            );
20
-        }
21
-    }
6
+	function run()
7
+	{
8
+		$teams = \App\Lib\DsManager\Models\Orm\Team::all()->toArray();
9
+		$halfTheTeams = count($teams) / 2;
10
+		$chunks = array_chunk($teams, $halfTheTeams);
11
+		$teamsSlice1 = $chunks[0];
12
+		$teamsSlice2 = $chunks[1];
13
+		for ($i = 0; $i < $halfTheTeams; $i++) {
14
+			\App\Lib\DsManager\Models\Orm\Match::create(
15
+				[
16
+					'home_team_id' => $teamsSlice1[$i]['id'],
17
+					'away_team_id' => $teamsSlice2[$i]['id']
18
+				]
19
+			);
20
+		}
21
+	}
22 22
 }
23 23
\ No newline at end of file
Please login to merge, or discard this patch.
api/database/migrations/CreateMatchTable.php 2 patches
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -5,24 +5,24 @@
 block discarded – undo
5 5
 
6 6
 class CreateMatchTable
7 7
 {
8
-    /**
9
-     * Run the migrations.
10
-     *
11
-     * @return void
12
-     */
13
-    public function run()
14
-    {
15
-        Capsule::schema()->dropIfExists('matches');
16
-        Capsule::schema()->create('matches', function (Blueprint $table) {
17
-            $table->increments('id');
18
-            $table->integer('home_team_id');
19
-            $table->integer('goal_home')->default(0);
20
-            $table->integer('away_team_id');
21
-            $table->integer('goal_away')->default(0);
22
-            $table->boolean('simulated')->default(false);
23
-            $table->text('info')->nullable();
24
-            $table->date('match_date')->default(\Carbon\Carbon::now());
25
-            $table->timestamps();
26
-        });
27
-    }
8
+	/**
9
+	 * Run the migrations.
10
+	 *
11
+	 * @return void
12
+	 */
13
+	public function run()
14
+	{
15
+		Capsule::schema()->dropIfExists('matches');
16
+		Capsule::schema()->create('matches', function (Blueprint $table) {
17
+			$table->increments('id');
18
+			$table->integer('home_team_id');
19
+			$table->integer('goal_home')->default(0);
20
+			$table->integer('away_team_id');
21
+			$table->integer('goal_away')->default(0);
22
+			$table->boolean('simulated')->default(false);
23
+			$table->text('info')->nullable();
24
+			$table->date('match_date')->default(\Carbon\Carbon::now());
25
+			$table->timestamps();
26
+		});
27
+	}
28 28
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
     public function run()
14 14
     {
15 15
         Capsule::schema()->dropIfExists('matches');
16
-        Capsule::schema()->create('matches', function (Blueprint $table) {
16
+        Capsule::schema()->create('matches', function(Blueprint $table) {
17 17
             $table->increments('id');
18 18
             $table->integer('home_team_id');
19 19
             $table->integer('goal_home')->default(0);
Please login to merge, or discard this patch.
api/index.php 2 patches
Indentation   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -10,208 +10,208 @@
 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::with(
140
-        'homeTeam',
141
-        'homeTeam.roster',
142
-        'homeTeam.coach',
143
-        'awayTeam',
144
-        'awayTeam.roster',
145
-        'awayTeam.coach'
146
-    )->where(
147
-        [
148
-            'id' => $args['id']
149
-        ]
150
-    )->first();
151
-
152
-    return Responder::getJsonResponse(
153
-        $result,
154
-        $response
155
-    );
139
+	$result = \App\Lib\DsManager\Models\Orm\MatchResult::with(
140
+		'homeTeam',
141
+		'homeTeam.roster',
142
+		'homeTeam.coach',
143
+		'awayTeam',
144
+		'awayTeam.roster',
145
+		'awayTeam.coach'
146
+	)->where(
147
+		[
148
+			'id' => $args['id']
149
+		]
150
+	)->first();
151
+
152
+	return Responder::getJsonResponse(
153
+		$result,
154
+		$response
155
+	);
156 156
 });
157 157
 
158 158
 $api->put('/matches/{id}/simulate', function ($request, $response, $args) {
159
-    $result = \App\Lib\DsManager\Models\Orm\MatchResult::with(
160
-        'homeTeam',
161
-        'homeTeam.roster',
162
-        'homeTeam.coach',
163
-        'awayTeam',
164
-        'awayTeam.roster',
165
-        'awayTeam.coach'
166
-    )->where(
167
-        [
168
-            'id' => $args['id']
169
-        ]
170
-    )->first();
171
-
172
-    if (!empty($result) && !$result->simulated) {
173
-        //simulate match
174
-        $match = \App\Lib\DsManager\Models\Match::fromArray(
175
-            \App\Lib\DsManager\Models\Orm\Match::with(
176
-                'homeTeam',
177
-                'homeTeam.roster',
178
-                'homeTeam.coach',
179
-                'awayTeam',
180
-                'awayTeam.roster',
181
-                'awayTeam.coach'
182
-            )->where(
183
-                [
184
-                    'id' => $args['id']
185
-                ]
186
-            )->first()->toArray()
187
-        );
188
-        $matchResult = $match->simulate()->toArray();
189
-        $result = \App\Lib\DsManager\Models\Orm\MatchResult::where(
190
-            [
191
-                'id' => $args['id']
192
-            ]
193
-        )->update(
194
-            $matchResult
195
-        );
196
-        if ($result === 1) {
197
-            $result = \App\Lib\DsManager\Models\Orm\MatchResult::with(
198
-                'homeTeam',
199
-                'homeTeam.roster',
200
-                'homeTeam.coach',
201
-                'awayTeam',
202
-                'awayTeam.roster',
203
-                'awayTeam.coach'
204
-            )->where(
205
-                [
206
-                    'id' => $args['id']
207
-                ]
208
-            )->first();
209
-        }
210
-
211
-    }
212
-    return Responder::getJsonResponse(
213
-        $result,
214
-        $response
215
-    );
159
+	$result = \App\Lib\DsManager\Models\Orm\MatchResult::with(
160
+		'homeTeam',
161
+		'homeTeam.roster',
162
+		'homeTeam.coach',
163
+		'awayTeam',
164
+		'awayTeam.roster',
165
+		'awayTeam.coach'
166
+	)->where(
167
+		[
168
+			'id' => $args['id']
169
+		]
170
+	)->first();
171
+
172
+	if (!empty($result) && !$result->simulated) {
173
+		//simulate match
174
+		$match = \App\Lib\DsManager\Models\Match::fromArray(
175
+			\App\Lib\DsManager\Models\Orm\Match::with(
176
+				'homeTeam',
177
+				'homeTeam.roster',
178
+				'homeTeam.coach',
179
+				'awayTeam',
180
+				'awayTeam.roster',
181
+				'awayTeam.coach'
182
+			)->where(
183
+				[
184
+					'id' => $args['id']
185
+				]
186
+			)->first()->toArray()
187
+		);
188
+		$matchResult = $match->simulate()->toArray();
189
+		$result = \App\Lib\DsManager\Models\Orm\MatchResult::where(
190
+			[
191
+				'id' => $args['id']
192
+			]
193
+		)->update(
194
+			$matchResult
195
+		);
196
+		if ($result === 1) {
197
+			$result = \App\Lib\DsManager\Models\Orm\MatchResult::with(
198
+				'homeTeam',
199
+				'homeTeam.roster',
200
+				'homeTeam.coach',
201
+				'awayTeam',
202
+				'awayTeam.roster',
203
+				'awayTeam.coach'
204
+			)->where(
205
+				[
206
+					'id' => $args['id']
207
+				]
208
+			)->first();
209
+		}
210
+
211
+	}
212
+	return Responder::getJsonResponse(
213
+		$result,
214
+		$response
215
+	);
216 216
 });
217 217
 $api->run();
218 218
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 $c = new \Slim\Container($configuration);
18 18
 $api = new \Slim\App($c);
19 19
 
20
-$api->get('/ping', function ($request, $response, $args) {
20
+$api->get('/ping', function($request, $response, $args) {
21 21
     $jsonResp = json_encode(
22 22
         [
23 23
             "status" => "service up",
@@ -28,34 +28,34 @@  discard block
 block discarded – undo
28 28
     return Responder::getJsonResponse($jsonResp, $response);
29 29
 });
30 30
 
31
-$api->get('/players', function ($request, $response, $args) {
31
+$api->get('/players', function($request, $response, $args) {
32 32
     $json = json_encode(Player::all());
33 33
     return Responder::getJsonResponse($json, $response);
34 34
 });
35 35
 
36 36
 
37
-$api->get('/players/{id}', function ($request, $response, $args) {
37
+$api->get('/players/{id}', function($request, $response, $args) {
38 38
     return Responder::getJsonResponse(
39 39
         Player::findOrFail($args['id']),
40 40
         $response
41 41
     );
42 42
 });
43 43
 
44
-$api->get('/coaches', function ($request, $response, $args) {
44
+$api->get('/coaches', function($request, $response, $args) {
45 45
     return Responder::getJsonResponse(
46 46
         Coach::all(),
47 47
         $response
48 48
     );
49 49
 });
50 50
 
51
-$api->get('/teams', function ($request, $response, $args) {
51
+$api->get('/teams', function($request, $response, $args) {
52 52
     return Responder::getJsonResponse(
53 53
         Team::all(),
54 54
         $response
55 55
     );
56 56
 });
57 57
 
58
-$api->get('/teams/{id}', function ($request, $response, $args) {
58
+$api->get('/teams/{id}', function($request, $response, $args) {
59 59
     return Responder::getJsonResponse(
60 60
         Team::with(
61 61
             'roster',
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
     );
70 70
 });
71 71
 
72
-$api->get('/teams/{id}/players', function ($request, $response, $args) {
72
+$api->get('/teams/{id}/players', function($request, $response, $args) {
73 73
     return Responder::getJsonResponse(
74 74
         Team::with(
75 75
             'roster'
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
     );
83 83
 });
84 84
 
85
-$api->get('/teams/{id}/players/{playerId}', function ($request, $response, $args) {
85
+$api->get('/teams/{id}/players/{playerId}', function($request, $response, $args) {
86 86
     return Responder::getJsonResponse(
87 87
         Player::where(
88 88
             [
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
     );
95 95
 });
96 96
 
97
-$api->get('/teams/{id}/coach', function ($request, $response, $args) {
97
+$api->get('/teams/{id}/coach', function($request, $response, $args) {
98 98
     return Responder::getJsonResponse(
99 99
         Team::with(
100 100
             'coach'
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
     );
108 108
 });
109 109
 
110
-$api->get('/matches', function ($request, $response, $args) {
110
+$api->get('/matches', function($request, $response, $args) {
111 111
     return Responder::getJsonResponse(
112 112
         \App\Lib\DsManager\Models\Orm\Match::with(
113 113
             'homeTeam',
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
     );
118 118
 });
119 119
 
120
-$api->get('/matches/{id}', function ($request, $response, $args) {
120
+$api->get('/matches/{id}', function($request, $response, $args) {
121 121
     return Responder::getJsonResponse(
122 122
         \App\Lib\DsManager\Models\Orm\Match::with(
123 123
             'homeTeam',
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
     );
136 136
 });
137 137
 
138
-$api->get('/matches/{id}/result', function ($request, $response, $args) {
138
+$api->get('/matches/{id}/result', function($request, $response, $args) {
139 139
     $result = \App\Lib\DsManager\Models\Orm\MatchResult::with(
140 140
         'homeTeam',
141 141
         'homeTeam.roster',
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
     );
156 156
 });
157 157
 
158
-$api->put('/matches/{id}/simulate', function ($request, $response, $args) {
158
+$api->put('/matches/{id}/simulate', function($request, $response, $args) {
159 159
     $result = \App\Lib\DsManager\Models\Orm\MatchResult::with(
160 160
         'homeTeam',
161 161
         'homeTeam.roster',
Please login to merge, or discard this patch.
api/Lib/DsManager/Models/Orm/MatchResult.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -8,49 +8,49 @@
 block discarded – undo
8 8
  */
9 9
 class MatchResult extends DsManagerOrm
10 10
 {
11
-    /**
12
-     * @var string
13
-     */
14
-    protected $table = 'matches';
11
+	/**
12
+	 * @var string
13
+	 */
14
+	protected $table = 'matches';
15 15
 
16
-    /**
17
-     * @var array
18
-     */
19
-    protected $fillable = [
20
-        'goal_home',
21
-        'goal_away',
22
-        'info',
23
-        'simulated'
24
-    ];
16
+	/**
17
+	 * @var array
18
+	 */
19
+	protected $fillable = [
20
+		'goal_home',
21
+		'goal_away',
22
+		'info',
23
+		'simulated'
24
+	];
25 25
 
26
-    protected $hidden = [
27
-        'home_team_id',
28
-        'away_team_id',
29
-        'created_at',
30
-        'updated_at'
31
-    ];
26
+	protected $hidden = [
27
+		'home_team_id',
28
+		'away_team_id',
29
+		'created_at',
30
+		'updated_at'
31
+	];
32 32
 
33
-    /**
34
-     * @var array
35
-     */
36
-    protected $casts = [
37
-        'info' => 'json',
38
-        'simulated' => 'boolean'
39
-    ];
33
+	/**
34
+	 * @var array
35
+	 */
36
+	protected $casts = [
37
+		'info' => 'json',
38
+		'simulated' => 'boolean'
39
+	];
40 40
 
41
-    /**
42
-     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
43
-     */
44
-    public function homeTeam()
45
-    {
46
-        return $this->belongsTo(Team::class, 'home_team_id');
47
-    }
41
+	/**
42
+	 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
43
+	 */
44
+	public function homeTeam()
45
+	{
46
+		return $this->belongsTo(Team::class, 'home_team_id');
47
+	}
48 48
 
49
-    /**
50
-     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
51
-     */
52
-    public function awayTeam()
53
-    {
54
-        return $this->belongsTo(Team::class, 'away_team_id');
55
-    }
49
+	/**
50
+	 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
51
+	 */
52
+	public function awayTeam()
53
+	{
54
+		return $this->belongsTo(Team::class, 'away_team_id');
55
+	}
56 56
 }
57 57
\ No newline at end of file
Please login to merge, or discard this patch.
api/Lib/DsManager/Models/Orm/Match.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -9,51 +9,51 @@
 block discarded – undo
9 9
 class Match extends DsManagerOrm
10 10
 {
11 11
 
12
-    /**
13
-     * @var string
14
-     */
15
-    protected $table = 'matches';
16
-
17
-    /**
18
-     * @var array
19
-     */
20
-    protected $fillable = [
21
-        'home_team_id',
22
-        'away_team_id'
23
-    ];
24
-
25
-    /**
26
-     * @var array
27
-     */
28
-    protected $hidden = [
29
-        'home_team_id',
30
-        'away_team_id',
31
-        'created_at',
32
-        'updated_at',
33
-        'info'
34
-    ];
35
-
36
-    /**
37
-     * @var array
38
-     */
39
-    protected $casts = [
40
-        'simulated' => 'boolean'
41
-    ];
42
-
43
-    /**
44
-     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
45
-     */
46
-    public function homeTeam()
47
-    {
48
-        return $this->belongsTo(Team::class, 'home_team_id');
49
-    }
50
-
51
-    /**
52
-     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
53
-     */
54
-    public function awayTeam()
55
-    {
56
-        return $this->belongsTo(Team::class, 'away_team_id');
57
-    }
12
+	/**
13
+	 * @var string
14
+	 */
15
+	protected $table = 'matches';
16
+
17
+	/**
18
+	 * @var array
19
+	 */
20
+	protected $fillable = [
21
+		'home_team_id',
22
+		'away_team_id'
23
+	];
24
+
25
+	/**
26
+	 * @var array
27
+	 */
28
+	protected $hidden = [
29
+		'home_team_id',
30
+		'away_team_id',
31
+		'created_at',
32
+		'updated_at',
33
+		'info'
34
+	];
35
+
36
+	/**
37
+	 * @var array
38
+	 */
39
+	protected $casts = [
40
+		'simulated' => 'boolean'
41
+	];
42
+
43
+	/**
44
+	 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
45
+	 */
46
+	public function homeTeam()
47
+	{
48
+		return $this->belongsTo(Team::class, 'home_team_id');
49
+	}
50
+
51
+	/**
52
+	 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
53
+	 */
54
+	public function awayTeam()
55
+	{
56
+		return $this->belongsTo(Team::class, 'away_team_id');
57
+	}
58 58
 
59 59
 }
60 60
\ No newline at end of file
Please login to merge, or discard this patch.
api/Lib/DsManager/Models/Match.php 1 patch
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -11,164 +11,164 @@
 block discarded – undo
11 11
  */
12 12
 class Match extends DsManagerModel
13 13
 {
14
-    /**
15
-     * @var Team
16
-     */
17
-    private $homeTeam;
18
-    /**
19
-     * @var Team
20
-     */
21
-    private $awayTeam;
22
-
23
-    /**
24
-     * Match constructor.
25
-     * @param Team $home
26
-     * @param Team $away
27
-     */
28
-    public function __construct(Team $home, Team $away)
29
-    {
30
-        $this->homeTeam = $home;
31
-        $this->awayTeam = $away;
32
-    }
33
-
34
-    /**
35
-     * @return MatchResult
36
-     */
37
-    public function simulate()
38
-    {
39
-        $homePoints = $this->homeTeam->getAvgSkill();
40
-        $awayPoints = $this->awayTeam->getAvgSkill();
41
-
42
-        $homePoints += $this->malusModule(
43
-            $this->homeTeam->coach->favouriteModule,
44
-            $this->homeTeam->playersPerRoleArray()
45
-        );
46
-        $awayPoints += $this->malusModule(
47
-            $this->awayTeam->coach->favouriteModule,
48
-            $this->awayTeam->playersPerRoleArray()
49
-        );
50
-
51
-        $goalHome = 0;
52
-        $goalAway = 0;
53
-
54
-        if (Randomizer::boolOnPercentage(80)) {
55
-            if (($homePoints - $awayPoints) < 0) {
56
-                $goalAway = ($awayPoints - $homePoints) % 6;
57
-                $goalHome += $this->chance();
58
-                $goalAway += $this->chance();
59
-                $goalHome += $this->bonusHome();
60
-            } else {
61
-                $goalHome = ($homePoints - $awayPoints) % 6;
62
-                $goalAway += $this->chance();
63
-                $goalHome += $this->bonusHome();
64
-            }
65
-        } else {
66
-            $goalHome += $this->chance();
67
-            $goalAway += $this->chance();
68
-            $goalHome += $this->bonusHome();
69
-        }
70
-        $goalHome += $this->bonusAge($this->homeTeam);
71
-        $goalAway += $this->bonusAge($this->awayTeam);
72
-
73
-        //Bonus on Good GoalKeeper
74
-        $goalies = $this->homeTeam->getBestPlayerForRole("GK");
75
-        $goalAway -= $this->bonusGoalKeeper($goalies);
76
-        $goalies = $this->awayTeam->getBestPlayerForRole("GK");
77
-        $goalHome -= $this->bonusGoalKeeper($goalies);
78
-        //
79
-        $homeModule = new Module($this->homeTeam->coach->favouriteModule);
80
-        $awayModule = new Module($this->awayTeam->coach->favouriteModule);
81
-        if ($homeModule->isOffensive()) {
82
-            $goalHome += Randomizer::boolOnPercentage(50) ? rand(1, 2) : 0;
83
-            $goalAway += Randomizer::boolOnPercentage(20) ? 1 : 0;
84
-        }
85
-        if ($awayModule->isOffensive()) {
86
-            $goalAway += Randomizer::boolOnPercentage(50) ? rand(1, 2) : 0;
87
-            $goalHome += Randomizer::boolOnPercentage(20) ? 1 : 0;
88
-        }
89
-        if ($awayModule->isDefensive()) {
90
-            $goalHome -= Randomizer::boolOnPercentage(50) ? 1 : 0;
91
-        }
92
-        if ($homeModule->isDefensive()) {
93
-            $goalAway -= Randomizer::boolOnPercentage(50) ? 1 : 0;
94
-        }
95
-        $goalHome = $goalHome < 0 ? 0 : $goalHome;
96
-        $goalAway = $goalAway < 0 ? 0 : $goalAway;
97
-        return new MatchResult($goalHome, $goalAway, $this->homeTeam, $this->awayTeam);
98
-    }
99
-
100
-    /**
101
-     * @param Team $team
102
-     * @return int
103
-     */
104
-    private function bonusAge(Team $team)
105
-    {
106
-        if ($team->getAvgAge() > 29 || $team->getAvgAge() < 24) {
107
-            return $this->chance();
108
-        }
109
-        return 0;
110
-    }
111
-
112
-    /**
113
-     * @param $goalkeeper
114
-     * @return int
115
-     */
116
-    private function bonusGoalKeeper($goalkeeper)
117
-    {
118
-        $skillGoalkeeper = empty($goalkeeper) ? 1 : $goalkeeper->skillAvg;
119
-        return (Randomizer::boolOnPercentage($skillGoalkeeper) ? 1 : 0);
120
-    }
121
-
122
-    /**
123
-     * @return int
124
-     */
125
-    private function chance()
126
-    {
127
-        return rand(0, 3);
128
-    }
129
-
130
-    /**
131
-     * @return int
132
-     */
133
-    private function bonusHome()
134
-    {
135
-        return Randomizer::boolOnPercentage(66) ? 1 : 0;
136
-    }
137
-
138
-    /**
139
-     * @param $moduleString
140
-     * @param $playersRoleArray
141
-     * @return int
142
-     */
143
-    private function malusModule($moduleString, $playersRoleArray)
144
-    {
145
-        $module = new Module($moduleString);
146
-        if ($module->isApplicableToArray($playersRoleArray)) {
147
-            return rand(1, 10);
148
-        } else {
149
-            return (-1) * rand(1, 10);
150
-        }
151
-    }
152
-
153
-    /**
154
-     * @param array $ormMatchArray
155
-     * @return Match
156
-     */
157
-    public static function fromArray($ormMatchArray = [])
158
-    {
159
-        $homeTeam = Team::fromArray($ormMatchArray['home_team']);
160
-        $awayTeam = Team::fromArray($ormMatchArray['away_team']);
161
-        return new Match($homeTeam, $awayTeam);
162
-    }
163
-
164
-    /**
165
-     * @return mixed
166
-     */
167
-    function toArray()
168
-    {
169
-        $result = [];
170
-        $result['home_team_id'] = $this->homeTeam->id;
171
-        $result['away_team_id'] = $this->awayTeam->id;
172
-        return $result;
173
-    }
14
+	/**
15
+	 * @var Team
16
+	 */
17
+	private $homeTeam;
18
+	/**
19
+	 * @var Team
20
+	 */
21
+	private $awayTeam;
22
+
23
+	/**
24
+	 * Match constructor.
25
+	 * @param Team $home
26
+	 * @param Team $away
27
+	 */
28
+	public function __construct(Team $home, Team $away)
29
+	{
30
+		$this->homeTeam = $home;
31
+		$this->awayTeam = $away;
32
+	}
33
+
34
+	/**
35
+	 * @return MatchResult
36
+	 */
37
+	public function simulate()
38
+	{
39
+		$homePoints = $this->homeTeam->getAvgSkill();
40
+		$awayPoints = $this->awayTeam->getAvgSkill();
41
+
42
+		$homePoints += $this->malusModule(
43
+			$this->homeTeam->coach->favouriteModule,
44
+			$this->homeTeam->playersPerRoleArray()
45
+		);
46
+		$awayPoints += $this->malusModule(
47
+			$this->awayTeam->coach->favouriteModule,
48
+			$this->awayTeam->playersPerRoleArray()
49
+		);
50
+
51
+		$goalHome = 0;
52
+		$goalAway = 0;
53
+
54
+		if (Randomizer::boolOnPercentage(80)) {
55
+			if (($homePoints - $awayPoints) < 0) {
56
+				$goalAway = ($awayPoints - $homePoints) % 6;
57
+				$goalHome += $this->chance();
58
+				$goalAway += $this->chance();
59
+				$goalHome += $this->bonusHome();
60
+			} else {
61
+				$goalHome = ($homePoints - $awayPoints) % 6;
62
+				$goalAway += $this->chance();
63
+				$goalHome += $this->bonusHome();
64
+			}
65
+		} else {
66
+			$goalHome += $this->chance();
67
+			$goalAway += $this->chance();
68
+			$goalHome += $this->bonusHome();
69
+		}
70
+		$goalHome += $this->bonusAge($this->homeTeam);
71
+		$goalAway += $this->bonusAge($this->awayTeam);
72
+
73
+		//Bonus on Good GoalKeeper
74
+		$goalies = $this->homeTeam->getBestPlayerForRole("GK");
75
+		$goalAway -= $this->bonusGoalKeeper($goalies);
76
+		$goalies = $this->awayTeam->getBestPlayerForRole("GK");
77
+		$goalHome -= $this->bonusGoalKeeper($goalies);
78
+		//
79
+		$homeModule = new Module($this->homeTeam->coach->favouriteModule);
80
+		$awayModule = new Module($this->awayTeam->coach->favouriteModule);
81
+		if ($homeModule->isOffensive()) {
82
+			$goalHome += Randomizer::boolOnPercentage(50) ? rand(1, 2) : 0;
83
+			$goalAway += Randomizer::boolOnPercentage(20) ? 1 : 0;
84
+		}
85
+		if ($awayModule->isOffensive()) {
86
+			$goalAway += Randomizer::boolOnPercentage(50) ? rand(1, 2) : 0;
87
+			$goalHome += Randomizer::boolOnPercentage(20) ? 1 : 0;
88
+		}
89
+		if ($awayModule->isDefensive()) {
90
+			$goalHome -= Randomizer::boolOnPercentage(50) ? 1 : 0;
91
+		}
92
+		if ($homeModule->isDefensive()) {
93
+			$goalAway -= Randomizer::boolOnPercentage(50) ? 1 : 0;
94
+		}
95
+		$goalHome = $goalHome < 0 ? 0 : $goalHome;
96
+		$goalAway = $goalAway < 0 ? 0 : $goalAway;
97
+		return new MatchResult($goalHome, $goalAway, $this->homeTeam, $this->awayTeam);
98
+	}
99
+
100
+	/**
101
+	 * @param Team $team
102
+	 * @return int
103
+	 */
104
+	private function bonusAge(Team $team)
105
+	{
106
+		if ($team->getAvgAge() > 29 || $team->getAvgAge() < 24) {
107
+			return $this->chance();
108
+		}
109
+		return 0;
110
+	}
111
+
112
+	/**
113
+	 * @param $goalkeeper
114
+	 * @return int
115
+	 */
116
+	private function bonusGoalKeeper($goalkeeper)
117
+	{
118
+		$skillGoalkeeper = empty($goalkeeper) ? 1 : $goalkeeper->skillAvg;
119
+		return (Randomizer::boolOnPercentage($skillGoalkeeper) ? 1 : 0);
120
+	}
121
+
122
+	/**
123
+	 * @return int
124
+	 */
125
+	private function chance()
126
+	{
127
+		return rand(0, 3);
128
+	}
129
+
130
+	/**
131
+	 * @return int
132
+	 */
133
+	private function bonusHome()
134
+	{
135
+		return Randomizer::boolOnPercentage(66) ? 1 : 0;
136
+	}
137
+
138
+	/**
139
+	 * @param $moduleString
140
+	 * @param $playersRoleArray
141
+	 * @return int
142
+	 */
143
+	private function malusModule($moduleString, $playersRoleArray)
144
+	{
145
+		$module = new Module($moduleString);
146
+		if ($module->isApplicableToArray($playersRoleArray)) {
147
+			return rand(1, 10);
148
+		} else {
149
+			return (-1) * rand(1, 10);
150
+		}
151
+	}
152
+
153
+	/**
154
+	 * @param array $ormMatchArray
155
+	 * @return Match
156
+	 */
157
+	public static function fromArray($ormMatchArray = [])
158
+	{
159
+		$homeTeam = Team::fromArray($ormMatchArray['home_team']);
160
+		$awayTeam = Team::fromArray($ormMatchArray['away_team']);
161
+		return new Match($homeTeam, $awayTeam);
162
+	}
163
+
164
+	/**
165
+	 * @return mixed
166
+	 */
167
+	function toArray()
168
+	{
169
+		$result = [];
170
+		$result['home_team_id'] = $this->homeTeam->id;
171
+		$result['away_team_id'] = $this->awayTeam->id;
172
+		return $result;
173
+	}
174 174
 }
175 175
\ No newline at end of file
Please login to merge, or discard this patch.