| Conditions | 1 |
| Paths | 1 |
| Total Lines | 52 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 18 | public function testArray2Object() |
||
| 19 | { |
||
| 20 | $teamArray |
||
| 21 | = [ |
||
| 22 | 'name' => 'Dream Team', |
||
| 23 | 'createdAt' => '2016-01-01', |
||
| 24 | 'points' => '25', |
||
| 25 | 'players' => |
||
| 26 | [ |
||
| 27 | [ |
||
| 28 | 'name' => 'Player 1', |
||
| 29 | 'number' => '1', |
||
| 30 | 'height' => '1.80', |
||
| 31 | 'regular' => 'true' |
||
| 32 | ], |
||
| 33 | [ |
||
| 34 | 'name' => 'Player 2', |
||
| 35 | 'number' => '2', |
||
| 36 | 'height' => '1.85', |
||
| 37 | 'regular' => 'false' |
||
| 38 | ] |
||
| 39 | ], |
||
| 40 | 'scores' => [ |
||
| 41 | '2016' => '29', |
||
| 42 | '2015' => '28', |
||
| 43 | '2014' => '30', |
||
| 44 | ] |
||
| 45 | |||
| 46 | ]; |
||
| 47 | |||
| 48 | /** @var Team $team */ |
||
| 49 | $team = Array2Object::createObject(Team::class, $teamArray); |
||
| 50 | static::assertEquals('Dream Team', $team->getName()); |
||
| 51 | static::assertEquals(25, $team->getPoints()); |
||
| 52 | static::assertEquals(29, $team->getScores()[2016]); |
||
| 53 | static::assertEquals('2016-01-01', $team->getCreatedAt()->format('Y-m-d')); |
||
| 54 | |||
| 55 | static::assertEquals('Player 1', $team->getPlayers()[0]->getName()); |
||
| 56 | static::assertEquals(1, $team->getPlayers()[0]->getNumber()); |
||
| 57 | static::assertEquals(1.80, $team->getPlayers()[0]->getHeight()); |
||
| 58 | static::assertTrue($team->getPlayers()[0]->isRegular()); |
||
| 59 | |||
| 60 | static::assertEquals('Player 2', $team->getPlayers()[1]->getName()); |
||
| 61 | static::assertEquals(2, $team->getPlayers()[1]->getNumber()); |
||
| 62 | static::assertEquals(1.85, $team->getPlayers()[1]->getHeight()); |
||
| 63 | static::assertFalse($team->getPlayers()[1]->isRegular()); |
||
| 64 | |||
| 65 | static::assertInternalType('string', $team->getName()); |
||
| 66 | static::assertInternalType('integer', $team->getPoints()); |
||
| 67 | static::assertInternalType('boolean', $team->getPlayers()[0]->isRegular()); |
||
| 68 | static::assertInternalType('float', $team->getPlayers()[0]->getHeight()); |
||
| 69 | } |
||
| 70 | } |
||
| 71 |