GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ResearchManager::update()   F
last analyzed

Complexity

Conditions 34
Paths 12366

Size

Total Lines 194
Code Lines 165

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 34
eloc 165
nc 12366
nop 6
dl 0
loc 194
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * ResearchManager
5
 *
6
 * @author Jacky Casas
7
 * @copyright Expansion - le jeu
8
 *
9
 * @package Prométhée
10
 * @update 20.05.13
11
*/
12
13
namespace Asylamba\Modules\Promethee\Manager;
14
15
use Asylamba\Classes\Worker\Manager;
16
use Asylamba\Classes\Database\Database;
17
use Asylamba\Classes\Library\Utils;
18
use Asylamba\Classes\Container\StackList;
19
20
use Asylamba\Modules\Promethee\Model\Research;
21
22
use Asylamba\Modules\Zeus\Manager\PlayerManager;
23
use Asylamba\Modules\Hermes\Manager\NotificationManager;
24
use Asylamba\Modules\Promethee\Helper\ResearchHelper;
25
use Asylamba\Modules\Hermes\Model\Notification;
26
use Asylamba\Modules\Demeter\Resource\ColorResource;
27
28
use Asylamba\Classes\Exception\ErrorException;
29
30
class ResearchManager extends Manager {
31
	/** @var string **/
32
	protected $managerType = '_Research';
33
	/** @var PlayerManager **/
34
	protected $playerManager;
35
	/** @var NotificationManager **/
36
	protected $notificationManager;
37
	/** @var ResearchHelper **/
38
	protected $researchHelper;
39
	/** @var int **/
40
	protected $researchQuantity;
41
	
42
	/**
43
	 * @param Database $database
44
	 * @param PlayerManager $playerManager
45
	 * @param NotificationManager $notificationManager
46
	 * @param ResearchHelper $researchHelper
47
	 * @param int $researchQuantity
48
	 */
49
	public function __construct(
50
		Database $database,
51
		PlayerManager $playerManager,
52
		NotificationManager $notificationManager,
53
		ResearchHelper $researchHelper,
54
		$researchQuantity
55
	)
56
	{
0 ignored issues
show
Coding Style introduced by
The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
Loading history...
57
		parent::__construct($database);
58
		$this->playerManager = $playerManager;
59
		$this->notificationManager = $notificationManager;
60
		$this->researchHelper = $researchHelper;
61
		$this->researchQuantity = $researchQuantity;
62
	}
63
	
64
	public function load($where = array(), $order = array(), $limit = array()) {
65
		$formatWhere = Utils::arrayToWhere($where);
66
		$formatOrder = Utils::arrayToOrder($order);
67
		$formatLimit = Utils::arrayToLimit($limit);
68
69
		$qr = $this->database->prepare('SELECT *
70
			FROM research
71
			' . $formatWhere . '
72
			' . $formatOrder . '
73
			' . $formatLimit
74
		);
75
76
		foreach($where AS $v) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FOREACH keyword; 0 found
Loading history...
Coding Style introduced by
AS keyword must be lowercase; expected "as" but found "AS"
Loading history...
Coding Style introduced by
As per coding-style, PHP keywords should be in lowercase; expected as, but found AS.
Loading history...
77
			if (is_array($v)) {
78
				foreach ($v as $p) {
79
					$valuesArray[] = $p;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$valuesArray was never initialized. Although not strictly required by PHP, it is generally a good practice to add $valuesArray = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
80
				}
81
			} else {
82
				$valuesArray[] = $v;
0 ignored issues
show
Bug introduced by
The variable $valuesArray does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
83
			}
84
		}
85
86
		if (empty($valuesArray)) {
87
			$qr->execute();
88
		} else {
89
			$qr->execute($valuesArray);
90
		}
91
92
		while($aw = $qr->fetch()) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after WHILE keyword; 0 found
Loading history...
93
			$res = new Research();
94
95
			$res->rPlayer = $aw['rPlayer'];
96
			$res->mathLevel = $aw['mathLevel'];
97
			$res->physLevel = $aw['physLevel'];
98
			$res->chemLevel = $aw['chemLevel'];
99
			$res->bioLevel = $aw['bioLevel'];
100
			$res->mediLevel = $aw['mediLevel'];
101
			$res->econoLevel = $aw['econoLevel'];
102
			$res->psychoLevel = $aw['psychoLevel'];
103
			$res->networkLevel = $aw['networkLevel'];
104
			$res->algoLevel = $aw['algoLevel'];
105
			$res->statLevel = $aw['statLevel'];
106
			$res->naturalTech = $aw['naturalTech'];
107
			$res->lifeTech = $aw['lifeTech'];
108
			$res->socialTech = $aw['socialTech'];
109
			$res->informaticTech = $aw['informaticTech'];
110
			$res->naturalToPay = $aw['naturalToPay'];
111
			$res->lifeToPay = $aw['lifeToPay'];
112
			$res->socialToPay = $aw['socialToPay'];
113
			$res->informaticToPay = $aw['informaticToPay'];
114
			
115
			$this->_Add($res);
116
		}
117
	}
118
119
	public function add(Research $res) {
120
		$qr = $this->database->prepare('INSERT INTO
121
			research(rPlayer, mathLevel, physLevel, chemLevel, bioLevel, mediLevel, econoLevel, psychoLevel, networkLevel, algoLevel, statLevel, naturalTech, lifeTech, socialTech, informaticTech, naturalToPay, lifeToPay, socialToPay, informaticToPay)
122
			VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
123
		$qr->execute(array(
124
			$res->rPlayer,
125
			$res->mathLevel,
126
			$res->physLevel,
127
			$res->chemLevel,
128
			$res->bioLevel,
129
			$res->mediLevel,
130
			$res->econoLevel,
131
			$res->psychoLevel,
132
			$res->networkLevel,
133
			$res->algoLevel,
134
			$res->statLevel,
135
			$res->naturalTech,
136
			$res->lifeTech,
137
			$res->socialTech,
138
			$res->informaticTech,
139
			$res->naturalToPay,
140
			$res->lifeToPay,
141
			$res->socialToPay,
142
			$res->informaticToPay
143
		));
144
145
		$this->_Add($res);
146
	}
147
148
	public function save() {
149
		$researches = $this->_Save();
150
151
		foreach ($researches AS $k => $res) {
0 ignored issues
show
Coding Style introduced by
AS keyword must be lowercase; expected "as" but found "AS"
Loading history...
Coding Style introduced by
As per coding-style, PHP keywords should be in lowercase; expected as, but found AS.
Loading history...
152
			$qr = $this->database->prepare('UPDATE research
153
				SET	rPlayer = ?,
154
					mathLevel = ?,
155
					physLevel = ?,
156
					chemLevel = ?,
157
					bioLevel = ?,
158
					mediLevel = ?,
159
					econoLevel = ?,
160
					psychoLevel = ?,
161
					networkLevel = ?,
162
					algoLevel = ?,
163
					statLevel = ?,
164
					naturalTech = ?,
165
					lifeTech = ?,
166
					socialTech = ?,
167
					informaticTech = ?,
168
					naturalToPay = ?,
169
					lifeToPay = ?,
170
					socialToPay = ?,
171
					informaticToPay = ?
172
				WHERE rPlayer = ?');
173
			$qr->execute(array(
174
				$res->rPlayer,
175
				$res->mathLevel,
176
				$res->physLevel,
177
				$res->chemLevel,
178
				$res->bioLevel,
179
				$res->mediLevel,
180
				$res->econoLevel,
181
				$res->psychoLevel,
182
				$res->networkLevel,
183
				$res->algoLevel,
184
				$res->statLevel,
185
				$res->naturalTech,
186
				$res->lifeTech,
187
				$res->socialTech,
188
				$res->informaticTech,
189
				$res->naturalToPay,
190
				$res->lifeToPay,
191
				$res->socialToPay,
192
				$res->informaticToPay,
193
				$res->rPlayer
194
			));
195
		}
196
	}
197
198
	public function update(Research $research, $playerId, $naturalInvest, $lifeInvest, $socialInvest, $informaticInvest) {
199
		# prestige
200
		$player = $this->playerManager->get($playerId);
201
		$applyPrestige = FALSE;
0 ignored issues
show
Unused Code introduced by
$applyPrestige is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
202
		if ($player->rColor == ColorResource::APHERA) {
203
			$applyPrestige = TRUE;
0 ignored issues
show
Unused Code introduced by
$applyPrestige is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
204
		}
205
		// natural technologies
206
		do {
207
			if ($research->naturalToPay > $naturalInvest) {
208
				$research->naturalToPay -= $naturalInvest;
209
				$naturalInvest = 0;
210
			} else {
211
				$naturalInvest -= $research->naturalToPay;
212
				switch ($research->naturalTech) {
213
					case 0 :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
214
						$research->mathLevel++;
215
						$levelReached = $research->mathLevel;
216
						break;
217
					case 1 :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
218
						$research->physLevel++;
219
						$levelReached = $research->physLevel;
220
						break;
221
					case 2 :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
222
						$research->chemLevel++;
223
						$levelReached = $research->chemLevel;
224
						break;
225
					default :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a DEFAULT statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in the default statement.

switch ($expr) {
    default : //wrong
        doSomething();
        break;
}

switch ($expr) {
    default: //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
226
						$levelReached = 0;
0 ignored issues
show
Unused Code introduced by
$levelReached is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
227
						throw new ErrorException('une erreur est survenue lors de la mise à jour des technologies');
228
				}
229
230
				$n = new Notification();
231
				$n->setRPlayer($playerId);
232
				$n->setTitle($this->researchHelper->getInfo($research->naturalTech, 'name') . ' niveau ' . $levelReached);
233
				$n->setContent('Vos investissements dans l\'Université ont payé !<br />
234
					Vos chercheurs du département des <strong>Sciences Naturelles</strong> ont fait des avancées en <strong>' 
235
					. $this->researchHelper->getInfo($research->naturalTech, 'name') . '</strong>. Vous êtes actuellement au <strong>niveau ' 
236
					. $levelReached . '</strong> dans ce domaine. Félicitations !');
237
				$this->notificationManager->add($n);
238
				do {
239
					$research->naturalTech = rand(0, 2); // 0, 1 ou 2
240
					$tech1 = $research->mathLevel;
241
					$tech2 = $research->physLevel;
242
					$tech3 = $research->chemLevel;
243
					switch ($research->naturalTech) {
244
						case 0 : $tech1++; break;
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
245
						case 1 : $tech2++; break;
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
246
						case 2 : $tech3++; break;
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
247
						default :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a DEFAULT statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in the default statement.

switch ($expr) {
    default : //wrong
        doSomething();
        break;
}

switch ($expr) {
    default: //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
248
							throw new ErrorException('une erreur est survenue lors de la mise à jour des technologies');
249
					}
250
				} while (!$this->researchHelper->isResearchPermit($tech1, $tech2, $tech3));
251
				$research->naturalToPay = $this->researchHelper->getInfo($research->naturalTech, 'level', $research->getLevel($research->naturalTech) + 1, 'price');
252
			}
253
		} while ($naturalInvest > 0);
254
		// life technologies (en fait ce sont les sciences politiques)
255
		do {
256
			if ($research->lifeToPay > $lifeInvest) {
257
				$research->lifeToPay -= $lifeInvest;
258
				$lifeInvest = 0;
259
			} else {
260
				$lifeInvest -= $research->lifeToPay;
261
				switch ($research->lifeTech) {
262
					case 3 :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
263
						$research->bioLevel++;
264
						$levelReached = $research->bioLevel;
265
						break;
266
					case 4 :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
267
						$research->mediLevel++;
268
						$levelReached = $research->mediLevel;
269
						break;
270
					default :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a DEFAULT statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in the default statement.

switch ($expr) {
    default : //wrong
        doSomething();
        break;
}

switch ($expr) {
    default: //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
271
						$levelReached = 0;
0 ignored issues
show
Unused Code introduced by
$levelReached is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
272
						throw new ErrorException('une erreur est survenue lors de la mise à jour des technologies');
273
				}
274
275
				$n = new Notification();
276
				$n->setRPlayer($playerId);
277
				$n->setTitle($this->researchHelper->getInfo($research->lifeTech, 'name') . ' niveau ' . $levelReached);
278
				$n->setContent('Vos investissements dans l\'Université ont payé !<br />
279
					Vos chercheurs du département des <strong>Sciences Politiques</strong> ont fait des avancées en <strong>' 
280
					. $this->researchHelper->getInfo($research->lifeTech, 'name') . '</strong>. Vous êtes actuellement au <strong>niveau ' 
281
					. $levelReached . '</strong> dans ce domaine. Félicitations !');
282
				$this->notificationManager->add($n);
283
284
				do {
285
					$research->lifeTech = rand(3, 4);
286
					$tech1 = $research->bioLevel;
287
					$tech2 = $research->mediLevel;
288
					switch ($research->lifeTech) {
289
						case 3 : $tech1++; break;
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
290
						case 4 : $tech2++; break;
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
291
						default :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a DEFAULT statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in the default statement.

switch ($expr) {
    default : //wrong
        doSomething();
        break;
}

switch ($expr) {
    default: //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
292
							throw new ErrorException('une erreur est survenue lors de la mise à jour des technologies');
293
					}
294
				} while (!$this->researchHelper->isResearchPermit($tech1, $tech2));
295
				$research->lifeToPay = $this->researchHelper->getInfo($research->lifeTech, 'level', $research->getLevel($research->lifeTech) + 1, 'price');
296
			}
297
		} while ($lifeInvest > 0);
298
		// social technologies
299
		do {
300
			if ($research->socialToPay > $socialInvest) {
301
				$research->socialToPay -= $socialInvest;
302
				$socialInvest = 0;
303
			} else {
304
				$socialInvest -= $research->socialToPay;
305
				switch ($research->socialTech) {
306
					case 5 :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
307
						$research->econoLevel++;
308
						$levelReached = $research->econoLevel;
309
						break;
310
					case 6 :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
311
						$research->psychoLevel++;
312
						$levelReached = $research->psychoLevel;
313
						break;
314
					default :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a DEFAULT statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in the default statement.

switch ($expr) {
    default : //wrong
        doSomething();
        break;
}

switch ($expr) {
    default: //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
315
						$levelReached = 0;
0 ignored issues
show
Unused Code introduced by
$levelReached is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
316
						throw new ErrorException('une erreur est survenue lors de la mise à jour des technologies');
317
				}
318
319
				$n = new Notification();
320
				$n->setRPlayer($playerId);
321
				$n->setTitle($this->researchHelper->getInfo($research->socialTech, 'name') . ' niveau ' . $levelReached);
322
				$n->setContent('Vos investissements dans l\'Université ont payé !<br />
323
					Vos chercheurs du département des <strong>Sciences Economiques et Sociales</strong> ont fait des avancées en <strong>' 
324
					. $this->researchHelper->getInfo($research->socialTech, 'name') . '</strong>. Vous êtes actuellement au <strong>niveau ' 
325
					. $levelReached . '</strong> dans ce domaine. Félicitations !');
326
				$this->notificationManager->add($n);
327
				do {
328
					$research->socialTech = rand(5, 6);
329
					$tech1 = $research->econoLevel;
330
					$tech2 = $research->psychoLevel;
331
					switch ($research->socialTech) {
332
						case 5 : $tech1++; break;
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
333
						case 6 : $tech2++; break;
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
334
						default :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a DEFAULT statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in the default statement.

switch ($expr) {
    default : //wrong
        doSomething();
        break;
}

switch ($expr) {
    default: //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
335
							throw new ErrorException('une erreur est survenue lors de la mise à jour des technologies');
336
					}
337
				} while (!$this->researchHelper->isResearchPermit($tech1, $tech2));
338
				$research->socialToPay = $this->researchHelper->getInfo($research->socialTech, 'level', $research->getLevel($research->socialTech) + 1, 'price');
339
			}
340
		} while ($socialInvest > 0);
341
		// informatic technologies
342
		do {
343
			if ($research->informaticToPay > $informaticInvest) {
344
				$research->informaticToPay -= $informaticInvest;
345
				$informaticInvest = 0;
346
			} else {
347
				$informaticInvest -= $research->informaticToPay;
348
				switch ($research->informaticTech) {
349
					case 7 :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
350
						$research->networkLevel++;
351
						$levelReached = $research->networkLevel;
352
						break;
353
					case 8 :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
354
						$research->algoLevel++;
355
						$levelReached = $research->algoLevel;
356
						break;
357
					case 9 :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
358
						$research->statLevel++;
359
						$levelReached = $research->statLevel;
360
						break;
361
					default :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a DEFAULT statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in the default statement.

switch ($expr) {
    default : //wrong
        doSomething();
        break;
}

switch ($expr) {
    default: //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
362
						$levelReached = 0;
0 ignored issues
show
Unused Code introduced by
$levelReached is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
363
						throw new ErrorException('une erreur est survenue lors de la mise à jour des technologies');
364
				}
365
				
366
				$n = new Notification();
367
				$n->setRPlayer($playerId);
368
				$n->setTitle($this->researchHelper->getInfo($research->informaticTech, 'name') . ' niveau ' . $levelReached);
369
				$n->setContent('Vos investissements dans l\'Université ont payé !<br />
370
					Vos chercheurs du département de l\'<strong>Ingénierie Informatique</strong> ont fait des avancées en <strong>' 
371
					. $this->researchHelper->getInfo($research->informaticTech, 'name') . '</strong>. Vous êtes actuellement au <strong>niveau ' 
372
					. $levelReached . '</strong> dans ce domaine. Félicitations !');
373
				$this->notificationManager->add($n);
374
375
				do {
376
					$research->informaticTech = rand(7, 9);
377
					$tech1 = $research->networkLevel;
378
					$tech2 = $research->algoLevel;
379
					$tech3 = $research->statLevel;
380
					switch ($research->informaticTech) {
381
						case 7 : $tech1++; break;
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
382
						case 8 : $tech2++; break;
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
383
						case 9 : $tech3++; break;
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
384
						default :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a DEFAULT statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in the default statement.

switch ($expr) {
    default : //wrong
        doSomething();
        break;
}

switch ($expr) {
    default: //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
385
							throw new ErrorException('une erreur est survenue lors de la mise à jour des technologies');
386
					}
387
				} while (!$this->researchHelper->isResearchPermit($tech1, $tech2, $tech3));
388
				$research->informaticToPay = $this->researchHelper->getInfo($research->informaticTech, 'level', $research->getLevel($research->informaticTech) + 1, 'price');
389
			}
390
		} while ($informaticInvest > 0);
391
	}
392
393
	public function getResearchList(Research $research) {
394
		// return a stacklist of the researches
395
		$r = new StackList();
396
		for ($i = 0; $i < $this->researchQuantity; $i++) {
397
			$r->append($research->getLevel($i));
398
		}
399
		return $r;
400
	}
401
	
402
	/* This will no longer work
403
	public static function deleteByRPlayer($rPlayer) {
404
		try {
405
			$db = Database::getInstance();
406
			$qr = $db->prepare('DELETE FROM research WHERE rPlayer = ?');
407
			$qr->execute(array($rPlayer));
408
			return TRUE;
409
		} catch(Exception $e) {
410
			$_SESSION[SERVERSESS]['alert'][] = array($e->getMessage(), $e->getCode());
411
		}
412
	}*/
413
}