Completed
Push — master ( b65b7b...c616f0 )
by Vincenzo
02:30
created
api/Lib/DsManager/Models/MatchResult.php 1 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/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.
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
-            $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
+			$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/Match.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -9,62 +9,62 @@
 block discarded – undo
9 9
 class Match extends DsManagerOrm
10 10
 {
11 11
 
12
-    /**
13
-     * @var string
14
-     */
15
-    protected $table = 'matches';
12
+	/**
13
+	 * @var string
14
+	 */
15
+	protected $table = 'matches';
16 16
 
17
-    /**
18
-     * @var array
19
-     */
20
-    protected $fillable = [
21
-        'home_team_id',
22
-        'away_team_id'
23
-    ];
17
+	/**
18
+	 * @var array
19
+	 */
20
+	protected $fillable = [
21
+		'home_team_id',
22
+		'away_team_id'
23
+	];
24 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
-    ];
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 35
 
36
-    /**
37
-     * @var array
38
-     */
39
-    protected $casts = [
40
-        'simulated' => 'boolean'
41
-    ];
36
+	/**
37
+	 * @var array
38
+	 */
39
+	protected $casts = [
40
+		'simulated' => 'boolean'
41
+	];
42 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
-    }
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 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
-    }
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
-    public function scopeComplete($query){
60
-        return $query->with(
61
-            'homeTeam',
62
-            'homeTeam.roster',
63
-            'homeTeam.coach',
64
-            'awayTeam',
65
-            'awayTeam.roster',
66
-            'awayTeam.coach'
67
-        );
68
-    }
59
+	public function scopeComplete($query){
60
+		return $query->with(
61
+			'homeTeam',
62
+			'homeTeam.roster',
63
+			'homeTeam.coach',
64
+			'awayTeam',
65
+			'awayTeam.roster',
66
+			'awayTeam.coach'
67
+		);
68
+	}
69 69
 
70 70
 }
71 71
\ No newline at end of file
Please login to merge, or discard this patch.
api/Lib/DsManager/Models/Orm/MatchResult.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -8,28 +8,28 @@
 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 36
\ No newline at end of file
Please login to merge, or discard this patch.