This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php namespace Xaoc303\BattleCalc; |
||
2 | |||
3 | use View; |
||
4 | |||
5 | /** |
||
6 | * Class BattleCalc |
||
7 | * @package Xaoc303\BattleCalc |
||
8 | */ |
||
9 | class BattleCalc |
||
10 | { |
||
11 | /** |
||
12 | * @var string |
||
13 | */ |
||
14 | private $log = ''; |
||
15 | |||
16 | /** |
||
17 | * @var int |
||
18 | */ |
||
19 | private $round = 0; |
||
20 | |||
21 | /** |
||
22 | * @var Army |
||
23 | */ |
||
24 | private $army1; |
||
25 | |||
26 | /** |
||
27 | * @var Army |
||
28 | */ |
||
29 | private $army2; |
||
30 | |||
31 | /** |
||
32 | * calculation |
||
33 | * |
||
34 | * @param array $army_1 |
||
35 | * @param array $army_2 |
||
36 | * @return string |
||
37 | */ |
||
38 | public function calculation(&$army_1, &$army_2) |
||
39 | { |
||
40 | $this->army1 = new Army($army_1); |
||
41 | $this->army2 = new Army($army_2); |
||
42 | |||
43 | $this->war(); |
||
44 | |||
45 | return $this->log; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * war |
||
50 | */ |
||
51 | private function war() |
||
52 | { |
||
53 | $MaxIniciative = 0; |
||
54 | |||
55 | $ManCount1 = $this->army1->manCount($MaxIniciative); |
||
56 | $ManCount2 = $this->army2->manCount($MaxIniciative); |
||
57 | |||
58 | $Round = 0; |
||
59 | $this->round = $Round; |
||
60 | $this->addLog($Round); |
||
61 | |||
62 | while (($ManCount1 > 0) && ($ManCount2 > 0) && ($Round < 50)) { |
||
63 | $this->battle($ManCount1, $ManCount2, $MaxIniciative, $Round); |
||
64 | |||
65 | $Round++; |
||
66 | $this->round = $Round; |
||
67 | $MaxIniciative--; |
||
68 | $this->addLog($Round); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * battle |
||
74 | * |
||
75 | * @param integer $ManCount1 |
||
76 | * @param integer $ManCount2 |
||
77 | * @param integer $MaxIniciative |
||
78 | * @param integer $Round |
||
79 | */ |
||
80 | private function battle(&$ManCount1, &$ManCount2, &$MaxIniciative, &$Round) |
||
81 | { |
||
82 | $this->army1->shadow($this->army2, $MaxIniciative); |
||
83 | $this->army2->shadow($this->army1, $MaxIniciative); |
||
84 | |||
85 | $this->army1->clear(); |
||
86 | $this->army2->clear(); |
||
87 | |||
88 | ArmyAttack::run($this->army1, $this->army2, $MaxIniciative); |
||
89 | ArmyAttack::run($this->army2, $this->army1, $MaxIniciative); |
||
90 | |||
91 | $this->army1->attackNull($this->army2->manCountVisible(1)); |
||
92 | $this->army2->attackNull($this->army1->manCountVisible(1)); |
||
93 | |||
94 | ArmyLog::colorize($this->army1); |
||
95 | ArmyLog::colorize($this->army2); |
||
96 | |||
97 | if ($this->isExitRound($Round)) { |
||
98 | ob_start(); |
||
99 | echo '$Round = '.$Round.'<br />'; |
||
100 | echo '$MaxIniciative = '.$MaxIniciative.'<br />'; |
||
101 | echo '$ManCount1 = '.$ManCount1.'<br />'; |
||
102 | echo '$ManCount2 = '.$ManCount2.'<br />'; |
||
103 | echo '<pre>'.print_r($this->army1, true).'</pre>'; |
||
104 | echo '<pre>'.print_r($this->army2, true).'</pre>'; |
||
105 | echo $this->log; |
||
106 | ob_end_flush(); |
||
107 | exit; |
||
0 ignored issues
–
show
|
|||
108 | } |
||
109 | |||
110 | ArmyDamage::run($this->army2, $this->army1); |
||
111 | ArmyDamage::run($this->army1, $this->army2); |
||
112 | |||
113 | $ManCount1 = $this->army1->count(); |
||
114 | $ManCount2 = $this->army2->count(); |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * exitRound |
||
119 | * |
||
120 | * @param integer $Round |
||
121 | * @return bool |
||
122 | */ |
||
123 | private function isExitRound($Round) |
||
124 | { |
||
125 | $ERound = false; |
||
126 | /* |
||
127 | int DamageT1 = 0; |
||
128 | int DamageT2 = 0; |
||
129 | int DamageA1 = 0; |
||
130 | int DamageA2 = 0; |
||
131 | int DamageM1 = 0; |
||
132 | int DamageM2 = 0; |
||
133 | int ManCountT1 = 0; |
||
134 | int ManCountT2 = 0; |
||
135 | int ManCountA1 = 0; |
||
136 | int ManCountA2 = 0; |
||
137 | |||
138 | for (int i=0; i<Army1.size(); i++) |
||
139 | { |
||
140 | DamageT1 += Army1[i].AttackTer; |
||
141 | DamageA1 += Army1[i].AttackAir; |
||
142 | DamageM1 += Army1[i].AttackMagic; |
||
143 | if (Army1[i].UT==Ter) ManCountT1 += Army1[i].ManCount; |
||
144 | if (Army1[i].UT==Air) ManCountA1 += Army1[i].ManCount; |
||
145 | } |
||
146 | |||
147 | for (int i=0; i<Army2.size(); i++) |
||
148 | { |
||
149 | DamageT2 += Army2[i].AttackTer; |
||
150 | DamageA2 += Army2[i].AttackAir; |
||
151 | DamageM2 += Army2[i].AttackMagic; |
||
152 | if (Army2[i].UT==Ter) ManCountT2 += Army2[i].ManCount; |
||
153 | if (Army2[i].UT==Air) ManCountA2 += Army2[i].ManCount; |
||
154 | } |
||
155 | |||
156 | if (ManCountT2==0) DamageT1=0; |
||
157 | if (ManCountA2==0) DamageA1=0; |
||
158 | if (ManCountT1==0) DamageT2=0; |
||
159 | if (ManCountA1==0) DamageA2=0; |
||
160 | |||
161 | if (Inic<0) |
||
162 | if ((DamageT1==0 && DamageA1==0) || (DamageT2==0 && DamageA2==0)) |
||
163 | ERound = true; |
||
164 | */ |
||
165 | |||
166 | if ($Round > 50) { |
||
167 | $ERound = true; |
||
168 | } |
||
169 | |||
170 | return $ERound; |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * addLog |
||
175 | * |
||
176 | * @param integer $Round |
||
177 | */ |
||
178 | private function addLog($Round) |
||
179 | { |
||
180 | $this->log .= '----------------- ROUND '.$Round.' ----------------'; |
||
181 | $this->log .= View::make('battle-calc::views.log')->with('units', $this->army1->getUnits())->render(); |
||
182 | $this->log .= View::make('battle-calc::views.log')->with('units', $this->army2->getUnits())->render(); |
||
183 | $this->log .= '<br />'; |
||
184 | } |
||
185 | } |
||
186 |
An exit expression should only be used in rare cases. For example, if you write a short command line script.
In most cases however, using an
exit
expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.