Conditions | 1 |
Paths | 1 |
Total Lines | 108 |
Code Lines | 88 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
88 | public function testImport(): void |
||
89 | { |
||
90 | $this->assertUser([ |
||
91 | 'email' => '[email protected]', |
||
92 | 'subscription_type' => null, |
||
93 | 'subscription_last_review_id' => null, |
||
94 | 'membership' => 'none', |
||
95 | 'first_name' => 'Hector', |
||
96 | 'last_name' => 'Barbossa', |
||
97 | 'street' => '', |
||
98 | 'postcode' => '', |
||
99 | 'locality' => '', |
||
100 | 'country_id' => '1', |
||
101 | 'phone' => '', |
||
102 | 'web_temporary_access' => '0', |
||
103 | 'password' => 'aa08769cdcb26674c6706093503ff0a3', |
||
104 | ]); |
||
105 | |||
106 | $otherMember = [ |
||
107 | 'email' => '[email protected]', |
||
108 | 'subscription_type' => 'digital', |
||
109 | 'subscription_last_review_id' => '3001', |
||
110 | 'membership' => 'payed', |
||
111 | 'first_name' => 'Elizabeth', |
||
112 | 'last_name' => 'Swann', |
||
113 | 'street' => '', |
||
114 | 'postcode' => '', |
||
115 | 'locality' => '', |
||
116 | 'country_id' => '1', |
||
117 | 'phone' => '', |
||
118 | 'web_temporary_access' => '0', |
||
119 | 'password' => '1895eaf4aad48bd97ec1a2fd15336591', |
||
120 | ]; |
||
121 | $this->assertUser($otherMember); |
||
122 | |||
123 | $this->assertShouldDeleteUserCount(0); |
||
124 | $actual = $this->import('tests/data/importer/normal.csv'); |
||
125 | |||
126 | self::assertArrayHasKey('time', $actual); |
||
127 | unset($actual['time']); |
||
128 | |||
129 | $expected = [ |
||
130 | 'updatedUsers' => 4, |
||
131 | 'updatedOrganizations' => 1, |
||
132 | 'deletedOrganizations' => 2, |
||
133 | 'totalUsers' => 6, |
||
134 | 'totalOrganizations' => 1, |
||
135 | 'totalLines' => 5, |
||
136 | ]; |
||
137 | self::assertSame($expected, $actual); |
||
138 | |||
139 | $this->assertShouldDeleteUserCount(2); |
||
140 | |||
141 | $this->assertUser([ |
||
142 | 'email' => '[email protected]', |
||
143 | 'subscription_type' => null, |
||
144 | 'subscription_last_review_id' => null, |
||
145 | 'membership' => 'none', |
||
146 | 'first_name' => '', |
||
147 | 'last_name' => '', |
||
148 | 'street' => '', |
||
149 | 'postcode' => '', |
||
150 | 'locality' => '', |
||
151 | 'country_id' => null, |
||
152 | 'phone' => '', |
||
153 | 'web_temporary_access' => '0', |
||
154 | 'password' => '', |
||
155 | ]); |
||
156 | |||
157 | $this->assertUser([ |
||
158 | 'email' => 'thé[email protected]', |
||
159 | 'subscription_type' => 'paper', |
||
160 | 'subscription_last_review_id' => '3000', |
||
161 | 'membership' => 'due', |
||
162 | 'first_name' => '', |
||
163 | 'last_name' => '', |
||
164 | 'street' => '', |
||
165 | 'postcode' => '', |
||
166 | 'locality' => '', |
||
167 | 'country_id' => null, |
||
168 | 'phone' => '', |
||
169 | 'web_temporary_access' => '0', |
||
170 | 'password' => '', |
||
171 | ]); |
||
172 | |||
173 | $this->assertUser([ |
||
174 | 'email' => '[email protected]', |
||
175 | 'subscription_type' => 'both', |
||
176 | 'subscription_last_review_id' => null, |
||
177 | 'membership' => 'payed', |
||
178 | 'first_name' => 'Roger "Bob"', |
||
179 | 'last_name' => 'Doe', |
||
180 | 'street' => 'Main street', |
||
181 | 'postcode' => '2000', |
||
182 | 'locality' => 'New York', |
||
183 | 'country_id' => '2', |
||
184 | 'phone' => '032 987 65 43', |
||
185 | 'web_temporary_access' => '0', |
||
186 | 'password' => 'aa08769cdcb26674c6706093503ff0a3', |
||
187 | ]); |
||
188 | |||
189 | $this->assertOrganization([ |
||
190 | 'pattern' => '.*@university\.com', |
||
191 | 'subscription_last_review_id' => '3001', |
||
192 | ]); |
||
193 | |||
194 | // Unchanged |
||
195 | $this->assertUser($otherMember); |
||
196 | } |
||
314 |