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