Completed
Push — master ( f63a1c...36889c )
by Vincenzo
03:03
created
api/database/seeds/ATeamsSeeder.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 ATeamsSeeder
5 5
 {
6
-    function run()
7
-    {
8
-        $teamNumber = 16;
9
-        $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller();
10
-        for ($i = 1; $i <= $teamNumber; $i++) {
11
-            $team = $rndFiller->getTeam($rndFiller->getLocale());
12
-            $teamArray = $team->toArray();
13
-            $teamO = \App\Lib\DsManager\Models\Orm\Team::create($teamArray);
14
-            foreach ($teamArray['roster'] as $player) {
15
-                $player['team_id'] = $teamO->id;
16
-                \App\Lib\DsManager\Models\Orm\Player::create($player);
17
-            }
18
-            $teamArray['coach']['team_id'] = $teamO->id;
19
-            \App\Lib\DsManager\Models\Orm\Coach::create($teamArray['coach']);
20
-        }
21
-    }
6
+	function run()
7
+	{
8
+		$teamNumber = 16;
9
+		$rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller();
10
+		for ($i = 1; $i <= $teamNumber; $i++) {
11
+			$team = $rndFiller->getTeam($rndFiller->getLocale());
12
+			$teamArray = $team->toArray();
13
+			$teamO = \App\Lib\DsManager\Models\Orm\Team::create($teamArray);
14
+			foreach ($teamArray['roster'] as $player) {
15
+				$player['team_id'] = $teamO->id;
16
+				\App\Lib\DsManager\Models\Orm\Player::create($player);
17
+			}
18
+			$teamArray['coach']['team_id'] = $teamO->id;
19
+			\App\Lib\DsManager\Models\Orm\Coach::create($teamArray['coach']);
20
+		}
21
+	}
22 22
 }
23 23
\ No newline at end of file
Please login to merge, or discard this patch.
api/Lib/DsManager/Models/Orm/Team.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -8,45 +8,45 @@
 block discarded – undo
8 8
  */
9 9
 class Team extends DsManagerOrm
10 10
 {
11
-    /**
12
-     * @var string
13
-     */
14
-    protected $table = 'teams';
11
+	/**
12
+	 * @var string
13
+	 */
14
+	protected $table = 'teams';
15 15
 
16
-    /**
17
-     * @var array
18
-     */
19
-    protected $fillable = [
20
-        'name',
21
-        'nationality'
22
-    ];
16
+	/**
17
+	 * @var array
18
+	 */
19
+	protected $fillable = [
20
+		'name',
21
+		'nationality'
22
+	];
23 23
 
24
-    /**
25
-     * @return \Illuminate\Database\Eloquent\Relations\HasMany
26
-     */
27
-    public function roster()
28
-    {
29
-        return $this->hasMany(Player::class);
30
-    }
24
+	/**
25
+	 * @return \Illuminate\Database\Eloquent\Relations\HasMany
26
+	 */
27
+	public function roster()
28
+	{
29
+		return $this->hasMany(Player::class);
30
+	}
31 31
 
32
-    /**
33
-     * @return \Illuminate\Database\Eloquent\Relations\HasMany
34
-     */
35
-    public function coach()
36
-    {
37
-        return $this->hasOne(Coach::class);
38
-    }
32
+	/**
33
+	 * @return \Illuminate\Database\Eloquent\Relations\HasMany
34
+	 */
35
+	public function coach()
36
+	{
37
+		return $this->hasOne(Coach::class);
38
+	}
39 39
 
40
-    /**
41
-     * @param $query
42
-     * @return mixed
43
-     */
44
-    public function scopeComplete($query)
45
-    {
46
-        return $query->with(
47
-            'roster',
48
-            'coach'
49
-        );
50
-    }
40
+	/**
41
+	 * @param $query
42
+	 * @return mixed
43
+	 */
44
+	public function scopeComplete($query)
45
+	{
46
+		return $query->with(
47
+			'roster',
48
+			'coach'
49
+		);
50
+	}
51 51
 
52 52
 }
53 53
\ No newline at end of file
Please login to merge, or discard this patch.
api/Lib/DsManager/Helpers/RandomFiller.php 1 patch
Indentation   +152 added lines, -152 removed lines patch added patch discarded remove patch
@@ -15,157 +15,157 @@
 block discarded – undo
15 15
  */
16 16
 class RandomFiller
17 17
 {
18
-    /**
19
-     * @var \Faker\Generator
20
-     */
21
-    protected $faker;
22
-
23
-    /**
24
-     * @var string
25
-     */
26
-    protected $locale;
27
-
28
-
29
-    /**
30
-     * RandomFiller constructor.
31
-     * @param string $locale
32
-     */
33
-    public function __construct($locale = "it_IT")
34
-    {
35
-        $this->locale = $locale;
36
-        $this->faker = \Faker\Factory::create($locale);
37
-    }
38
-
39
-    /**
40
-     * @return string
41
-     */
42
-    public function getTeamName()
43
-    {
44
-        return $this->faker->city;
45
-    }
46
-
47
-
48
-    /**
49
-     * @param null $forcedRole
50
-     * @param null $locale
51
-     * @return Player
52
-     */
53
-    public function getPlayer($forcedRole = null, $locale = null)
54
-    {
55
-        $this->setFaker($locale);
56
-        $player = new Player;
57
-        $player->name = $this->faker->firstNameMale;
58
-        $player->surname = $this->faker->lastName;
59
-        $player->role = $forcedRole == null ? $this->getRole() : $forcedRole;
60
-        $player->nationality = $this->nationalityFromLocale($this->locale);
61
-        $player->age = rand(16, 38);
62
-        $player->skillAvg = rand(40, 100);
63
-
64
-        return $player;
65
-    }
66
-
67
-
68
-    /**
69
-     * @param null $locale
70
-     * @return Coach
71
-     */
72
-    public function getCoach($locale = null)
73
-    {
74
-        $this->setFaker($locale);
75
-        $coach = new Coach;
76
-        $coach->name = $this->faker->firstNameMale;
77
-        $coach->surname = $this->faker->lastName;
78
-        $coach->favouriteModule = $this->getModule();
79
-        $coach->nationality = $this->nationalityFromLocale($this->locale);
80
-        $coach->age = rand(33, 68);
81
-        $coach->skillAvg = rand(40, 100);
82
-
83
-        return $coach;
84
-    }
85
-
86
-    /**
87
-     * @return mixed
88
-     */
89
-    public function getRole()
90
-    {
91
-        $roles = array_keys(Config::get('modules.roles'));
92
-        shuffle($roles);
93
-        return $roles[0];
94
-    }
95
-
96
-    /**
97
-     * @return mixed
98
-     */
99
-    public function getModule()
100
-    {
101
-        $modules = array_keys(Config::get('modules.modules'));
102
-        shuffle($modules);
103
-        return $modules[0];
104
-    }
105
-
106
-
107
-    /**
108
-     * @param null $locale
109
-     * @return Team
110
-     */
111
-    public function getTeam($locale = null)
112
-    {
113
-        $rosterConf = Config::get('generic.rosters');
114
-        $numberOfPlayers = rand($rosterConf['min'], $rosterConf['max']);
115
-        $this->setFaker($locale);
116
-        $team = new Team;
117
-        $team->name = $this->getTeamName();
118
-        $team->nationality = $this->nationalityFromLocale($this->locale);
119
-        $players = [];
120
-        for ($i = 0; $i < $numberOfPlayers; $i++) {
121
-            $players[] = $this->getPlayer();
122
-        }
123
-        //Adding some forced role
124
-        $players[] = $this->getPlayer("GK", $this->getLocale());
125
-        $players[] = $this->getPlayer("CD", $this->getLocale());
126
-        $players[] = $this->getPlayer("CD", $this->getLocale());
127
-        $players[] = $this->getPlayer("CM", $this->getLocale());
128
-        $players[] = $this->getPlayer("CM", $this->getLocale());
129
-        $players[] = $this->getPlayer("CS", $this->getLocale());
130
-        //
131
-
132
-        $team->roster = $players;
133
-        //setting random Nationality Coach (20%)
134
-        $coachNationality = Randomizer::boolOnPercentage(20) ? $this->getLocale() : null;
135
-        $team->coach = $this->getCoach($coachNationality);
136
-
137
-        return $team;
138
-    }
139
-
140
-
141
-    /**
142
-     * @return mixed
143
-     */
144
-    public function getLocale()
145
-    {
146
-        $locales = (Config::get('generic.localesSmall'));
147
-        shuffle($locales);
148
-        return $locales[0];
149
-    }
150
-
151
-    /**
152
-     * @param $locale
153
-     * @return mixed
154
-     */
155
-    private function nationalityFromLocale($locale)
156
-    {
157
-        return preg_replace("/.._/", '', $locale);
158
-    }
159
-
160
-    /**
161
-     * @param $locale
162
-     */
163
-    private function setFaker($locale)
164
-    {
165
-        if ($locale !== null) {
166
-            $this->faker = \Faker\Factory::create($locale);
167
-            $this->locale = $locale;
168
-        }
169
-    }
18
+	/**
19
+	 * @var \Faker\Generator
20
+	 */
21
+	protected $faker;
22
+
23
+	/**
24
+	 * @var string
25
+	 */
26
+	protected $locale;
27
+
28
+
29
+	/**
30
+	 * RandomFiller constructor.
31
+	 * @param string $locale
32
+	 */
33
+	public function __construct($locale = "it_IT")
34
+	{
35
+		$this->locale = $locale;
36
+		$this->faker = \Faker\Factory::create($locale);
37
+	}
38
+
39
+	/**
40
+	 * @return string
41
+	 */
42
+	public function getTeamName()
43
+	{
44
+		return $this->faker->city;
45
+	}
46
+
47
+
48
+	/**
49
+	 * @param null $forcedRole
50
+	 * @param null $locale
51
+	 * @return Player
52
+	 */
53
+	public function getPlayer($forcedRole = null, $locale = null)
54
+	{
55
+		$this->setFaker($locale);
56
+		$player = new Player;
57
+		$player->name = $this->faker->firstNameMale;
58
+		$player->surname = $this->faker->lastName;
59
+		$player->role = $forcedRole == null ? $this->getRole() : $forcedRole;
60
+		$player->nationality = $this->nationalityFromLocale($this->locale);
61
+		$player->age = rand(16, 38);
62
+		$player->skillAvg = rand(40, 100);
63
+
64
+		return $player;
65
+	}
66
+
67
+
68
+	/**
69
+	 * @param null $locale
70
+	 * @return Coach
71
+	 */
72
+	public function getCoach($locale = null)
73
+	{
74
+		$this->setFaker($locale);
75
+		$coach = new Coach;
76
+		$coach->name = $this->faker->firstNameMale;
77
+		$coach->surname = $this->faker->lastName;
78
+		$coach->favouriteModule = $this->getModule();
79
+		$coach->nationality = $this->nationalityFromLocale($this->locale);
80
+		$coach->age = rand(33, 68);
81
+		$coach->skillAvg = rand(40, 100);
82
+
83
+		return $coach;
84
+	}
85
+
86
+	/**
87
+	 * @return mixed
88
+	 */
89
+	public function getRole()
90
+	{
91
+		$roles = array_keys(Config::get('modules.roles'));
92
+		shuffle($roles);
93
+		return $roles[0];
94
+	}
95
+
96
+	/**
97
+	 * @return mixed
98
+	 */
99
+	public function getModule()
100
+	{
101
+		$modules = array_keys(Config::get('modules.modules'));
102
+		shuffle($modules);
103
+		return $modules[0];
104
+	}
105
+
106
+
107
+	/**
108
+	 * @param null $locale
109
+	 * @return Team
110
+	 */
111
+	public function getTeam($locale = null)
112
+	{
113
+		$rosterConf = Config::get('generic.rosters');
114
+		$numberOfPlayers = rand($rosterConf['min'], $rosterConf['max']);
115
+		$this->setFaker($locale);
116
+		$team = new Team;
117
+		$team->name = $this->getTeamName();
118
+		$team->nationality = $this->nationalityFromLocale($this->locale);
119
+		$players = [];
120
+		for ($i = 0; $i < $numberOfPlayers; $i++) {
121
+			$players[] = $this->getPlayer();
122
+		}
123
+		//Adding some forced role
124
+		$players[] = $this->getPlayer("GK", $this->getLocale());
125
+		$players[] = $this->getPlayer("CD", $this->getLocale());
126
+		$players[] = $this->getPlayer("CD", $this->getLocale());
127
+		$players[] = $this->getPlayer("CM", $this->getLocale());
128
+		$players[] = $this->getPlayer("CM", $this->getLocale());
129
+		$players[] = $this->getPlayer("CS", $this->getLocale());
130
+		//
131
+
132
+		$team->roster = $players;
133
+		//setting random Nationality Coach (20%)
134
+		$coachNationality = Randomizer::boolOnPercentage(20) ? $this->getLocale() : null;
135
+		$team->coach = $this->getCoach($coachNationality);
136
+
137
+		return $team;
138
+	}
139
+
140
+
141
+	/**
142
+	 * @return mixed
143
+	 */
144
+	public function getLocale()
145
+	{
146
+		$locales = (Config::get('generic.localesSmall'));
147
+		shuffle($locales);
148
+		return $locales[0];
149
+	}
150
+
151
+	/**
152
+	 * @param $locale
153
+	 * @return mixed
154
+	 */
155
+	private function nationalityFromLocale($locale)
156
+	{
157
+		return preg_replace("/.._/", '', $locale);
158
+	}
159
+
160
+	/**
161
+	 * @param $locale
162
+	 */
163
+	private function setFaker($locale)
164
+	{
165
+		if ($locale !== null) {
166
+			$this->faker = \Faker\Factory::create($locale);
167
+			$this->locale = $locale;
168
+		}
169
+	}
170 170
 
171 171
 }
172 172
\ No newline at end of file
Please login to merge, or discard this patch.
api/Lib/DsManager/Models/Orm/MatchPlayer.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -9,47 +9,47 @@
 block discarded – undo
9 9
 class MatchPlayer extends DsManagerOrm
10 10
 {
11 11
 
12
-    /**
13
-     * @var string
14
-     */
15
-    protected $table = 'match_players';
16
-
17
-    /**
18
-     * @var array
19
-     */
20
-    protected $fillable = [
21
-        'match_id',
22
-        'team_id',
23
-        'player_id',
24
-        'goals',
25
-        'vote'
26
-    ];
27
-
28
-    /**
29
-     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
30
-     */
31
-    public function player()
32
-    {
33
-        return $this->belongsTo(Player::class, 'player_id');
34
-    }
35
-
36
-    /**
37
-     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
38
-     */
39
-    public function team()
40
-    {
41
-        return $this->belongsTo(Team::class, 'team_id');
42
-    }
43
-
44
-    /**
45
-     * @param $query
46
-     * @return mixed
47
-     */
48
-    public function scopeComplete($query){
49
-        return $query->with(
50
-            'team',
51
-            'player'
52
-        );
53
-    }
12
+	/**
13
+	 * @var string
14
+	 */
15
+	protected $table = 'match_players';
16
+
17
+	/**
18
+	 * @var array
19
+	 */
20
+	protected $fillable = [
21
+		'match_id',
22
+		'team_id',
23
+		'player_id',
24
+		'goals',
25
+		'vote'
26
+	];
27
+
28
+	/**
29
+	 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
30
+	 */
31
+	public function player()
32
+	{
33
+		return $this->belongsTo(Player::class, 'player_id');
34
+	}
35
+
36
+	/**
37
+	 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
38
+	 */
39
+	public function team()
40
+	{
41
+		return $this->belongsTo(Team::class, 'team_id');
42
+	}
43
+
44
+	/**
45
+	 * @param $query
46
+	 * @return mixed
47
+	 */
48
+	public function scopeComplete($query){
49
+		return $query->with(
50
+			'team',
51
+			'player'
52
+		);
53
+	}
54 54
 
55 55
 }
56 56
\ No newline at end of file
Please login to merge, or discard this patch.
api/index.php 1 patch
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -10,189 +10,189 @@
 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
-        ]
26
-    );
27
-    return Responder::getJsonResponse($jsonResp, $response);
21
+	$jsonResp = json_encode(
22
+		[
23
+			"status" => "service up",
24
+			"message" => "in a bottle"
25
+		]
26
+	);
27
+	return Responder::getJsonResponse($jsonResp, $response);
28 28
 });
29 29
 
30 30
 $api->get('/players', function ($request, $response, $args) {
31
-    $json = json_encode(Player::all());
32
-    return Responder::getJsonResponse($json, $response);
31
+	$json = json_encode(Player::all());
32
+	return Responder::getJsonResponse($json, $response);
33 33
 });
34 34
 
35 35
 
36 36
 $api->get('/players/{id}', function ($request, $response, $args) {
37
-    return Responder::getJsonResponse(
38
-        Player::findOrFail($args['id']),
39
-        $response
40
-    );
37
+	return Responder::getJsonResponse(
38
+		Player::findOrFail($args['id']),
39
+		$response
40
+	);
41 41
 });
42 42
 
43 43
 $api->get('/coaches', function ($request, $response, $args) {
44
-    return Responder::getJsonResponse(
45
-        Coach::all(),
46
-        $response
47
-    );
44
+	return Responder::getJsonResponse(
45
+		Coach::all(),
46
+		$response
47
+	);
48 48
 });
49 49
 
50 50
 $api->get('/teams', function ($request, $response, $args) {
51
-    return Responder::getJsonResponse(
52
-        Team::all(),
53
-        $response
54
-    );
51
+	return Responder::getJsonResponse(
52
+		Team::all(),
53
+		$response
54
+	);
55 55
 });
56 56
 
57 57
 $api->get('/teams/{id}', function ($request, $response, $args) {
58
-    return Responder::getJsonResponse(
59
-        Team::complete()
60
-            ->where(
61
-                [
62
-                    'id' => $args['id']
63
-                ]
64
-            )->get(),
65
-        $response
66
-    );
58
+	return Responder::getJsonResponse(
59
+		Team::complete()
60
+			->where(
61
+				[
62
+					'id' => $args['id']
63
+				]
64
+			)->get(),
65
+		$response
66
+	);
67 67
 });
68 68
 
69 69
 $api->get('/teams/{id}/players', function ($request, $response, $args) {
70
-    return Responder::getJsonResponse(
71
-        Team::with(
72
-            'roster'
73
-        )->where(
74
-            [
75
-                'id' => $args['id']
76
-            ]
77
-        )->get(),
78
-        $response
79
-    );
70
+	return Responder::getJsonResponse(
71
+		Team::with(
72
+			'roster'
73
+		)->where(
74
+			[
75
+				'id' => $args['id']
76
+			]
77
+		)->get(),
78
+		$response
79
+	);
80 80
 });
81 81
 
82 82
 $api->get('/teams/{id}/players/{playerId}', function ($request, $response, $args) {
83
-    return Responder::getJsonResponse(
84
-        Player::where(
85
-            [
86
-                'id' => $args['playerId'],
87
-                'team_id' => $args['id']
88
-            ]
89
-        )->get(),
90
-        $response
91
-    );
83
+	return Responder::getJsonResponse(
84
+		Player::where(
85
+			[
86
+				'id' => $args['playerId'],
87
+				'team_id' => $args['id']
88
+			]
89
+		)->get(),
90
+		$response
91
+	);
92 92
 });
93 93
 
94 94
 $api->get('/teams/{id}/coach', function ($request, $response, $args) {
95
-    return Responder::getJsonResponse(
96
-        Team::with(
97
-            'coach'
98
-        )->where(
99
-            [
100
-                'id' => $args['id']
101
-            ]
102
-        )->get(),
103
-        $response
104
-    );
95
+	return Responder::getJsonResponse(
96
+		Team::with(
97
+			'coach'
98
+		)->where(
99
+			[
100
+				'id' => $args['id']
101
+			]
102
+		)->get(),
103
+		$response
104
+	);
105 105
 });
106 106
 
107 107
 $api->get('/matches', function ($request, $response, $args) {
108
-    return Responder::getJsonResponse(
109
-        \App\Lib\DsManager\Models\Orm\Match::with(
110
-            'homeTeam',
111
-            'awayTeam'
112
-        )->get(),
113
-        $response
114
-    );
108
+	return Responder::getJsonResponse(
109
+		\App\Lib\DsManager\Models\Orm\Match::with(
110
+			'homeTeam',
111
+			'awayTeam'
112
+		)->get(),
113
+		$response
114
+	);
115 115
 });
116 116
 
117 117
 $api->post('/matches', function ($request, $response, $args) {
118
-    $json = $request->getBody();
119
-    $json = json_decode($json, true);
120
-    return Responder::getJsonResponse(
121
-        \App\Lib\DsManager\Models\Orm\Match::create(
122
-            $json
123
-        ),
124
-        $response
125
-    );
118
+	$json = $request->getBody();
119
+	$json = json_decode($json, true);
120
+	return Responder::getJsonResponse(
121
+		\App\Lib\DsManager\Models\Orm\Match::create(
122
+			$json
123
+		),
124
+		$response
125
+	);
126 126
 });
127 127
 
128 128
 $api->get('/matches/{id}', function ($request, $response, $args) {
129
-    return Responder::getJsonResponse(
130
-        \App\Lib\DsManager\Models\Orm\Match::complete()
131
-            ->where(
132
-                [
133
-                    'id' => $args['id']
134
-                ]
135
-            )->first(),
136
-        $response
137
-    );
129
+	return Responder::getJsonResponse(
130
+		\App\Lib\DsManager\Models\Orm\Match::complete()
131
+			->where(
132
+				[
133
+					'id' => $args['id']
134
+				]
135
+			)->first(),
136
+		$response
137
+	);
138 138
 });
139 139
 
140 140
 $api->get('/matches/{id}/result', function ($request, $response, $args) {
141
-    $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete()
142
-        ->where(
143
-            [
144
-                'id' => $args['id']
145
-            ]
146
-        )->first();
147
-
148
-    return Responder::getJsonResponse(
149
-        $result,
150
-        $response
151
-    );
141
+	$result = \App\Lib\DsManager\Models\Orm\MatchResult::complete()
142
+		->where(
143
+			[
144
+				'id' => $args['id']
145
+			]
146
+		)->first();
147
+
148
+	return Responder::getJsonResponse(
149
+		$result,
150
+		$response
151
+	);
152 152
 });
153 153
 
154 154
 $api->put('/matches/{id}/simulate', function ($request, $response, $args) {
155
-    $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete()
156
-        ->where(
157
-            [
158
-                'id' => $args['id']
159
-            ]
160
-        )->first();
161
-
162
-    if (!empty($result) && !$result->simulated) {
163
-        //simulate match
164
-        $match = \App\Lib\DsManager\Models\Match::fromArray(
165
-            \App\Lib\DsManager\Models\Orm\Match::complete()
166
-                ->where(
167
-                    [
168
-                        'id' => $args['id']
169
-                    ]
170
-                )->first()->toArray()
171
-        );
172
-        $matchResult = $match->simulate()->toArray();
173
-        $result = \App\Lib\DsManager\Models\Orm\MatchResult::where(
174
-            [
175
-                'id' => $args['id']
176
-            ]
177
-        )->update(
178
-            \App\Lib\DsManager\Models\Orm\MatchResult::resolveAttributes(
179
-                $matchResult,
180
-                $args['id']
181
-            )
182
-        );
183
-        if ($result === 1) {
184
-            $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete()
185
-                ->where(
186
-                    [
187
-                        'id' => $args['id']
188
-                    ]
189
-                )->first();
190
-        }
191
-
192
-    }
193
-    return Responder::getJsonResponse(
194
-        $result,
195
-        $response
196
-    );
155
+	$result = \App\Lib\DsManager\Models\Orm\MatchResult::complete()
156
+		->where(
157
+			[
158
+				'id' => $args['id']
159
+			]
160
+		)->first();
161
+
162
+	if (!empty($result) && !$result->simulated) {
163
+		//simulate match
164
+		$match = \App\Lib\DsManager\Models\Match::fromArray(
165
+			\App\Lib\DsManager\Models\Orm\Match::complete()
166
+				->where(
167
+					[
168
+						'id' => $args['id']
169
+					]
170
+				)->first()->toArray()
171
+		);
172
+		$matchResult = $match->simulate()->toArray();
173
+		$result = \App\Lib\DsManager\Models\Orm\MatchResult::where(
174
+			[
175
+				'id' => $args['id']
176
+			]
177
+		)->update(
178
+			\App\Lib\DsManager\Models\Orm\MatchResult::resolveAttributes(
179
+				$matchResult,
180
+				$args['id']
181
+			)
182
+		);
183
+		if ($result === 1) {
184
+			$result = \App\Lib\DsManager\Models\Orm\MatchResult::complete()
185
+				->where(
186
+					[
187
+						'id' => $args['id']
188
+					]
189
+				)->first();
190
+		}
191
+
192
+	}
193
+	return Responder::getJsonResponse(
194
+		$result,
195
+		$response
196
+	);
197 197
 });
198 198
 $api->run();
199 199
\ No newline at end of file
Please login to merge, or discard this patch.
api/database/migrations/CreateMatchPlayersTable.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -5,22 +5,22 @@
 block discarded – undo
5 5
 
6 6
 class CreateMatchPlayersTable
7 7
 {
8
-    /**
9
-     * Run the migrations.
10
-     *
11
-     * @return void
12
-     */
13
-    public function run()
14
-    {
15
-        Capsule::schema()->dropIfExists('match_players');
16
-        Capsule::schema()->create('match_players', function (Blueprint $table) {
17
-            $table->increments('id');
18
-            $table->integer('match_id');
19
-            $table->integer('team_id');
20
-            $table->integer('player_id')->default(0);
21
-            $table->unsignedTinyInteger('goals')->default(0);
22
-            $table->unsignedTinyInteger('vote')->default(6);
23
-            $table->timestamps();
24
-        });
25
-    }
8
+	/**
9
+	 * Run the migrations.
10
+	 *
11
+	 * @return void
12
+	 */
13
+	public function run()
14
+	{
15
+		Capsule::schema()->dropIfExists('match_players');
16
+		Capsule::schema()->create('match_players', function (Blueprint $table) {
17
+			$table->increments('id');
18
+			$table->integer('match_id');
19
+			$table->integer('team_id');
20
+			$table->integer('player_id')->default(0);
21
+			$table->unsignedTinyInteger('goals')->default(0);
22
+			$table->unsignedTinyInteger('vote')->default(6);
23
+			$table->timestamps();
24
+		});
25
+	}
26 26
 }
Please login to merge, or discard this patch.
api/tests/ModelsTest.php 1 patch
Indentation   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -8,227 +8,227 @@
 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->assertGreaterThanOrEqual(
97
-                \App\Lib\Helpers\Config::get('generic.rosters')['min'],
98
-                count($team->roster)
99
-            );
100
-            $this->assertNotEmpty($team->name);
101
-            $this->assertNotEmpty($team->nationality);
102
-            $this->assertNotEmpty($team->getAvgSkill());
103
-            $this->assertNotEmpty($team->getAvgAge());
104
-        }
105
-    }
106
-
107
-    /**
108
-     * @group Match
109
-     */
110
-    public function testGetRandomMatch()
111
-    {
112
-        for ($i = 1; $i <= 30; $i++) {
113
-            $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
114
-            $spanish = $rndF->getTeam();
115
-            $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
116
-            $italian = $rndF->getTeam();
117
-            $this->assertNotEmpty($spanish);
118
-            $this->assertNotEmpty($italian);
119
-            $this->assertNotEmpty($italian->name);
120
-            $this->assertNotEmpty($spanish);
121
-            $this->assertNotEmpty($spanish->name);
122
-
123
-            $this->assertNotEmpty($italian->getAvgSkill());
124
-            $this->assertNotEmpty($spanish->getAvgSkill());
125
-            $result = (new \App\Lib\DsManager\Models\Match($italian, $spanish))->simulate()->toArray();
126
-            $this->assertNotEmpty($result);
127
-            $this->assertGreaterThanOrEqual(0, $result['goal_home']);
128
-            $this->assertGreaterThanOrEqual(0, $result['goal_away']);
129
-
130
-        }
131
-    }
132
-
133
-    /**
134
-     * @group Match
135
-     * @group MatchResult
136
-     * @group matchresultoutput
137
-     */
138
-    public function testMatchFromExistingTeams()
139
-    {
140
-        $teamHome = 1;
141
-        $teamAway = 2;
142
-        $homeOrm = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->where(['id' => $teamHome])->first();
143
-        $awayOrm = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->where(['id' => $teamAway])->first();
144
-        $home = \App\Lib\DsManager\Models\Team::fromArray($homeOrm->toArray());
145
-        $away = \App\Lib\DsManager\Models\Team::fromArray($awayOrm->toArray());
146
-
147
-        $match = new \App\Lib\DsManager\Models\Match($home, $away);
148
-        $result = $match->simulate()->toArray();
149
-        $this->assertNotEmpty($result);
150
-        $this->assertGreaterThanOrEqual(0, $result['goal_away']);
151
-        $this->assertGreaterThanOrEqual(0, $result['goal_home']);
152
-        if ($result['goal_home'] > 0) {
153
-            $this->assertNotEmpty($result['info']['scorers']['home']);
154
-            foreach ($result['info']['scorers']['home'] as $scorerHome) {
155
-                $this->assertEquals($scorerHome->team_id, $teamHome);
156
-            }
157
-        } else {
158
-            $this->assertEmpty($result['info']['scorers']['home']);
159
-        }
160
-        if ($result['goal_away'] > 0) {
161
-            $this->assertNotEmpty($result['info']['scorers']['away']);
162
-            foreach ($result['info']['scorers']['away'] as $scorerAway) {
163
-                $this->assertEquals($scorerAway->team_id, $teamAway);
164
-            }
165
-        } else {
166
-            $this->assertEmpty($result['info']['scorers']['away']);
167
-        }
168
-        if ($result['goal_home'] == $result['goal_away']) {
169
-            $this->assertTrue($result['info']['is_draw']);
170
-        } else {
171
-            $this->assertFalse($result['info']['is_draw']);
172
-        }
173
-    }
174
-
175
-    /**
176
-     * @group Matches
177
-     */
178
-    public function testGetRandomMatchesOneTeam()
179
-    {
180
-        $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
181
-        $myTeam = $rndF->getTeam();
182
-        $myTeam->id = 1000;
183
-        $win = 0;
184
-        $lost = 0;
185
-        $draw = 0;
186
-
187
-        for ($i = 1; $i <= 2; $i++) {
188
-
189
-            $randomLocale = \App\Lib\Helpers\Config::get('generic.localesSmall');
190
-            shuffle($randomLocale);
191
-            $randomLocale = $randomLocale[0];
192
-            $rndF = new \App\Lib\DsManager\Helpers\RandomFiller($randomLocale);
193
-            $opponent = $rndF->getTeam();
194
-            $opponent->id = 6000;
195
-            $result = (new \App\Lib\DsManager\Models\Match($opponent, $myTeam))->simulate()->toArray();
196
-            $this->assertNotEmpty($result);
197
-            $result = $result['info'];
198
-            if (!$result['is_draw']) {
199
-                if ($result['winner_id'] == $myTeam->id) {
200
-                    $win++;
201
-                } else {
202
-                    $lost++;
203
-                }
204
-            } else {
205
-                $draw++;
206
-            }
207
-        }
208
-        $this->assertGreaterThanOrEqual(0, $win);
209
-        $this->assertGreaterThanOrEqual(0, $lost);
210
-        $this->assertGreaterThanOrEqual(0, $draw);
211
-    }
212
-
213
-    /**
214
-     * @group Module
215
-     */
216
-    public function testModule()
217
-    {
218
-        $rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
219
-        $team = $rndF->getTeam();
220
-
221
-        $modules = \App\Lib\Helpers\Config::get("modules.modules");
222
-        $modules = array_keys($modules);
223
-        foreach ($modules as $mod) {
224
-            $module = new \App\Lib\DsManager\Models\Module($mod);
225
-            $this->assertNotEmpty($module);
226
-            $this->assertNotNull($module->isDefensive());
227
-            $this->assertNotNull($module->isBalanced());
228
-            $this->assertNotNull($module->isOffensive());
229
-            $this->assertTrue(is_array($module->getRoleNeeded()));
230
-        }
231
-        $this->assertGreaterThan(0, $team->playersPerRoleArray());
232
-    }
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->assertGreaterThanOrEqual(
97
+				\App\Lib\Helpers\Config::get('generic.rosters')['min'],
98
+				count($team->roster)
99
+			);
100
+			$this->assertNotEmpty($team->name);
101
+			$this->assertNotEmpty($team->nationality);
102
+			$this->assertNotEmpty($team->getAvgSkill());
103
+			$this->assertNotEmpty($team->getAvgAge());
104
+		}
105
+	}
106
+
107
+	/**
108
+	 * @group Match
109
+	 */
110
+	public function testGetRandomMatch()
111
+	{
112
+		for ($i = 1; $i <= 30; $i++) {
113
+			$rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
114
+			$spanish = $rndF->getTeam();
115
+			$rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
116
+			$italian = $rndF->getTeam();
117
+			$this->assertNotEmpty($spanish);
118
+			$this->assertNotEmpty($italian);
119
+			$this->assertNotEmpty($italian->name);
120
+			$this->assertNotEmpty($spanish);
121
+			$this->assertNotEmpty($spanish->name);
122
+
123
+			$this->assertNotEmpty($italian->getAvgSkill());
124
+			$this->assertNotEmpty($spanish->getAvgSkill());
125
+			$result = (new \App\Lib\DsManager\Models\Match($italian, $spanish))->simulate()->toArray();
126
+			$this->assertNotEmpty($result);
127
+			$this->assertGreaterThanOrEqual(0, $result['goal_home']);
128
+			$this->assertGreaterThanOrEqual(0, $result['goal_away']);
129
+
130
+		}
131
+	}
132
+
133
+	/**
134
+	 * @group Match
135
+	 * @group MatchResult
136
+	 * @group matchresultoutput
137
+	 */
138
+	public function testMatchFromExistingTeams()
139
+	{
140
+		$teamHome = 1;
141
+		$teamAway = 2;
142
+		$homeOrm = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->where(['id' => $teamHome])->first();
143
+		$awayOrm = \App\Lib\DsManager\Models\Orm\Team::with('roster', 'coach')->where(['id' => $teamAway])->first();
144
+		$home = \App\Lib\DsManager\Models\Team::fromArray($homeOrm->toArray());
145
+		$away = \App\Lib\DsManager\Models\Team::fromArray($awayOrm->toArray());
146
+
147
+		$match = new \App\Lib\DsManager\Models\Match($home, $away);
148
+		$result = $match->simulate()->toArray();
149
+		$this->assertNotEmpty($result);
150
+		$this->assertGreaterThanOrEqual(0, $result['goal_away']);
151
+		$this->assertGreaterThanOrEqual(0, $result['goal_home']);
152
+		if ($result['goal_home'] > 0) {
153
+			$this->assertNotEmpty($result['info']['scorers']['home']);
154
+			foreach ($result['info']['scorers']['home'] as $scorerHome) {
155
+				$this->assertEquals($scorerHome->team_id, $teamHome);
156
+			}
157
+		} else {
158
+			$this->assertEmpty($result['info']['scorers']['home']);
159
+		}
160
+		if ($result['goal_away'] > 0) {
161
+			$this->assertNotEmpty($result['info']['scorers']['away']);
162
+			foreach ($result['info']['scorers']['away'] as $scorerAway) {
163
+				$this->assertEquals($scorerAway->team_id, $teamAway);
164
+			}
165
+		} else {
166
+			$this->assertEmpty($result['info']['scorers']['away']);
167
+		}
168
+		if ($result['goal_home'] == $result['goal_away']) {
169
+			$this->assertTrue($result['info']['is_draw']);
170
+		} else {
171
+			$this->assertFalse($result['info']['is_draw']);
172
+		}
173
+	}
174
+
175
+	/**
176
+	 * @group Matches
177
+	 */
178
+	public function testGetRandomMatchesOneTeam()
179
+	{
180
+		$rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
181
+		$myTeam = $rndF->getTeam();
182
+		$myTeam->id = 1000;
183
+		$win = 0;
184
+		$lost = 0;
185
+		$draw = 0;
186
+
187
+		for ($i = 1; $i <= 2; $i++) {
188
+
189
+			$randomLocale = \App\Lib\Helpers\Config::get('generic.localesSmall');
190
+			shuffle($randomLocale);
191
+			$randomLocale = $randomLocale[0];
192
+			$rndF = new \App\Lib\DsManager\Helpers\RandomFiller($randomLocale);
193
+			$opponent = $rndF->getTeam();
194
+			$opponent->id = 6000;
195
+			$result = (new \App\Lib\DsManager\Models\Match($opponent, $myTeam))->simulate()->toArray();
196
+			$this->assertNotEmpty($result);
197
+			$result = $result['info'];
198
+			if (!$result['is_draw']) {
199
+				if ($result['winner_id'] == $myTeam->id) {
200
+					$win++;
201
+				} else {
202
+					$lost++;
203
+				}
204
+			} else {
205
+				$draw++;
206
+			}
207
+		}
208
+		$this->assertGreaterThanOrEqual(0, $win);
209
+		$this->assertGreaterThanOrEqual(0, $lost);
210
+		$this->assertGreaterThanOrEqual(0, $draw);
211
+	}
212
+
213
+	/**
214
+	 * @group Module
215
+	 */
216
+	public function testModule()
217
+	{
218
+		$rndF = new \App\Lib\DsManager\Helpers\RandomFiller("it_IT");
219
+		$team = $rndF->getTeam();
220
+
221
+		$modules = \App\Lib\Helpers\Config::get("modules.modules");
222
+		$modules = array_keys($modules);
223
+		foreach ($modules as $mod) {
224
+			$module = new \App\Lib\DsManager\Models\Module($mod);
225
+			$this->assertNotEmpty($module);
226
+			$this->assertNotNull($module->isDefensive());
227
+			$this->assertNotNull($module->isBalanced());
228
+			$this->assertNotNull($module->isOffensive());
229
+			$this->assertTrue(is_array($module->getRoleNeeded()));
230
+		}
231
+		$this->assertGreaterThan(0, $team->playersPerRoleArray());
232
+	}
233 233
 
234 234
 }
Please login to merge, or discard this patch.
api/Lib/DsManager/Models/MatchResult.php 1 patch
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -13,118 +13,118 @@
 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 = $this->awayTeam;
55
-        $loser = $this->homeTeam;
56
-        if ($this->goalAway == $this->goalHome) {
57
-            $isDraw = true;
58
-        } else if ($this->goalHome < $this->goalAway) {
59
-            $winner = $this->awayTeam;
60
-            $loser = $this->homeTeam;
61
-        }
62
-        return [
63
-            'is_draw' => $isDraw,
64
-            'winner_id' => $winner->id,
65
-            'loser_id' => $loser->id
66
-        ];
67
-    }
48
+	/**
49
+	 * @return array
50
+	 */
51
+	public function getWinnerLoser()
52
+	{
53
+		$isDraw = false;
54
+		$winner = $this->awayTeam;
55
+		$loser = $this->homeTeam;
56
+		if ($this->goalAway == $this->goalHome) {
57
+			$isDraw = true;
58
+		} else if ($this->goalHome < $this->goalAway) {
59
+			$winner = $this->awayTeam;
60
+			$loser = $this->homeTeam;
61
+		}
62
+		return [
63
+			'is_draw' => $isDraw,
64
+			'winner_id' => $winner->id,
65
+			'loser_id' => $loser->id
66
+		];
67
+	}
68 68
 
69
-    /**
70
-     * @return array
71
-     */
72
-    public function toArray()
73
-    {
74
-        $result = [];
75
-        $result['home_team_id'] = $this->homeTeam->id;
76
-        $result['away_team_id'] = $this->awayTeam->id;
77
-        $result['goal_home'] = $this->goalHome;
78
-        $result['goal_away'] = $this->goalAway;
79
-        $result['info'] = $this->getWinnerLoser();
80
-        $result['info']['scorers'] = $this->getScorers();
81
-        $result['simulated'] = true;
82
-        return $result;
83
-    }
84
-    /**
85
-     * @return array
86
-     */
87
-    private function getScorers()
88
-    {
89
-        $scorers = [
90
-            'home' => [],
91
-            'away' => []
92
-        ];
93
-        for ($i = 0; $i < $this->goalHome; $i++) {
94
-            $scorers['home'][] = $this->pickAScorer($this->homeTeam);
95
-        }
96
-        for ($i = 0; $i < $this->goalAway; $i++) {
97
-            $scorers['away'][] = $this->pickAScorer($this->awayTeam);
98
-        }
99
-        return $scorers;
100
-    }
69
+	/**
70
+	 * @return array
71
+	 */
72
+	public function toArray()
73
+	{
74
+		$result = [];
75
+		$result['home_team_id'] = $this->homeTeam->id;
76
+		$result['away_team_id'] = $this->awayTeam->id;
77
+		$result['goal_home'] = $this->goalHome;
78
+		$result['goal_away'] = $this->goalAway;
79
+		$result['info'] = $this->getWinnerLoser();
80
+		$result['info']['scorers'] = $this->getScorers();
81
+		$result['simulated'] = true;
82
+		return $result;
83
+	}
84
+	/**
85
+	 * @return array
86
+	 */
87
+	private function getScorers()
88
+	{
89
+		$scorers = [
90
+			'home' => [],
91
+			'away' => []
92
+		];
93
+		for ($i = 0; $i < $this->goalHome; $i++) {
94
+			$scorers['home'][] = $this->pickAScorer($this->homeTeam);
95
+		}
96
+		for ($i = 0; $i < $this->goalAway; $i++) {
97
+			$scorers['away'][] = $this->pickAScorer($this->awayTeam);
98
+		}
99
+		return $scorers;
100
+	}
101 101
 
102
-    /**
103
-     * @param Team $team
104
-     * @return Player
105
-     */
106
-    private function pickAScorer(Team $team)
107
-    {
108
-        $player = null;
109
-        if (Randomizer::boolOnPercentage(70)) {
110
-            $roles = Config::get('modules.roles');
111
-            $forwards = array_splice($roles, count($roles) / 2);
112
-            $pos = array_rand($forwards);
113
-            unset($forwards[$pos]);
114
-            $player = $team->getBestPlayerForRole($pos);
115
-            while (empty($player)) {
116
-                if (!empty($forwards)) {
117
-                    $pos = array_rand($forwards);
118
-                    unset($forwards[$pos]);
119
-                    $player = $team->getBestPlayerForRole($pos);
120
-                } else {
121
-                    $player = $team->roster[array_rand($team->roster)];
122
-                }
123
-            }
124
-        } else {
125
-            $player = $team->roster[array_rand($team->roster)];
126
-        }
127
-        return $player;
128
-    }
102
+	/**
103
+	 * @param Team $team
104
+	 * @return Player
105
+	 */
106
+	private function pickAScorer(Team $team)
107
+	{
108
+		$player = null;
109
+		if (Randomizer::boolOnPercentage(70)) {
110
+			$roles = Config::get('modules.roles');
111
+			$forwards = array_splice($roles, count($roles) / 2);
112
+			$pos = array_rand($forwards);
113
+			unset($forwards[$pos]);
114
+			$player = $team->getBestPlayerForRole($pos);
115
+			while (empty($player)) {
116
+				if (!empty($forwards)) {
117
+					$pos = array_rand($forwards);
118
+					unset($forwards[$pos]);
119
+					$player = $team->getBestPlayerForRole($pos);
120
+				} else {
121
+					$player = $team->roster[array_rand($team->roster)];
122
+				}
123
+			}
124
+		} else {
125
+			$player = $team->roster[array_rand($team->roster)];
126
+		}
127
+		return $player;
128
+	}
129 129
 
130 130
 }
131 131
\ No newline at end of file
Please login to merge, or discard this patch.
api/Lib/DsManager/Models/Orm/MatchResult.php 1 patch
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -8,91 +8,91 @@
 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 resolveAttributes(array $attributes, $matchId)
37
-    {
38
-        if (array_key_exists('info', $attributes)) {
39
-            if (array_key_exists('scorers', $attributes['info'])) {
40
-                foreach ($attributes['info']['scorers']['home'] as $scorerHome) {
41
-                    self::addScorer($matchId, $attributes['home_team_id'], $scorerHome->id);
42
-                }
43
-                foreach ($attributes['info']['scorers']['away'] as $scorerAway) {
44
-                    self::addScorer($matchId, $attributes['away_team_id'], $scorerAway->id);
45
-                }
46
-                unset($attributes['info']['scorers']);
47
-            }
48
-            $attributes['info'] = json_encode($attributes['info']);
49
-        }
50
-        return $attributes;
51
-    }
36
+	public static function resolveAttributes(array $attributes, $matchId)
37
+	{
38
+		if (array_key_exists('info', $attributes)) {
39
+			if (array_key_exists('scorers', $attributes['info'])) {
40
+				foreach ($attributes['info']['scorers']['home'] as $scorerHome) {
41
+					self::addScorer($matchId, $attributes['home_team_id'], $scorerHome->id);
42
+				}
43
+				foreach ($attributes['info']['scorers']['away'] as $scorerAway) {
44
+					self::addScorer($matchId, $attributes['away_team_id'], $scorerAway->id);
45
+				}
46
+				unset($attributes['info']['scorers']);
47
+			}
48
+			$attributes['info'] = json_encode($attributes['info']);
49
+		}
50
+		return $attributes;
51
+	}
52 52
 
53
-    private static function addScorer($matchId, $teamId, $playerId)
54
-    {
55
-        $scorer = MatchPlayer::where(
56
-            [
57
-                'match_id' => $matchId,
58
-                'team_id' => $teamId,
59
-                'player_id' => $playerId
60
-            ]
61
-        )->where('goals', '>', 0)->first();
62
-        if (!empty($scorer)) {
63
-            $scorer->goals = $scorer->goals + 1;
64
-            $scorer->vote = $scorer->vote + rand(0, 1);
65
-            $scorer->save();
66
-        } else {
67
-            MatchPlayer::create(
68
-                [
69
-                    'match_id' => $matchId,
70
-                    'team_id' => $teamId,
71
-                    'player_id' => $playerId,
72
-                    'goals' => 1
73
-                ]
74
-            );
75
-        }
76
-    }
53
+	private static function addScorer($matchId, $teamId, $playerId)
54
+	{
55
+		$scorer = MatchPlayer::where(
56
+			[
57
+				'match_id' => $matchId,
58
+				'team_id' => $teamId,
59
+				'player_id' => $playerId
60
+			]
61
+		)->where('goals', '>', 0)->first();
62
+		if (!empty($scorer)) {
63
+			$scorer->goals = $scorer->goals + 1;
64
+			$scorer->vote = $scorer->vote + rand(0, 1);
65
+			$scorer->save();
66
+		} else {
67
+			MatchPlayer::create(
68
+				[
69
+					'match_id' => $matchId,
70
+					'team_id' => $teamId,
71
+					'player_id' => $playerId,
72
+					'goals' => 1
73
+				]
74
+			);
75
+		}
76
+	}
77 77
 
78
-    public function scorers()
79
-    {
80
-        return $this->belongsToMany(
81
-            Player::class,
82
-            'match_players',
83
-            'match_id'
84
-        )->withPivot(
85
-            'team_id',
86
-            'goals'
87
-        )->where(
88
-            'goals', '>', 0
89
-        );
90
-    }
78
+	public function scorers()
79
+	{
80
+		return $this->belongsToMany(
81
+			Player::class,
82
+			'match_players',
83
+			'match_id'
84
+		)->withPivot(
85
+			'team_id',
86
+			'goals'
87
+		)->where(
88
+			'goals', '>', 0
89
+		);
90
+	}
91 91
 
92
-    public function scopeComplete($query)
93
-    {
94
-        return parent::scopeComplete($query)->with('scorers');
95
-    }
92
+	public function scopeComplete($query)
93
+	{
94
+		return parent::scopeComplete($query)->with('scorers');
95
+	}
96 96
 
97 97
 
98 98
 }
99 99
\ No newline at end of file
Please login to merge, or discard this patch.