@@ -5,19 +5,19 @@ |
||
5 | 5 | |
6 | 6 | class CreateTeamTable |
7 | 7 | { |
8 | - /** |
|
9 | - * Run the migrations. |
|
10 | - * |
|
11 | - * @return void |
|
12 | - */ |
|
13 | - public function run() |
|
14 | - { |
|
15 | - Capsule::schema()->dropIfExists('teams'); |
|
16 | - Capsule::schema()->create('teams', function (Blueprint $table) { |
|
17 | - $table->increments('id'); |
|
18 | - $table->string('name'); |
|
19 | - $table->string('nationality',2); |
|
20 | - $table->timestamps(); |
|
21 | - }); |
|
22 | - } |
|
8 | + /** |
|
9 | + * Run the migrations. |
|
10 | + * |
|
11 | + * @return void |
|
12 | + */ |
|
13 | + public function run() |
|
14 | + { |
|
15 | + Capsule::schema()->dropIfExists('teams'); |
|
16 | + Capsule::schema()->create('teams', function (Blueprint $table) { |
|
17 | + $table->increments('id'); |
|
18 | + $table->string('name'); |
|
19 | + $table->string('nationality',2); |
|
20 | + $table->timestamps(); |
|
21 | + }); |
|
22 | + } |
|
23 | 23 | } |
@@ -5,35 +5,35 @@ |
||
5 | 5 | |
6 | 6 | class CreateCoachesTable |
7 | 7 | { |
8 | - /** |
|
9 | - * Run the migrations. |
|
10 | - * |
|
11 | - * @return void |
|
12 | - */ |
|
13 | - public function run() |
|
14 | - { |
|
15 | - Capsule::schema()->dropIfExists('coaches'); |
|
16 | - Capsule::schema()->create('coaches', function (Blueprint $table) { |
|
17 | - $table->increments('id'); |
|
18 | - $table->string('name'); |
|
19 | - $table->string('surname'); |
|
20 | - $table->tinyInteger('age'); |
|
21 | - $table->string('nationality',2); |
|
22 | - $table->float('skillAvg'); |
|
23 | - $table->float('wageReq'); |
|
24 | - $table->string('favouriteModule',10); |
|
25 | - $table->integer('team_id')->nullable(); |
|
26 | - $table->timestamps(); |
|
27 | - }); |
|
28 | - } |
|
8 | + /** |
|
9 | + * Run the migrations. |
|
10 | + * |
|
11 | + * @return void |
|
12 | + */ |
|
13 | + public function run() |
|
14 | + { |
|
15 | + Capsule::schema()->dropIfExists('coaches'); |
|
16 | + Capsule::schema()->create('coaches', function (Blueprint $table) { |
|
17 | + $table->increments('id'); |
|
18 | + $table->string('name'); |
|
19 | + $table->string('surname'); |
|
20 | + $table->tinyInteger('age'); |
|
21 | + $table->string('nationality',2); |
|
22 | + $table->float('skillAvg'); |
|
23 | + $table->float('wageReq'); |
|
24 | + $table->string('favouriteModule',10); |
|
25 | + $table->integer('team_id')->nullable(); |
|
26 | + $table->timestamps(); |
|
27 | + }); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Reverse the migrations. |
|
32 | - * |
|
33 | - * @return void |
|
34 | - */ |
|
35 | - public function down() |
|
36 | - { |
|
37 | - Schema::drop('coaches'); |
|
38 | - } |
|
30 | + /** |
|
31 | + * Reverse the migrations. |
|
32 | + * |
|
33 | + * @return void |
|
34 | + */ |
|
35 | + public function down() |
|
36 | + { |
|
37 | + Schema::drop('coaches'); |
|
38 | + } |
|
39 | 39 | } |
@@ -5,26 +5,26 @@ |
||
5 | 5 | |
6 | 6 | class CreatePlayersTable |
7 | 7 | { |
8 | - /** |
|
9 | - * Run the migrations. |
|
10 | - * |
|
11 | - * @return void |
|
12 | - */ |
|
13 | - public function run() |
|
14 | - { |
|
15 | - Capsule::schema()->dropIfExists('players'); |
|
16 | - Capsule::schema()->create('players', function (Blueprint $table) { |
|
17 | - $table->increments('id'); |
|
18 | - $table->string('name'); |
|
19 | - $table->string('surname'); |
|
20 | - $table->tinyInteger('age'); |
|
21 | - $table->string('nationality',2); |
|
22 | - $table->float('skillAvg'); |
|
23 | - $table->float('wageReq'); |
|
24 | - $table->float('val'); |
|
25 | - $table->string('role',2); |
|
26 | - $table->integer('team_id')->nullable(); |
|
27 | - $table->timestamps(); |
|
28 | - }); |
|
29 | - } |
|
8 | + /** |
|
9 | + * Run the migrations. |
|
10 | + * |
|
11 | + * @return void |
|
12 | + */ |
|
13 | + public function run() |
|
14 | + { |
|
15 | + Capsule::schema()->dropIfExists('players'); |
|
16 | + Capsule::schema()->create('players', function (Blueprint $table) { |
|
17 | + $table->increments('id'); |
|
18 | + $table->string('name'); |
|
19 | + $table->string('surname'); |
|
20 | + $table->tinyInteger('age'); |
|
21 | + $table->string('nationality',2); |
|
22 | + $table->float('skillAvg'); |
|
23 | + $table->float('wageReq'); |
|
24 | + $table->float('val'); |
|
25 | + $table->string('role',2); |
|
26 | + $table->integer('team_id')->nullable(); |
|
27 | + $table->timestamps(); |
|
28 | + }); |
|
29 | + } |
|
30 | 30 | } |
@@ -4,9 +4,9 @@ discard block |
||
4 | 4 | |
5 | 5 | $dotenv = new Dotenv\Dotenv(__DIR__ . "/../"); |
6 | 6 | try { |
7 | - $dotenv->load(); |
|
7 | + $dotenv->load(); |
|
8 | 8 | } catch (Exception $e) { |
9 | - //yummy exception |
|
9 | + //yummy exception |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | /** |
@@ -14,14 +14,14 @@ discard block |
||
14 | 14 | */ |
15 | 15 | $capsule = new Capsule; |
16 | 16 | $capsule->addConnection(array( |
17 | - 'driver' => 'mysql', |
|
18 | - 'host' => 'localhost', |
|
19 | - 'database' => 'dsmanager', |
|
20 | - 'username' => getenv('USERNAME'), |
|
21 | - 'password' => getenv('PASSWORD'), |
|
22 | - 'charset' => 'utf8', |
|
23 | - 'collation' => 'utf8_general_ci', |
|
24 | - 'prefix' => '' |
|
17 | + 'driver' => 'mysql', |
|
18 | + 'host' => 'localhost', |
|
19 | + 'database' => 'dsmanager', |
|
20 | + 'username' => getenv('USERNAME'), |
|
21 | + 'password' => getenv('PASSWORD'), |
|
22 | + 'charset' => 'utf8', |
|
23 | + 'collation' => 'utf8_general_ci', |
|
24 | + 'prefix' => '' |
|
25 | 25 | )); |
26 | 26 | $capsule->setAsGlobal(); |
27 | 27 | $capsule->bootEloquent(); |
@@ -11,164 +11,164 @@ |
||
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 |
@@ -74,10 +74,10 @@ |
||
74 | 74 | 'ro_MD', |
75 | 75 | 'tr_TR' |
76 | 76 | ], |
77 | - 'rosters' => [ |
|
78 | - 'min' => 11, |
|
79 | - 'max' => 18 |
|
80 | - ], |
|
77 | + 'rosters' => [ |
|
78 | + 'min' => 11, |
|
79 | + 'max' => 18 |
|
80 | + ], |
|
81 | 81 | ]; |
82 | 82 | |
83 | 83 |
@@ -8,101 +8,101 @@ |
||
8 | 8 | { |
9 | 9 | |
10 | 10 | |
11 | - /** |
|
12 | - * @group OrmModels |
|
13 | - * @group PlayerOrm |
|
14 | - */ |
|
15 | - public function testPlayerOrmGetSet() |
|
16 | - { |
|
17 | - $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
18 | - $playerM = $rndFiller->getPlayer(); |
|
19 | - $arrayPl = $playerM->toArray(); |
|
20 | - $playerO = \App\Lib\DsManager\Models\Orm\Player::create($arrayPl); |
|
21 | - $this->assertNotEmpty($playerO); |
|
11 | + /** |
|
12 | + * @group OrmModels |
|
13 | + * @group PlayerOrm |
|
14 | + */ |
|
15 | + public function testPlayerOrmGetSet() |
|
16 | + { |
|
17 | + $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
18 | + $playerM = $rndFiller->getPlayer(); |
|
19 | + $arrayPl = $playerM->toArray(); |
|
20 | + $playerO = \App\Lib\DsManager\Models\Orm\Player::create($arrayPl); |
|
21 | + $this->assertNotEmpty($playerO); |
|
22 | 22 | |
23 | - $newPlayer = \App\Lib\DsManager\Models\Player::fromArray($playerO->toArray()); |
|
24 | - $this->assertNotEmpty($newPlayer); |
|
25 | - } |
|
23 | + $newPlayer = \App\Lib\DsManager\Models\Player::fromArray($playerO->toArray()); |
|
24 | + $this->assertNotEmpty($newPlayer); |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * @group OrmModels |
|
29 | - * @group CoachOrm |
|
30 | - */ |
|
31 | - public function testCoachOrmGetSet() |
|
32 | - { |
|
33 | - $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
34 | - $coach = $rndFiller->getCoach(); |
|
35 | - $arrayPl = $coach->toArray(); |
|
36 | - $coachO = \App\Lib\DsManager\Models\Orm\Coach::create($arrayPl); |
|
37 | - $this->assertNotEmpty($coachO); |
|
27 | + /** |
|
28 | + * @group OrmModels |
|
29 | + * @group CoachOrm |
|
30 | + */ |
|
31 | + public function testCoachOrmGetSet() |
|
32 | + { |
|
33 | + $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
34 | + $coach = $rndFiller->getCoach(); |
|
35 | + $arrayPl = $coach->toArray(); |
|
36 | + $coachO = \App\Lib\DsManager\Models\Orm\Coach::create($arrayPl); |
|
37 | + $this->assertNotEmpty($coachO); |
|
38 | 38 | |
39 | - $newCoach = \App\Lib\DsManager\Models\Coach::fromArray($coachO->toArray()); |
|
40 | - $this->assertNotEmpty($newCoach); |
|
41 | - } |
|
39 | + $newCoach = \App\Lib\DsManager\Models\Coach::fromArray($coachO->toArray()); |
|
40 | + $this->assertNotEmpty($newCoach); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @group OrmModels |
|
45 | - * @group TeamOrm |
|
46 | - */ |
|
47 | - public function testTeamOrm() |
|
48 | - { |
|
49 | - $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
50 | - $team = $rndFiller->getTeam($rndFiller->getLocale()); |
|
51 | - $teamArray = $team->toArray(); |
|
52 | - $this->assertNotEmpty($team); |
|
53 | - $teamO = \App\Lib\DsManager\Models\Orm\Team::create($teamArray); |
|
54 | - $this->assertNotEmpty($teamArray); |
|
55 | - $this->assertNotEmpty($teamArray['roster']); |
|
56 | - foreach ($teamArray['roster'] as $player) { |
|
57 | - $player['team_id'] = $teamO->id; |
|
58 | - $playerO = \App\Lib\DsManager\Models\Orm\Player::create($player); |
|
59 | - $this->assertNotEmpty($playerO); |
|
60 | - } |
|
61 | - $teamArray['coach']['team_id'] = $teamO->id; |
|
62 | - $coachO = \App\Lib\DsManager\Models\Orm\Coach::create($teamArray['coach']); |
|
63 | - $this->assertNotEmpty($coachO); |
|
43 | + /** |
|
44 | + * @group OrmModels |
|
45 | + * @group TeamOrm |
|
46 | + */ |
|
47 | + public function testTeamOrm() |
|
48 | + { |
|
49 | + $rndFiller = new \App\Lib\DsManager\Helpers\RandomFiller(); |
|
50 | + $team = $rndFiller->getTeam($rndFiller->getLocale()); |
|
51 | + $teamArray = $team->toArray(); |
|
52 | + $this->assertNotEmpty($team); |
|
53 | + $teamO = \App\Lib\DsManager\Models\Orm\Team::create($teamArray); |
|
54 | + $this->assertNotEmpty($teamArray); |
|
55 | + $this->assertNotEmpty($teamArray['roster']); |
|
56 | + foreach ($teamArray['roster'] as $player) { |
|
57 | + $player['team_id'] = $teamO->id; |
|
58 | + $playerO = \App\Lib\DsManager\Models\Orm\Player::create($player); |
|
59 | + $this->assertNotEmpty($playerO); |
|
60 | + } |
|
61 | + $teamArray['coach']['team_id'] = $teamO->id; |
|
62 | + $coachO = \App\Lib\DsManager\Models\Orm\Coach::create($teamArray['coach']); |
|
63 | + $this->assertNotEmpty($coachO); |
|
64 | 64 | |
65 | - $this->assertNotEmpty( |
|
66 | - \App\Lib\DsManager\Models\Orm\Team::with( |
|
67 | - 'roster' |
|
68 | - )->with( |
|
69 | - 'coach' |
|
70 | - )->where( |
|
71 | - [ |
|
72 | - 'id' => $teamO->id |
|
73 | - ] |
|
74 | - )->get()->toArray() |
|
75 | - ); |
|
76 | - } |
|
65 | + $this->assertNotEmpty( |
|
66 | + \App\Lib\DsManager\Models\Orm\Team::with( |
|
67 | + 'roster' |
|
68 | + )->with( |
|
69 | + 'coach' |
|
70 | + )->where( |
|
71 | + [ |
|
72 | + 'id' => $teamO->id |
|
73 | + ] |
|
74 | + )->get()->toArray() |
|
75 | + ); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @group Match |
|
80 | - * @group createnewmatch |
|
81 | - */ |
|
82 | - public function testCreateNewMatch() |
|
83 | - { |
|
84 | - $teams = \App\Lib\DsManager\Models\Orm\Team::with( |
|
85 | - 'roster', |
|
86 | - 'coach' |
|
87 | - )->get(); |
|
88 | - $this->assertNotNull($teams); |
|
89 | - $teams = $teams->toArray(); |
|
90 | - $homeIndex = array_rand($teams); |
|
91 | - $teamHome = $teams[$homeIndex]; |
|
92 | - unset($teams[$homeIndex]); |
|
93 | - $teamAway = $teams[array_rand($teams)]; |
|
94 | - $this->assertNotNull($teamHome); |
|
95 | - $this->assertNotNull($teamAway); |
|
96 | - $matchO = \App\Lib\DsManager\Models\Orm\Match::create( |
|
97 | - [ |
|
98 | - 'home_team_id' => $teamHome['id'], |
|
99 | - 'away_team_id' => $teamAway['id'] |
|
100 | - ] |
|
101 | - ); |
|
102 | - $this->assertNotNull($matchO); |
|
103 | - $matchNew = \App\Lib\DsManager\Models\Orm\Match::complete()->where('id', $matchO->id)->first(); |
|
104 | - $this->assertNotNull($matchNew); |
|
105 | - $match = \App\Lib\DsManager\Models\Match::fromArray($matchNew->toArray()); |
|
106 | - $this->assertNotNull($match); |
|
107 | - } |
|
78 | + /** |
|
79 | + * @group Match |
|
80 | + * @group createnewmatch |
|
81 | + */ |
|
82 | + public function testCreateNewMatch() |
|
83 | + { |
|
84 | + $teams = \App\Lib\DsManager\Models\Orm\Team::with( |
|
85 | + 'roster', |
|
86 | + 'coach' |
|
87 | + )->get(); |
|
88 | + $this->assertNotNull($teams); |
|
89 | + $teams = $teams->toArray(); |
|
90 | + $homeIndex = array_rand($teams); |
|
91 | + $teamHome = $teams[$homeIndex]; |
|
92 | + unset($teams[$homeIndex]); |
|
93 | + $teamAway = $teams[array_rand($teams)]; |
|
94 | + $this->assertNotNull($teamHome); |
|
95 | + $this->assertNotNull($teamAway); |
|
96 | + $matchO = \App\Lib\DsManager\Models\Orm\Match::create( |
|
97 | + [ |
|
98 | + 'home_team_id' => $teamHome['id'], |
|
99 | + 'away_team_id' => $teamAway['id'] |
|
100 | + ] |
|
101 | + ); |
|
102 | + $this->assertNotNull($matchO); |
|
103 | + $matchNew = \App\Lib\DsManager\Models\Orm\Match::complete()->where('id', $matchO->id)->first(); |
|
104 | + $this->assertNotNull($matchNew); |
|
105 | + $match = \App\Lib\DsManager\Models\Match::fromArray($matchNew->toArray()); |
|
106 | + $this->assertNotNull($match); |
|
107 | + } |
|
108 | 108 | } |
@@ -8,45 +8,45 @@ |
||
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 |
@@ -15,157 +15,157 @@ |
||
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 |