| Conditions | 4 |
| Paths | 5 |
| Total Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 4.0058 |
| Changes | 0 | ||
| 1 | <?php |
||
| 29 | 2 | private function move(string $movement_string): void |
|
| 30 | { |
||
| 31 | 2 | $movement = Movement::fromString($movement_string); |
|
| 32 | 2 | if ($movement->isTurn()) |
|
| 33 | { |
||
| 34 | 1 | $this->orientation = $this->orientation->turn($movement); |
|
| 35 | |||
| 36 | 1 | return; |
|
| 37 | } |
||
| 38 | |||
| 39 | 2 | if ($movement->isForward()) |
|
| 40 | { |
||
| 41 | 2 | $new_position = $this->position->moveForward($this->orientation); |
|
| 42 | } |
||
| 43 | else |
||
| 44 | { |
||
| 45 | $new_position = $this->position->moveBackward($this->orientation); |
||
| 46 | } |
||
| 47 | |||
| 48 | 2 | $normalized_position = $this->map->normalizePosition($new_position); |
|
| 49 | |||
| 50 | 2 | if ($this->map->collideWithAnyObstacle($normalized_position)) |
|
| 51 | { |
||
| 52 | 1 | $this->collissions[] = $new_position; |
|
| 53 | |||
| 54 | 1 | return; |
|
| 55 | } |
||
| 56 | |||
| 57 | 2 | $this->position = $new_position; |
|
| 58 | 2 | } |
|
| 59 | |||
| 80 | } |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call: