| Conditions | 4 |
| Paths | 6 |
| Total Lines | 57 |
| 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 |
||
| 12 | public function sendSMTPMessageOverSecureSocket(IntegrationTester $I, Scenario $scenario) |
||
|
|
|||
| 13 | { |
||
| 14 | $connector = $I->createSecureSocketConnector(); |
||
| 15 | |||
| 16 | try { |
||
| 17 | $client = $connector->connect("localhost"); |
||
| 18 | } catch (SMTPException $exception) { |
||
| 19 | $I->markTestSkipped(<<<EOT |
||
| 20 | Make sure your SMTP server has a SSL certificate installed and that your system trusts it. |
||
| 21 | [{$exception->getMessage()}] |
||
| 22 | EOT); |
||
| 23 | } |
||
| 24 | |||
| 25 | $logger = new MockLogger(); |
||
| 26 | |||
| 27 | $client->setLogger($logger); |
||
| 28 | |||
| 29 | $quoted_body = quoted_printable_encode("Hey, Bar!\r\n\r\nIt's me! Foo!\r\n\r\nHow you been man?\r\n\r\n.\r\n\r\n.foo!\r\n\r\nhehehe :-)\r\n\r\n"); |
||
| 30 | |||
| 31 | $mime_message = <<<EOT |
||
| 32 | Date: Thu, 15 Sep 2016 17:20:54 +0200 |
||
| 33 | To: =?utf-8?q?Rasmus =C3=A5h Schultz?= <[email protected]> |
||
| 34 | From: [email protected] |
||
| 35 | Subject: =?UTF-8?Q?Hey, Rasmus! I like =C3=86=C3=98=C3=85=C3=A6=C3=B8=C3=A5!?= |
||
| 36 | MIME-Version: 1.0 |
||
| 37 | Content-Type: text/plain; charset=UTF-8 |
||
| 38 | Content-Transfer-Encoding: quoted-printable |
||
| 39 | |||
| 40 | $quoted_body |
||
| 41 | EOT; |
||
| 42 | |||
| 43 | $client->sendMail( |
||
| 44 | "[email protected]", |
||
| 45 | ["[email protected]"], |
||
| 46 | function ($resource) use ($mime_message) { |
||
| 47 | fwrite($resource, $mime_message); |
||
| 48 | } |
||
| 49 | ); |
||
| 50 | |||
| 51 | $expected = [ |
||
| 52 | 'S: MAIL FROM:<[email protected]>', |
||
| 53 | '/R: 250.*/', |
||
| 54 | 'S: RCPT TO:<[email protected]>', |
||
| 55 | '/R: 250.*/', |
||
| 56 | 'S: DATA', |
||
| 57 | '/R: 354.*/', |
||
| 58 | "S: \r\n.", |
||
| 59 | '/R: 250.*/', |
||
| 60 | ]; |
||
| 61 | |||
| 62 | $records = $logger->records; |
||
| 63 | |||
| 64 | foreach ($expected as $index => $entry) { |
||
| 65 | if (substr($entry, 0, 1) === "/") { |
||
| 66 | $I->assertRegExp($entry, $records[$index]); |
||
| 67 | } else { |
||
| 68 | $I->assertSame($entry, $records[$index]); |
||
| 69 | } |
||
| 73 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.