Completed
Push — master ( 393727...543190 )
by Vincenzo
03:00
created
api/index.php 2 patches
Unused Use Statements   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@
 block discarded – undo
4 4
 require_once("vendor/autoload.php");
5 5
 
6 6
 
7
-use App\Lib\DsManager\Helpers\MatchSimulator;
8
-use App\Lib\DsManager\Models\Orm\Match;
7
+use App\Lib\DsManager\Helpers\MatchSimulator;
8
+use App\Lib\DsManager\Models\Orm\Match;
9 9
 use App\Lib\DsManager\Models\Orm\MatchResult;
10 10
 use \App\Lib\Helpers\Responder;
11 11
 use \App\Lib\DsManager\Models\Orm\Player;
Please login to merge, or discard this patch.
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -13,153 +13,153 @@
 block discarded – undo
13 13
 use \App\Lib\DsManager\Models\Orm\Coach;
14 14
 
15 15
 $configuration = [
16
-    'settings' => [
17
-        'displayErrorDetails' => true,
18
-    ],
16
+	'settings' => [
17
+		'displayErrorDetails' => true,
18
+	],
19 19
 ];
20 20
 $c = new \Slim\Container($configuration);
21 21
 $api = new \Slim\App($c);
22 22
 
23 23
 $api->get('/ping', function ($request, $response, $args) {
24
-    $jsonResp = json_encode(
25
-        [
26
-            "status" => "service up",
27
-            "message" => "in a bottle"
28
-        ]
29
-    );
30
-    return Responder::getJsonResponse($jsonResp, $response);
24
+	$jsonResp = json_encode(
25
+		[
26
+			"status" => "service up",
27
+			"message" => "in a bottle"
28
+		]
29
+	);
30
+	return Responder::getJsonResponse($jsonResp, $response);
31 31
 });
32 32
 
33 33
 $api->get('/players', function ($request, $response, $args) {
34
-    $json = json_encode(Player::all());
35
-    return Responder::getJsonResponse($json, $response);
34
+	$json = json_encode(Player::all());
35
+	return Responder::getJsonResponse($json, $response);
36 36
 });
37 37
 
38 38
 
39 39
 $api->get('/players/{id}', function ($request, $response, $args) {
40
-    return Responder::getJsonResponse(
41
-        Player::findOrFail($args['id']),
42
-        $response
43
-    );
40
+	return Responder::getJsonResponse(
41
+		Player::findOrFail($args['id']),
42
+		$response
43
+	);
44 44
 });
45 45
 
46 46
 $api->get('/coaches', function ($request, $response, $args) {
47
-    return Responder::getJsonResponse(
48
-        Coach::all(),
49
-        $response
50
-    );
47
+	return Responder::getJsonResponse(
48
+		Coach::all(),
49
+		$response
50
+	);
51 51
 });
52 52
 
53 53
 $api->get('/teams', function ($request, $response, $args) {
54
-    return Responder::getJsonResponse(
55
-        Team::all(),
56
-        $response
57
-    );
54
+	return Responder::getJsonResponse(
55
+		Team::all(),
56
+		$response
57
+	);
58 58
 });
59 59
 
60 60
 $api->get('/teams/{id}', function ($request, $response, $args) {
61
-    return Responder::getJsonResponse(
62
-        Team::complete()
63
-            ->where(
64
-                [
65
-                    'id' => $args['id']
66
-                ]
67
-            )->get(),
68
-        $response
69
-    );
61
+	return Responder::getJsonResponse(
62
+		Team::complete()
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::statistics()->where(
88
-            [
89
-                'id' => $args['playerId'],
90
-                'team_id' => $args['id']
91
-            ]
92
-        )->get(),
93
-        $response
94
-    );
86
+	return Responder::getJsonResponse(
87
+		Player::statistics()->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
-        Match::with(
113
-            'homeTeam',
114
-            'awayTeam'
115
-        )->get(),
116
-        $response
117
-    );
111
+	return Responder::getJsonResponse(
112
+		Match::with(
113
+			'homeTeam',
114
+			'awayTeam'
115
+		)->get(),
116
+		$response
117
+	);
118 118
 });
119 119
 
120 120
 $api->post('/matches', function ($request, $response, $args) {
121
-    $json = $request->getBody();
122
-    $json = json_decode($json, true);
123
-    return Responder::getJsonResponse(
124
-        Match::create(
125
-            $json
126
-        ),
127
-        $response
128
-    );
121
+	$json = $request->getBody();
122
+	$json = json_decode($json, true);
123
+	return Responder::getJsonResponse(
124
+		Match::create(
125
+			$json
126
+		),
127
+		$response
128
+	);
129 129
 });
130 130
 
131 131
 $api->get('/matches/{id}', function ($request, $response, $args) {
132
-    return Responder::getJsonResponse(
133
-        Match::complete()
134
-            ->where(
135
-                [
136
-                    'id' => $args['id']
137
-                ]
138
-            )->first(),
139
-        $response
140
-    );
132
+	return Responder::getJsonResponse(
133
+		Match::complete()
134
+			->where(
135
+				[
136
+					'id' => $args['id']
137
+				]
138
+			)->first(),
139
+		$response
140
+	);
141 141
 });
142 142
 
143 143
 $api->get('/matches/{id}/result', function ($request, $response, $args) {
144
-    $result = MatchResult::complete()
145
-        ->where(
146
-            [
147
-                'id' => $args['id']
148
-            ]
149
-        )->first();
150
-
151
-    return Responder::getJsonResponse(
152
-        $result,
153
-        $response
154
-    );
144
+	$result = MatchResult::complete()
145
+		->where(
146
+			[
147
+				'id' => $args['id']
148
+			]
149
+		)->first();
150
+
151
+	return Responder::getJsonResponse(
152
+		$result,
153
+		$response
154
+	);
155 155
 });
156 156
 
157 157
 $api->put('/matches/{id}/simulate', function ($request, $response, $args) {
158
-    return Responder::getJsonResponse(
159
-        MatchSimulator::simulate(
160
-            $args['id']
161
-        ),
162
-        $response
163
-    );
158
+	return Responder::getJsonResponse(
159
+		MatchSimulator::simulate(
160
+			$args['id']
161
+		),
162
+		$response
163
+	);
164 164
 });
165 165
 $api->run();
166 166
\ No newline at end of file
Please login to merge, or discard this patch.
api/Lib/DsManager/Helpers/MatchSimulator.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -14,53 +14,53 @@
 block discarded – undo
14 14
 class MatchSimulator
15 15
 {
16 16
 
17
-    /**
18
-     * @param $matchId
19
-     * @return mixed
20
-     */
21
-    public static function simulate($matchId)
22
-    {
23
-        $result = MatchResult::complete()
24
-            ->where(
25
-                [
26
-                    'id' => $matchId
27
-                ]
28
-            )->first();
17
+	/**
18
+	 * @param $matchId
19
+	 * @return mixed
20
+	 */
21
+	public static function simulate($matchId)
22
+	{
23
+		$result = MatchResult::complete()
24
+			->where(
25
+				[
26
+					'id' => $matchId
27
+				]
28
+			)->first();
29 29
 
30
-        if (!empty($result) && !$result->simulated) {
31
-            //simulate match
32
-            $match = Match::fromArray(
33
-                \App\Lib\DsManager\Models\Orm\Match::complete()
34
-                    ->where(
35
-                        [
36
-                            'id' => $matchId
37
-                        ]
38
-                    )->first()->toArray()
39
-            );
30
+		if (!empty($result) && !$result->simulated) {
31
+			//simulate match
32
+			$match = Match::fromArray(
33
+				\App\Lib\DsManager\Models\Orm\Match::complete()
34
+					->where(
35
+						[
36
+							'id' => $matchId
37
+						]
38
+					)->first()->toArray()
39
+			);
40 40
 
41
-            $matchResult = $match->simulate()->toArray();
41
+			$matchResult = $match->simulate()->toArray();
42 42
 
43
-            $result = MatchResult::where(
44
-                [
45
-                    'id' => $matchId
46
-                ]
47
-            )->update(
48
-                MatchResult::resolveAttributes(
49
-                    $matchResult,
50
-                    $matchId
51
-                )
52
-            );
53
-            if ($result === 1) {
54
-                $result = MatchResult::complete()
55
-                    ->where(
56
-                        [
57
-                            'id' => $matchId
58
-                        ]
59
-                    )->first();
60
-            }
43
+			$result = MatchResult::where(
44
+				[
45
+					'id' => $matchId
46
+				]
47
+			)->update(
48
+				MatchResult::resolveAttributes(
49
+					$matchResult,
50
+					$matchId
51
+				)
52
+			);
53
+			if ($result === 1) {
54
+				$result = MatchResult::complete()
55
+					->where(
56
+						[
57
+							'id' => $matchId
58
+						]
59
+					)->first();
60
+			}
61 61
 
62
-        }
62
+		}
63 63
 
64
-        return $result;
65
-    }
64
+		return $result;
65
+	}
66 66
 }
67 67
\ No newline at end of file
Please login to merge, or discard this patch.