Conditions | 17 |
Paths | 5 |
Total Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Tests | 6 |
CRAP Score | 35.496 |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
54 | 1 | public function turn(Movement $movement): Orientation |
|
55 | { |
||
56 | 1 | if (($movement->isLeft() && $this->isEast()) || ($movement->isRight() && $this->isWest())) |
|
57 | { |
||
58 | 1 | return self::NORTH(); |
|
59 | } |
||
60 | |||
61 | 1 | if (($movement->isLeft() && $this->isWest()) || ($movement->isRight() && $this->isEast())) |
|
62 | { |
||
63 | return self::SOUTH(); |
||
64 | } |
||
65 | |||
66 | 1 | if (($movement->isLeft() && $this->isSouth()) || ($movement->isRight() && $this->isNorth())) |
|
67 | { |
||
68 | 1 | return self::EAST(); |
|
69 | } |
||
70 | |||
71 | if (($movement->isLeft() && $this->isNorth()) || ($movement->isRight() && $this->isSouth())) |
||
72 | { |
||
73 | return self::WEST(); |
||
74 | } |
||
75 | } |
||
76 | } |