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