| Conditions | 1 |
| Paths | 1 |
| Total Lines | 52 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 37 | function it_transforms( |
||
| 38 | User $user, |
||
| 39 | \DateTimeImmutable $createdOn, |
||
| 40 | \DateTimeImmutable $lastLogin, |
||
| 41 | \DateTimeImmutable $updatedOn, |
||
| 42 | FullName $fullName, |
||
| 43 | Username $username |
||
| 44 | ) { |
||
| 45 | $this->read()->shouldReturn([]); |
||
| 46 | |||
| 47 | $this->write($user); |
||
| 48 | |||
| 49 | $user->roles()->shouldBeCalled()->willReturn([new UserRole('ROLE_USER')]); |
||
| 50 | |||
| 51 | $password = UserPassword::fromEncoded('encoded-password', 'user-password-salt'); |
||
| 52 | |||
| 53 | $user->id()->shouldBeCalled()->willReturn(new UserId('user-id')); |
||
| 54 | $user->confirmationToken()->shouldBeCalled()->willReturn(null); |
||
| 55 | $user->createdOn()->shouldBeCalled()->willReturn($createdOn); |
||
| 56 | $user->email()->shouldBeCalled()->willReturn(new UserEmail('[email protected]')); |
||
| 57 | $user->invitationToken()->shouldBeCalled()->willReturn(null); |
||
| 58 | $user->lastLogin()->shouldBeCalled()->willReturn($lastLogin); |
||
| 59 | $user->password()->shouldBeCalled()->willReturn($password); |
||
| 60 | $user->rememberPasswordToken()->shouldBeCalled()->willReturn(null); |
||
| 61 | $user->updatedOn()->shouldBeCalled()->willReturn($updatedOn); |
||
| 62 | |||
| 63 | $user->username()->shouldBeCalled()->willReturn($username); |
||
| 64 | $username->username()->shouldBeCalled()->willReturn('user11111'); |
||
| 65 | |||
| 66 | $user->fullName()->shouldBeCalled()->willReturn($fullName); |
||
| 67 | $fullName->firstName()->shouldBeCalled()->willReturn('The user first name'); |
||
| 68 | $fullName->lastName()->shouldBeCalled()->willReturn('The user last name'); |
||
| 69 | $fullName->fullName()->shouldBeCalled()->willReturn('The user first name The user last name'); |
||
| 70 | |||
| 71 | $this->read()->shouldReturn([ |
||
| 72 | 'id' => 'user-id', |
||
| 73 | 'confirmation_token' => null, |
||
| 74 | 'created_on' => $createdOn, |
||
| 75 | 'email' => '[email protected]', |
||
| 76 | 'invitation_token' => null, |
||
| 77 | 'last_login' => $lastLogin, |
||
| 78 | 'encoded_password' => 'encoded-password', |
||
| 79 | 'salt' => 'user-password-salt', |
||
| 80 | 'remember_password_token' => null, |
||
| 81 | 'roles' => ['ROLE_USER'], |
||
| 82 | 'updated_on' => $updatedOn, |
||
| 83 | 'user_name' => 'user11111', |
||
| 84 | 'first_name' => 'The user first name', |
||
| 85 | 'last_name' => 'The user last name', |
||
| 86 | 'full_name' => 'The user first name The user last name', |
||
| 87 | ]); |
||
| 88 | } |
||
| 89 | } |
||
| 90 |