Conditions | 1 |
Paths | 1 |
Total Lines | 67 |
Code Lines | 36 |
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 |
||
55 | public function testAuthenticate() |
||
56 | { |
||
57 | $mockDate1 = '2010-01-01 10:00:00'; |
||
58 | $readingMode = sprintf('Archive.%s.Stage', $mockDate1); |
||
59 | |||
60 | /** @var Member $member */ |
||
61 | $member = DBDatetime::withFixedNow($mockDate1, function () { |
||
62 | $member = Member::create(); |
||
63 | $member->update([ |
||
64 | 'FirstName' => 'Jane', |
||
65 | 'Surname' => 'Doe', |
||
66 | 'Email' => '[email protected]' |
||
67 | ]); |
||
68 | $member->write(); |
||
69 | $member->changePassword('password', true); |
||
70 | |||
71 | return $member; |
||
72 | }); |
||
73 | |||
74 | $member->changePassword('new-password', true); |
||
75 | |||
76 | /** @var ValidationResult $results */ |
||
77 | $results = Versioned::withVersionedMode(function () use ($readingMode) { |
||
78 | Versioned::set_reading_mode($readingMode); |
||
79 | $authenticator = new MemberAuthenticator(); |
||
80 | |||
81 | // Test correct login |
||
82 | /** @var ValidationResult $message */ |
||
83 | $authenticator->authenticate( |
||
84 | [ |
||
85 | 'Email' => '[email protected]', |
||
86 | 'Password' => 'password' |
||
87 | ], |
||
88 | Controller::curr()->getRequest(), |
||
89 | $result |
||
90 | ); |
||
91 | |||
92 | return $result; |
||
93 | }); |
||
94 | |||
95 | $this->assertFalse( |
||
96 | $results->isValid(), |
||
97 | 'Authenticate using old credentials fails even when using an old reading mode' |
||
98 | ); |
||
99 | |||
100 | /** @var ValidationResult $results */ |
||
101 | $results = Versioned::withVersionedMode(function () use ($readingMode) { |
||
102 | Versioned::set_reading_mode($readingMode); |
||
103 | $authenticator = new MemberAuthenticator(); |
||
104 | |||
105 | // Test correct login |
||
106 | /** @var ValidationResult $message */ |
||
107 | $authenticator->authenticate( |
||
108 | [ |
||
109 | 'Email' => '[email protected]', |
||
110 | 'Password' => 'new-password' |
||
111 | ], |
||
112 | Controller::curr()->getRequest(), |
||
113 | $result |
||
114 | ); |
||
115 | |||
116 | return $result; |
||
117 | }); |
||
118 | |||
119 | $this->assertTrue( |
||
120 | $results->isValid(), |
||
121 | 'Authenticate using current credentials succeeds even when using an old reading mode' |
||
122 | ); |
||
189 |