@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | |
35 | 35 | /** |
36 | 36 | * @param $matchId |
37 | - * @return mixed |
|
37 | + * @return MatchResult |
|
38 | 38 | */ |
39 | 39 | public static function simulateCompleteResult($matchId) |
40 | 40 | { |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | |
51 | 51 | /** |
52 | 52 | * @param $matchId |
53 | - * @return mixed |
|
53 | + * @return MatchResult |
|
54 | 54 | */ |
55 | 55 | public static function simulateSimpleResult($matchId) |
56 | 56 | { |
@@ -14,109 +14,109 @@ |
||
14 | 14 | */ |
15 | 15 | class MatchSimulator |
16 | 16 | { |
17 | - /** |
|
18 | - * @param $roundId |
|
19 | - * @return string |
|
20 | - */ |
|
21 | - public static function simulateRound($roundId) |
|
22 | - { |
|
23 | - $matches = Match::where( |
|
24 | - [ |
|
25 | - 'league_round_id' => $roundId |
|
26 | - ] |
|
27 | - )->get(); |
|
28 | - $result = []; |
|
29 | - foreach ($matches as $match) { |
|
30 | - $result[] = self::simulateSimpleResult($match->id)->toArray(); |
|
31 | - } |
|
32 | - return json_encode($result); |
|
33 | - } |
|
17 | + /** |
|
18 | + * @param $roundId |
|
19 | + * @return string |
|
20 | + */ |
|
21 | + public static function simulateRound($roundId) |
|
22 | + { |
|
23 | + $matches = Match::where( |
|
24 | + [ |
|
25 | + 'league_round_id' => $roundId |
|
26 | + ] |
|
27 | + )->get(); |
|
28 | + $result = []; |
|
29 | + foreach ($matches as $match) { |
|
30 | + $result[] = self::simulateSimpleResult($match->id)->toArray(); |
|
31 | + } |
|
32 | + return json_encode($result); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param $matchId |
|
37 | - * @return mixed |
|
38 | - */ |
|
39 | - public static function simulateCompleteResult($matchId) |
|
40 | - { |
|
41 | - $result = self::getCompleteResult($matchId); |
|
42 | - if (!empty($result) |
|
43 | - && !$result->simulated |
|
44 | - && self::simulate($matchId) === 1 |
|
45 | - ) { |
|
46 | - $result = self::getCompleteResult($matchId); |
|
47 | - } |
|
48 | - return $result; |
|
49 | - } |
|
35 | + /** |
|
36 | + * @param $matchId |
|
37 | + * @return mixed |
|
38 | + */ |
|
39 | + public static function simulateCompleteResult($matchId) |
|
40 | + { |
|
41 | + $result = self::getCompleteResult($matchId); |
|
42 | + if (!empty($result) |
|
43 | + && !$result->simulated |
|
44 | + && self::simulate($matchId) === 1 |
|
45 | + ) { |
|
46 | + $result = self::getCompleteResult($matchId); |
|
47 | + } |
|
48 | + return $result; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param $matchId |
|
53 | - * @return mixed |
|
54 | - */ |
|
55 | - public static function simulateSimpleResult($matchId) |
|
56 | - { |
|
57 | - $result = self::getSimpleResult($matchId); |
|
58 | - if (!empty($result) |
|
59 | - && !$result->simulated |
|
60 | - && self::simulate($matchId) === 1 |
|
61 | - ) { |
|
62 | - $result = self::getSimpleResult($matchId); |
|
63 | - } |
|
64 | - return $result; |
|
65 | - } |
|
51 | + /** |
|
52 | + * @param $matchId |
|
53 | + * @return mixed |
|
54 | + */ |
|
55 | + public static function simulateSimpleResult($matchId) |
|
56 | + { |
|
57 | + $result = self::getSimpleResult($matchId); |
|
58 | + if (!empty($result) |
|
59 | + && !$result->simulated |
|
60 | + && self::simulate($matchId) === 1 |
|
61 | + ) { |
|
62 | + $result = self::getSimpleResult($matchId); |
|
63 | + } |
|
64 | + return $result; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @param $matchId |
|
69 | - * @return mixed |
|
70 | - */ |
|
71 | - private static function simulate($matchId) |
|
72 | - { |
|
73 | - $match = \App\Lib\DsManager\Models\Match::fromArray( |
|
74 | - MatchOrm::complete() |
|
75 | - ->where( |
|
76 | - [ |
|
77 | - 'id' => $matchId |
|
78 | - ] |
|
79 | - )->first()->toArray() |
|
80 | - ); |
|
81 | - $matchResult = $match->simulate()->toArray(); |
|
82 | - $result = MatchResult::where( |
|
83 | - [ |
|
84 | - 'id' => $matchId |
|
85 | - ] |
|
86 | - )->update( |
|
87 | - MatchResult::resolveAttributes( |
|
88 | - $matchResult, |
|
89 | - $matchId |
|
90 | - ) |
|
91 | - ); |
|
92 | - return $result; |
|
93 | - } |
|
67 | + /** |
|
68 | + * @param $matchId |
|
69 | + * @return mixed |
|
70 | + */ |
|
71 | + private static function simulate($matchId) |
|
72 | + { |
|
73 | + $match = \App\Lib\DsManager\Models\Match::fromArray( |
|
74 | + MatchOrm::complete() |
|
75 | + ->where( |
|
76 | + [ |
|
77 | + 'id' => $matchId |
|
78 | + ] |
|
79 | + )->first()->toArray() |
|
80 | + ); |
|
81 | + $matchResult = $match->simulate()->toArray(); |
|
82 | + $result = MatchResult::where( |
|
83 | + [ |
|
84 | + 'id' => $matchId |
|
85 | + ] |
|
86 | + )->update( |
|
87 | + MatchResult::resolveAttributes( |
|
88 | + $matchResult, |
|
89 | + $matchId |
|
90 | + ) |
|
91 | + ); |
|
92 | + return $result; |
|
93 | + } |
|
94 | 94 | |
95 | 95 | |
96 | - /** |
|
97 | - * @param $matchId |
|
98 | - * @return MatchResult |
|
99 | - */ |
|
100 | - private static function getCompleteResult($matchId) |
|
101 | - { |
|
102 | - return MatchResult::complete()->where( |
|
103 | - [ |
|
104 | - 'id' => $matchId |
|
105 | - ] |
|
106 | - )->first(); |
|
107 | - } |
|
96 | + /** |
|
97 | + * @param $matchId |
|
98 | + * @return MatchResult |
|
99 | + */ |
|
100 | + private static function getCompleteResult($matchId) |
|
101 | + { |
|
102 | + return MatchResult::complete()->where( |
|
103 | + [ |
|
104 | + 'id' => $matchId |
|
105 | + ] |
|
106 | + )->first(); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * @param $matchId |
|
111 | - * @return MatchResult |
|
112 | - */ |
|
113 | - private static function getSimpleResult($matchId) |
|
114 | - { |
|
115 | - return MatchResult::teams()->where( |
|
116 | - [ |
|
117 | - 'id' => $matchId |
|
118 | - ] |
|
119 | - )->first(); |
|
120 | - } |
|
109 | + /** |
|
110 | + * @param $matchId |
|
111 | + * @return MatchResult |
|
112 | + */ |
|
113 | + private static function getSimpleResult($matchId) |
|
114 | + { |
|
115 | + return MatchResult::teams()->where( |
|
116 | + [ |
|
117 | + 'id' => $matchId |
|
118 | + ] |
|
119 | + )->first(); |
|
120 | + } |
|
121 | 121 | |
122 | 122 | } |
123 | 123 | \ No newline at end of file |