Completed
Push — master ( 543190...5d04a1 )
by Vincenzo
02:30
created
api/Lib/DsManager/Helpers/Randomizer.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -10,22 +10,22 @@
 block discarded – undo
10 10
  */
11 11
 class Randomizer
12 12
 {
13
-    /**
14
-     * @param $percentage
15
-     * @return bool
16
-     */
17
-    public static function boolOnPercentage($percentage)
18
-    {
19
-        return (rand(0, 100) < $percentage);
20
-    }
13
+	/**
14
+	 * @param $percentage
15
+	 * @return bool
16
+	 */
17
+	public static function boolOnPercentage($percentage)
18
+	{
19
+		return (rand(0, 100) < $percentage);
20
+	}
21 21
 
22
-    /**
23
-     * @param $skill
24
-     * @return int
25
-     */
26
-    public static function voteFromSkill($skill)
27
-    {
28
-        return rand((2 * ($skill - 100) / 25), 10);
29
-    }
22
+	/**
23
+	 * @param $skill
24
+	 * @return int
25
+	 */
26
+	public static function voteFromSkill($skill)
27
+	{
28
+		return rand((2 * ($skill - 100) / 25), 10);
29
+	}
30 30
 
31 31
 }
32 32
\ No newline at end of file
Please login to merge, or discard this patch.
api/Lib/DsManager/Models/Orm/MatchResult.php 1 patch
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -9,118 +9,118 @@
 block discarded – undo
9 9
  */
10 10
 class MatchResult extends Match
11 11
 {
12
-    /**
13
-     * @var array
14
-     */
15
-    protected $fillable = [
16
-        'goal_home',
17
-        'goal_away',
18
-        'info',
19
-        'simulated'
20
-    ];
12
+	/**
13
+	 * @var array
14
+	 */
15
+	protected $fillable = [
16
+		'goal_home',
17
+		'goal_away',
18
+		'info',
19
+		'simulated'
20
+	];
21 21
 
22
-    protected $hidden = [
23
-        'home_team_id',
24
-        'away_team_id',
25
-        'created_at',
26
-        'updated_at'
27
-    ];
22
+	protected $hidden = [
23
+		'home_team_id',
24
+		'away_team_id',
25
+		'created_at',
26
+		'updated_at'
27
+	];
28 28
 
29
-    /**
30
-     * @var array
31
-     */
32
-    protected $casts = [
33
-        'info' => 'json',
34
-        'simulated' => 'boolean'
35
-    ];
29
+	/**
30
+	 * @var array
31
+	 */
32
+	protected $casts = [
33
+		'info' => 'json',
34
+		'simulated' => 'boolean'
35
+	];
36 36
 
37
-    public static function resolveAttributes(array $attributes, $matchId)
38
-    {
39
-        self::generateAppearances(
40
-            [
41
-                $attributes['home_team_id'],
42
-                $attributes['away_team_id']
43
-            ],
44
-            $matchId
45
-        );
46
-        if (array_key_exists('info', $attributes)) {
47
-            if (array_key_exists('scorers', $attributes['info'])) {
48
-                foreach ($attributes['info']['scorers']['home'] as $scorerHome) {
49
-                    self::addScorer($matchId, $attributes['home_team_id'], $scorerHome->id);
50
-                }
51
-                foreach ($attributes['info']['scorers']['away'] as $scorerAway) {
52
-                    self::addScorer($matchId, $attributes['away_team_id'], $scorerAway->id);
53
-                }
54
-                unset($attributes['info']['scorers']);
55
-            }
56
-            $attributes['info'] = json_encode($attributes['info']);
57
-        }
58
-        return $attributes;
59
-    }
37
+	public static function resolveAttributes(array $attributes, $matchId)
38
+	{
39
+		self::generateAppearances(
40
+			[
41
+				$attributes['home_team_id'],
42
+				$attributes['away_team_id']
43
+			],
44
+			$matchId
45
+		);
46
+		if (array_key_exists('info', $attributes)) {
47
+			if (array_key_exists('scorers', $attributes['info'])) {
48
+				foreach ($attributes['info']['scorers']['home'] as $scorerHome) {
49
+					self::addScorer($matchId, $attributes['home_team_id'], $scorerHome->id);
50
+				}
51
+				foreach ($attributes['info']['scorers']['away'] as $scorerAway) {
52
+					self::addScorer($matchId, $attributes['away_team_id'], $scorerAway->id);
53
+				}
54
+				unset($attributes['info']['scorers']);
55
+			}
56
+			$attributes['info'] = json_encode($attributes['info']);
57
+		}
58
+		return $attributes;
59
+	}
60 60
 
61
-    private static function addScorer($matchId, $teamId, $playerId)
62
-    {
63
-        $scorer = MatchPlayer::where(
64
-            [
65
-                'match_id' => $matchId,
66
-                'team_id' => $teamId,
67
-                'player_id' => $playerId
68
-            ]
69
-        )->first();
70
-        if (!empty($scorer)) {
71
-            $scorer->goals = $scorer->goals + 1;
72
-            $scorer->vote = $scorer->vote <= 9 ? $scorer->vote + rand(0, 1) : $scorer->vote;
73
-            $scorer->save();
74
-        } else {
75
-            MatchPlayer::create(
76
-                [
77
-                    'match_id' => $matchId,
78
-                    'team_id' => $teamId,
79
-                    'player_id' => $playerId,
80
-                    'goals' => 1
81
-                ]
82
-            );
83
-        }
84
-    }
61
+	private static function addScorer($matchId, $teamId, $playerId)
62
+	{
63
+		$scorer = MatchPlayer::where(
64
+			[
65
+				'match_id' => $matchId,
66
+				'team_id' => $teamId,
67
+				'player_id' => $playerId
68
+			]
69
+		)->first();
70
+		if (!empty($scorer)) {
71
+			$scorer->goals = $scorer->goals + 1;
72
+			$scorer->vote = $scorer->vote <= 9 ? $scorer->vote + rand(0, 1) : $scorer->vote;
73
+			$scorer->save();
74
+		} else {
75
+			MatchPlayer::create(
76
+				[
77
+					'match_id' => $matchId,
78
+					'team_id' => $teamId,
79
+					'player_id' => $playerId,
80
+					'goals' => 1
81
+				]
82
+			);
83
+		}
84
+	}
85 85
 
86
-    private static function generateAppearances(
87
-        $teamIds,
88
-        $matchId
89
-    )
90
-    {
91
-        foreach ($teamIds as $id) {
92
-            $players = Player::where('team_id', $id)->get()->random(11);
93
-            foreach ($players as $player) {
94
-                MatchPlayer::create(
95
-                    [
96
-                        'match_id' => $matchId,
97
-                        'team_id' => $id,
98
-                        'player_id' => $player->id,
99
-                        'vote' => Randomizer::voteFromSkill($player->skillAvg)
100
-                    ]
101
-                );
102
-            }
103
-        }
104
-    }
86
+	private static function generateAppearances(
87
+		$teamIds,
88
+		$matchId
89
+	)
90
+	{
91
+		foreach ($teamIds as $id) {
92
+			$players = Player::where('team_id', $id)->get()->random(11);
93
+			foreach ($players as $player) {
94
+				MatchPlayer::create(
95
+					[
96
+						'match_id' => $matchId,
97
+						'team_id' => $id,
98
+						'player_id' => $player->id,
99
+						'vote' => Randomizer::voteFromSkill($player->skillAvg)
100
+					]
101
+				);
102
+			}
103
+		}
104
+	}
105 105
 
106
-    public function scorers()
107
-    {
108
-        return $this->belongsToMany(
109
-            Player::class,
110
-            'match_players',
111
-            'match_id'
112
-        )->withPivot(
113
-            'team_id',
114
-            'goals'
115
-        )->where(
116
-            'goals', '>', 0
117
-        );
118
-    }
106
+	public function scorers()
107
+	{
108
+		return $this->belongsToMany(
109
+			Player::class,
110
+			'match_players',
111
+			'match_id'
112
+		)->withPivot(
113
+			'team_id',
114
+			'goals'
115
+		)->where(
116
+			'goals', '>', 0
117
+		);
118
+	}
119 119
 
120
-    public function scopeComplete($query)
121
-    {
122
-        return parent::scopeComplete($query)->with('scorers');
123
-    }
120
+	public function scopeComplete($query)
121
+	{
122
+		return parent::scopeComplete($query)->with('scorers');
123
+	}
124 124
 
125 125
 
126 126
 }
127 127
\ No newline at end of file
Please login to merge, or discard this patch.
api/Lib/DsManager/Models/Orm/Player.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -9,70 +9,70 @@
 block discarded – undo
9 9
 class Player extends DsManagerOrm
10 10
 {
11 11
 
12
-    /**
13
-     * @var string
14
-     */
15
-    protected $table = 'players';
12
+	/**
13
+	 * @var string
14
+	 */
15
+	protected $table = 'players';
16 16
 
17
-    /**
18
-     * @var array
19
-     */
20
-    protected $fillable = [
21
-        'name',
22
-        'surname',
23
-        'age',
24
-        'nationality',
25
-        'skillAvg',
26
-        'wageReq',
27
-        'val',
28
-        'role',
29
-        'team_id'
30
-    ];
17
+	/**
18
+	 * @var array
19
+	 */
20
+	protected $fillable = [
21
+		'name',
22
+		'surname',
23
+		'age',
24
+		'nationality',
25
+		'skillAvg',
26
+		'wageReq',
27
+		'val',
28
+		'role',
29
+		'team_id'
30
+	];
31 31
 
32
-    /**
33
-     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
34
-     */
35
-    public function team()
36
-    {
37
-        return $this->belongsTo(Team::class);
38
-    }
32
+	/**
33
+	 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
34
+	 */
35
+	public function team()
36
+	{
37
+		return $this->belongsTo(Team::class);
38
+	}
39 39
 
40
-    public function lastMatches()
41
-    {
42
-        return $this->hasMany(MatchPlayer::class)
43
-            ->orderBy('updated_at', 'DESC')
44
-            ->limit(5);
45
-    }
40
+	public function lastMatches()
41
+	{
42
+		return $this->hasMany(MatchPlayer::class)
43
+			->orderBy('updated_at', 'DESC')
44
+			->limit(5);
45
+	}
46 46
 
47
-    public function goals()
48
-    {
49
-        return $this->hasOne(MatchPlayer::class)
50
-            ->selectRaw('player_id, sum(goals) as count')
51
-            ->groupBy('player_id');
52
-    }
47
+	public function goals()
48
+	{
49
+		return $this->hasOne(MatchPlayer::class)
50
+			->selectRaw('player_id, sum(goals) as count')
51
+			->groupBy('player_id');
52
+	}
53 53
 
54
-    public function appearances()
55
-    {
56
-        return $this->hasOne(MatchPlayer::class)
57
-            ->selectRaw('player_id, count(match_id) as count')
58
-            ->groupBy('player_id');
59
-    }
54
+	public function appearances()
55
+	{
56
+		return $this->hasOne(MatchPlayer::class)
57
+			->selectRaw('player_id, count(match_id) as count')
58
+			->groupBy('player_id');
59
+	}
60 60
 
61
-    public function avg()
62
-    {
63
-        return $this->hasOne(MatchPlayer::class)
64
-            ->selectRaw('player_id, round(avg(vote),2) as avg')
65
-            ->groupBy('player_id');
66
-    }
61
+	public function avg()
62
+	{
63
+		return $this->hasOne(MatchPlayer::class)
64
+			->selectRaw('player_id, round(avg(vote),2) as avg')
65
+			->groupBy('player_id');
66
+	}
67 67
 
68
-    public function scopeStatistics($query)
69
-    {
70
-        return $query->with(
71
-            'goals',
72
-            'appearances',
73
-            'avg',
74
-            'lastMatches',
75
-            'team'
76
-        );
77
-    }
68
+	public function scopeStatistics($query)
69
+	{
70
+		return $query->with(
71
+			'goals',
72
+			'appearances',
73
+			'avg',
74
+			'lastMatches',
75
+			'team'
76
+		);
77
+	}
78 78
 }
79 79
\ 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.
api/Lib/DsManager/Models/Orm/League.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -8,23 +8,23 @@
 block discarded – undo
8 8
  */
9 9
 class League extends DsManagerOrm
10 10
 {
11
-    /**
12
-     * @var string
13
-     */
14
-    protected $table = 'leagues';
11
+	/**
12
+	 * @var string
13
+	 */
14
+	protected $table = 'leagues';
15 15
 
16
-    /**
17
-     * @var array
18
-     */
19
-    protected $fillable = [
20
-        'name'
21
-    ];
16
+	/**
17
+	 * @var array
18
+	 */
19
+	protected $fillable = [
20
+		'name'
21
+	];
22 22
 
23
-    /**
24
-     * @return \Illuminate\Database\Eloquent\Relations\HasMany
25
-     */
26
-    public function match_days()
27
-    {
28
-        return $this->hasMany(MatchDay::class);
29
-    }
23
+	/**
24
+	 * @return \Illuminate\Database\Eloquent\Relations\HasMany
25
+	 */
26
+	public function match_days()
27
+	{
28
+		return $this->hasMany(MatchDay::class);
29
+	}
30 30
 } 
31 31
\ No newline at end of file
Please login to merge, or discard this patch.
api/Lib/DsManager/Models/Orm/MatchDay.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -9,32 +9,32 @@
 block discarded – undo
9 9
 class MatchDay extends DsManagerOrm
10 10
 {
11 11
 
12
-    /**
13
-     * @var string
14
-     */
15
-    protected $table = 'league_match_days';
12
+	/**
13
+	 * @var string
14
+	 */
15
+	protected $table = 'league_match_days';
16 16
 
17
-    /**
18
-     * @var array
19
-     */
20
-    protected $fillable = [
21
-        'league_id',
22
-        'day'
23
-    ];
17
+	/**
18
+	 * @var array
19
+	 */
20
+	protected $fillable = [
21
+		'league_id',
22
+		'day'
23
+	];
24 24
 
25
-    /**
26
-     * @return \Illuminate\Database\Eloquent\Relations\HasOne
27
-     */
28
-    public function league()
29
-    {
30
-        return $this->hasOne(League::class);
31
-    }
25
+	/**
26
+	 * @return \Illuminate\Database\Eloquent\Relations\HasOne
27
+	 */
28
+	public function league()
29
+	{
30
+		return $this->hasOne(League::class);
31
+	}
32 32
 
33
-    /**
34
-     * @return \Illuminate\Database\Eloquent\Relations\HasMany
35
-     */
36
-    public function matches()
37
-    {
38
-        return $this->hasMany(Match::class);
39
-    }
33
+	/**
34
+	 * @return \Illuminate\Database\Eloquent\Relations\HasMany
35
+	 */
36
+	public function matches()
37
+	{
38
+		return $this->hasMany(Match::class);
39
+	}
40 40
 }
41 41
\ No newline at end of file
Please login to merge, or discard this patch.
api/database/migrations/CreateLeaguesTable.php 2 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -5,18 +5,18 @@
 block discarded – undo
5 5
 
6 6
 class CreateLeaguesTable
7 7
 {
8
-    /**
9
-     * Run the migrations.
10
-     *
11
-     * @return void
12
-     */
13
-    public function run()
14
-    {
15
-        Capsule::schema()->dropIfExists('leagues');
16
-        Capsule::schema()->create('leagues', function (Blueprint $table) {
17
-            $table->increments('id');
18
-            $table->string('name');
19
-            $table->timestamps();
20
-        });
21
-    }
8
+	/**
9
+	 * Run the migrations.
10
+	 *
11
+	 * @return void
12
+	 */
13
+	public function run()
14
+	{
15
+		Capsule::schema()->dropIfExists('leagues');
16
+		Capsule::schema()->create('leagues', function (Blueprint $table) {
17
+			$table->increments('id');
18
+			$table->string('name');
19
+			$table->timestamps();
20
+		});
21
+	}
22 22
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
     public function run()
14 14
     {
15 15
         Capsule::schema()->dropIfExists('leagues');
16
-        Capsule::schema()->create('leagues', function (Blueprint $table) {
16
+        Capsule::schema()->create('leagues', function(Blueprint $table) {
17 17
             $table->increments('id');
18 18
             $table->string('name');
19 19
             $table->timestamps();
Please login to merge, or discard this patch.
api/database/migrations/CreateLeagueMatchDaysTable.php 2 patches
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -5,19 +5,19 @@
 block discarded – undo
5 5
 
6 6
 class CreateLeagueMatchDaysTable
7 7
 {
8
-    /**
9
-     * Run the migrations.
10
-     *
11
-     * @return void
12
-     */
13
-    public function run()
14
-    {
15
-        Capsule::schema()->dropIfExists('league_match_days');
16
-        Capsule::schema()->create('league_match_days', function (Blueprint $table) {
17
-            $table->increments('id');
18
-            $table->integer('league_id');
19
-            $table->integer('day')->default(0);
20
-            $table->timestamps();
21
-        });
22
-    }
8
+	/**
9
+	 * Run the migrations.
10
+	 *
11
+	 * @return void
12
+	 */
13
+	public function run()
14
+	{
15
+		Capsule::schema()->dropIfExists('league_match_days');
16
+		Capsule::schema()->create('league_match_days', function (Blueprint $table) {
17
+			$table->increments('id');
18
+			$table->integer('league_id');
19
+			$table->integer('day')->default(0);
20
+			$table->timestamps();
21
+		});
22
+	}
23 23
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
     public function run()
14 14
     {
15 15
         Capsule::schema()->dropIfExists('league_match_days');
16
-        Capsule::schema()->create('league_match_days', function (Blueprint $table) {
16
+        Capsule::schema()->create('league_match_days', function(Blueprint $table) {
17 17
             $table->increments('id');
18 18
             $table->integer('league_id');
19 19
             $table->integer('day')->default(0);
Please login to merge, or discard this patch.
api/database/seeds/A001LeaguesSeeder.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -3,28 +3,28 @@
 block discarded – undo
3 3
 
4 4
 class A001LeaguesSeeder
5 5
 {
6
-    function run()
7
-    {
8
-        $leagues = [
9
-            'friendly' => 5,
10
-            'europa league' => 2
11
-        ];
6
+	function run()
7
+	{
8
+		$leagues = [
9
+			'friendly' => 5,
10
+			'europa league' => 2
11
+		];
12 12
 
13
-        foreach ($leagues as $league => $dayMatches) {
14
-            $league = \App\Lib\DsManager\Models\Orm\League::create(
15
-                [
16
-                    'name' => $league
17
-                ]
18
-            );
13
+		foreach ($leagues as $league => $dayMatches) {
14
+			$league = \App\Lib\DsManager\Models\Orm\League::create(
15
+				[
16
+					'name' => $league
17
+				]
18
+			);
19 19
 
20
-            for ($i = 1; $i <= $dayMatches; $i++) {
21
-                \App\Lib\DsManager\Models\Orm\MatchDay::create(
22
-                    [
23
-                        'league_id' => $league->id,
24
-                        'day' => $i
25
-                    ]
26
-                );
27
-            }
28
-        }
29
-    }
20
+			for ($i = 1; $i <= $dayMatches; $i++) {
21
+				\App\Lib\DsManager\Models\Orm\MatchDay::create(
22
+					[
23
+						'league_id' => $league->id,
24
+						'day' => $i
25
+					]
26
+				);
27
+			}
28
+		}
29
+	}
30 30
 }
31 31
\ No newline at end of file
Please login to merge, or discard this patch.