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.

OrbitalBaseHelper   C
last analyzed

Complexity

Total Complexity 74

Size/Duplication

Total Lines 197
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 197
rs 5.5244
c 0
b 0
f 0
wmc 74
lcom 1
cbo 2

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isABuilding() 0 3 1
A isAShipFromDock1() 0 3 1
A isAShipFromDock2() 0 3 1
A isAShipFromDock3() 0 3 1
B fleetQuantity() 0 14 5
A getInfo() 0 3 1
D haveRights() 0 89 29
C getBuildingInfo() 0 59 34

How to fix   Complexity   

Complex Class

Complex classes like OrbitalBaseHelper often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use OrbitalBaseHelper, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Asylamba\Modules\Athena\Helper;
4
5
use Asylamba\Modules\Promethee\Helper\TechnologyHelper;
6
use Asylamba\Modules\Athena\Model\OrbitalBase;
7
use Asylamba\Modules\Athena\Resource\OrbitalBaseResource;
8
9
class OrbitalBaseHelper {
10
	/** @var TechnologyHelper **/
11
	protected $technologyHelper;
12
	
13
	/**
14
	 * @param TechnologyHelper $technologyHelper
15
	 */
16
	public function __construct(TechnologyHelper $technologyHelper)
17
	{
18
		$this->technologyHelper = $technologyHelper;
19
	}
20
	
21
	public function isABuilding($building) {
22
		return in_array($building, OrbitalBaseResource::$orbitalBaseBuildings);
23
	}
24
25
	public function isAShipFromDock1($ship) {
26
		return in_array($ship, OrbitalBaseResource::$dock1Ships);
27
	}
28
29
	public function isAShipFromDock2($ship) {
30
		return in_array($ship, OrbitalBaseResource::$dock2Ships);
31
	}
32
33
	public function isAShipFromDock3($ship) {
34
		return in_array($ship, OrbitalBaseResource::$dock3Ships);
35
	}
36
37
	public function fleetQuantity($typeOfBase) {
38
		switch ($typeOfBase) {
39
			case OrbitalBase::TYP_NEUTRAL:
40
				return 2; break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

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...
41
			case OrbitalBase::TYP_COMMERCIAL:
42
				return 2; break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

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...
43
			case OrbitalBase::TYP_MILITARY:
44
				return 5; break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

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...
45
			case OrbitalBase::TYP_CAPITAL:
46
				return 5; break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

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...
47
			default:
48
				return 0; break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

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...
49
		}
50
	}
51
52
	public function getInfo($buildingNumber, $info, $level = 0, $sup = 'default') {
53
		return $this->getBuildingInfo($buildingNumber, $info, $level, $sup);
54
	}
55
	
56
	public function getBuildingInfo($buildingNumber, $info, $level = 0, $sup = 'default') {
57
		if($this->isABuilding($buildingNumber)) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
58
			if (in_array($info, ['name', 'column', 'frenchName', 'imageLink', 'description'])) {
59
				return OrbitalBaseResource::$building[$buildingNumber][$info];
60
			} elseif ($info == 'techno') {
61
				if (in_array($buildingNumber, array(3,4,6,8,9))) {
62
					return OrbitalBaseResource::$building[$buildingNumber][$info];
63
				} else {
64
					return -1;
65
				}
66
			} elseif ($info == 'maxLevel') {
67
				# $level is the type of the base
68
				return OrbitalBaseResource::$building[$buildingNumber][$info][$level];
69
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
70
			} elseif ($info == 'level') {
71
				if ($level <= 0 OR $level > count(OrbitalBaseResource::$building[$buildingNumber]['level'])) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, PHP keywords should be in lowercase; expected or, but found OR.
Loading history...
72
					return FALSE;
73
				}
74
				if ($sup == 'time') {
75
					return OrbitalBaseResource::$building[$buildingNumber][$info][$level-1][0];
76
				} elseif($sup == 'resourcePrice') {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after ELSEIF keyword; 0 found
Loading history...
77
					return OrbitalBaseResource::$building[$buildingNumber][$info][$level-1][1];
78
				} elseif($sup == 'points') {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after ELSEIF keyword; 0 found
Loading history...
79
					return OrbitalBaseResource::$building[$buildingNumber][$info][$level-1][2];
80
				} else {
81
					if ($sup == 'nbQueues') {
82
						if ($buildingNumber == 0 OR $buildingNumber == 2 OR $buildingNumber == 3 OR $buildingNumber == 5) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, PHP keywords should be in lowercase; expected or, but found OR.
Loading history...
83
							return OrbitalBaseResource::$building[$buildingNumber][$info][$level-1][3];
84
						} 
85
					} elseif ($sup == 'storageSpace') {
86
						if ($buildingNumber == 7) {
87
							return OrbitalBaseResource::$building[$buildingNumber][$info][$level-1][3];
88
						} elseif ($buildingNumber == 2 OR $buildingNumber == 3) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, PHP keywords should be in lowercase; expected or, but found OR.
Loading history...
89
							return OrbitalBaseResource::$building[$buildingNumber][$info][$level-1][4];
90
						}
91
					} elseif ($sup == 'refiningCoefficient' AND $buildingNumber == 1) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, PHP keywords should be in lowercase; expected and, but found AND.
Loading history...
92
						return OrbitalBaseResource::$building[$buildingNumber][$info][$level-1][3];
93
					} elseif ($sup == 'releasedShip' AND ($buildingNumber == 2 OR $buildingNumber == 3)) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, PHP keywords should be in lowercase; expected and, but found AND.
Loading history...
Coding Style introduced by
As per coding-style, PHP keywords should be in lowercase; expected or, but found OR.
Loading history...
94
						return OrbitalBaseResource::$building[$buildingNumber][$info][$level-1][5];
95
					} elseif ($sup == 'releasedShip' AND $buildingNumber == 4) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, PHP keywords should be in lowercase; expected and, but found AND.
Loading history...
96
						return OrbitalBaseResource::$building[$buildingNumber][$info][$level-1][4];
97
					} elseif ($sup == 'nbCommercialShip' AND $buildingNumber == 6) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, PHP keywords should be in lowercase; expected and, but found AND.
Loading history...
98
						return OrbitalBaseResource::$building[$buildingNumber][$info][$level-1][3];
99
					} elseif ($sup == 'nbRecyclers' AND $buildingNumber == 8) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, PHP keywords should be in lowercase; expected and, but found AND.
Loading history...
100
						return OrbitalBaseResource::$building[$buildingNumber][$info][$level-1][3];
101
					} elseif ($sup == 'nbRoutesMax' AND $buildingNumber == 9) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, PHP keywords should be in lowercase; expected and, but found AND.
Loading history...
102
						return OrbitalBaseResource::$building[$buildingNumber][$info][$level-1][3];
103
					} else {
104
						throw new ErrorException('4e argument invalide dans getBuildingInfo de OrbitalBaseResource');
105
					}
106
				}
107
			} else {
108
				throw new ErrorException('2e argument invalide dans getBuildingInfo de OrbitalBaseResource');
109
			}
110
		} else {
111
			throw new ErrorException('1er argument invalide (entre 0 et 7) dans getBuildingInfo de OrbitalBaseResource');
112
		}
113
		return FALSE;
114
	}
115
116
	public function haveRights($buildingId, $level, $type, $sup) {
117
		if ($this->isABuilding($buildingId)) {
118
			switch($type) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after SWITCH keyword; 0 found
Loading history...
119
				// assez de ressources pour contruire ?
120
				case 'resource' : 
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...
121
					return ($sup < $this->getBuildingInfo($buildingId, 'level', $level, 'resourcePrice')) ? FALSE : TRUE;
122
					break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
123
				// encore de la place dans la queue ?
124
				// $sup est le nombre de batiments dans la queue
125
				case 'queue' :
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...
126
					// $buildingId n'est pas utilisé
127
					return ($sup < $this->getBuildingInfo($buildingId, 'level', $level, 'nbQueues')) ? TRUE : FALSE;
128
					break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
129
				// droit de construire le batiment ?
130
				// $sup est un objet de type OrbitalBase
131
				case 'buildingTree' :
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...
132
					$diminution = NULL;
0 ignored issues
show
Unused Code introduced by
$diminution 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...
133
					switch ($buildingId) {
134
						case OrbitalBaseResource::GENERATOR : 
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...
135
							$diminution = 0;
136
							break;
137
						case OrbitalBaseResource::REFINERY :
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...
138
							$diminution = 0;
139
							break;
140
						case OrbitalBaseResource::DOCK1 :
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...
141
							$diminution = 0;
142
							break;
143
						case OrbitalBaseResource::DOCK2 :
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...
144
							$diminution = 20;
145
							break;
146
						case OrbitalBaseResource::DOCK3 :
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...
147
							$diminution = 30;
148
							break;
149
						case OrbitalBaseResource::TECHNOSPHERE : 
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...
150
							$diminution = 0;
151
							break;
152
						case OrbitalBaseResource::COMMERCIAL_PLATEFORME :
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...
153
							$diminution = 10;
154
							break;
155
						case OrbitalBaseResource::STORAGE : 
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...
156
							$diminution = 0;
157
							break;
158
						case OrbitalBaseResource::RECYCLING : 
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...
159
							$diminution = 10;
160
							break;
161
						case OrbitalBaseResource::SPATIOPORT : 
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...
162
							$diminution = 20;
163
							break;
164
						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...
165
							throw new ErrorException('buildingId invalide (entre 0 et 9) dans haveRights de OrbitalBaseResource');
166
					}
167
					if ($diminution !== NULL) {
168
						if ($buildingId == OrbitalBaseResource::GENERATOR) {
169
							if ($level > OrbitalBaseResource::$building[$buildingId]['maxLevel'][$sup->typeOfBase]) {
170
								return 'niveau maximum atteint';
171
							} else {
172
								return TRUE;
173
							}
174
						} else {
175
							if ($level == 1 AND $sup->typeOfBase == OrbitalBase::TYP_NEUTRAL AND ($buildingId == OrbitalBaseResource::SPATIOPORT OR $buildingId == OrbitalBaseResource::DOCK2)) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, PHP keywords should be in lowercase; expected and, but found AND.
Loading history...
Coding Style introduced by
As per coding-style, PHP keywords should be in lowercase; expected or, but found OR.
Loading history...
176
								return 'vous devez évoluer votre colonie pour débloquer ce bâtiment';
177
							}
178
							if ($level > OrbitalBaseResource::$building[$buildingId]['maxLevel'][$sup->typeOfBase]) {
179
								return 'niveau maximum atteint';
180
							} elseif ($level > ($sup->realGeneratorLevel - $diminution)) {
181
								return 'le niveau du générateur n\'est pas assez élevé';
182
							} else {
183
								return TRUE;
184
							}
185
						}
186
					}
187
					break;
188
				// a la technologie pour construire ce bâtiment ?
189
				// $sup est un objet de type Technology
190
				case 'techno' : 
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...
191
					if ($this->getBuildingInfo($buildingId, 'techno') == -1) { return TRUE; }
192
					if ($sup->getTechnology($this->getBuildingInfo($buildingId, 'techno')) == 1) {
193
						return TRUE;
194
					} else { 
195
						return 'il vous faut développer la technologie ' . $this->technologyHelper->getInfo($this->getBuildingInfo($buildingId, 'techno'), 'name'); 
196
					}
197
					break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
198
				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...
199
					throw new ErrorException('$type invalide (entre 1 et 4) dans haveRights de OrbitalBaseResource');
200
			}
201
		} else {
202
			throw new ErrorException('buildingId invalide (entre 0 et 9) dans haveRights de OrbitalBaseResource');
203
		}
204
	}
205
}