Conditions | 1 |
Paths | 1 |
Total Lines | 64 |
Code Lines | 34 |
Lines | 0 |
Ratio | 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 |
||
16 | public function testCreateTransport() |
||
17 | { |
||
18 | $smtpConfig = [ |
||
19 | 'host' => 'localhost', |
||
20 | 'port' => 587, |
||
21 | 'options' => [ |
||
22 | 'username' => 'Obiwoan', |
||
23 | 'password' => 'Kenovi', |
||
24 | 'encryption' => 'ssl', |
||
25 | 'authMode' => 'Plain' |
||
26 | ] |
||
27 | ]; |
||
28 | $mailConfig = ['options' => '-f%s']; |
||
29 | $sendMailConfig = ['options' => '/usr/sbin/sendmail -s']; |
||
30 | |||
31 | $smtpFactory = TransportFactory::create($smtpConfig, TransportInterface::TYPE_SMTP); |
||
32 | |||
33 | $this->assertTrue($smtpFactory instanceof SmtpTransportFactory); |
||
34 | |||
35 | $smtp = $smtpFactory->create(); |
||
36 | |||
37 | $this->assertTrue($smtp instanceof SmtpTransport); |
||
38 | |||
39 | /** |
||
40 | * @var \Swift_SmtpTransport $swift |
||
41 | */ |
||
42 | $swift = $smtp->getSwiftTransportInstance(); |
||
43 | |||
44 | $this->assertEquals($smtpConfig['host'], $swift->getHost()); |
||
45 | $this->assertEquals($smtpConfig['port'], $swift->getPort()); |
||
46 | $this->assertEquals($smtpConfig['options']['username'], $swift->getUsername()); |
||
47 | $this->assertEquals($smtpConfig['options']['password'], $swift->getPassword()); |
||
48 | $this->assertEquals($smtpConfig['options']['encryption'], $swift->getEncryption()); |
||
49 | $this->assertEquals($smtpConfig['options']['authMode'], $swift->getAuthMode()); |
||
50 | |||
51 | $mailFactory = TransportFactory::create($mailConfig, TransportInterface::TYPE_MAIL); |
||
52 | |||
53 | $this->assertTrue($mailFactory instanceof MailTransportFactory); |
||
54 | |||
55 | $mail = $mailFactory->create(); |
||
56 | |||
57 | $this->assertTrue($mail instanceof MailTransport); |
||
58 | |||
59 | /** |
||
60 | * @var \Swift_MailTransport $swift |
||
61 | */ |
||
62 | $swift = $mail->getSwiftTransportInstance(); |
||
63 | |||
64 | $this->assertEquals($mailConfig['options'], $swift->getExtraParams()); |
||
65 | |||
66 | $sendMailFactory = TransportFactory::create($sendMailConfig, TransportInterface::TYPE_SEND_MAIL); |
||
67 | |||
68 | $this->assertTrue($sendMailFactory instanceof SendMailTransportFactory); |
||
69 | |||
70 | $sendMail = $sendMailFactory->create(); |
||
71 | |||
72 | $this->assertTrue($sendMail instanceof SendMailTransport); |
||
73 | /** |
||
74 | * @var \Swift_SendMailTransport $swift |
||
75 | */ |
||
76 | $swift = $sendMail->getSwiftTransportInstance(); |
||
77 | |||
78 | $this->assertEquals($sendMailConfig['options'], $swift->getCommand()); |
||
79 | } |
||
80 | |||
109 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.