Conditions | 1 |
Paths | 1 |
Total Lines | 53 |
Code Lines | 39 |
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 |
||
119 | public function testPayload(): void |
||
120 | { |
||
121 | $mailer = SparkPostHelper::registerTransport(); |
||
122 | /** @var \LeKoala\SparkPost\SparkPostApiTransport $transport */ |
||
123 | $transport = SparkPostHelper::getTransportFromMailer($mailer); |
||
124 | |||
125 | |||
126 | $html = <<<HTML |
||
127 | <!DOCTYPE html> |
||
128 | <html> |
||
129 | <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><style type="text/css">.red {color:red;}</style></head> |
||
130 | <body><span class="red">red</span></body> |
||
131 | </html> |
||
132 | HTML; |
||
133 | $result = <<<HTML |
||
134 | <!DOCTYPE html> |
||
135 | <html> |
||
136 | <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head> |
||
137 | <body><span class="red" style="color: red;">red</span></body> |
||
138 | </html> |
||
139 | |||
140 | HTML; |
||
141 | |||
142 | $sender = new Address('[email protected]', "testman"); |
||
143 | $recipients = [ |
||
144 | new Address('[email protected]', "testrec"), |
||
145 | ]; |
||
146 | $email = new Email(); |
||
147 | $email->setBody($html); |
||
148 | $envelope = new Envelope($sender, $recipients); |
||
149 | $payload = $transport->getPayload($email, $envelope); |
||
150 | $content = $payload['content']; |
||
151 | |||
152 | $payloadRecipients = $payload['recipients'][0]; |
||
153 | $this->assertEquals("testrec", $recipients[0]->getName()); |
||
154 | $this->assertEquals( |
||
155 | [ |
||
156 | 'address' => [ |
||
157 | 'email' => '[email protected]', |
||
158 | 'name' => 'rec' // extracted from email due to how recipients work |
||
159 | ] |
||
160 | ], |
||
161 | $payloadRecipients |
||
162 | ); |
||
163 | $payloadSender = $content['from']; |
||
164 | $this->assertEquals([ |
||
165 | 'email' => '[email protected]', |
||
166 | 'name' => 'testman' |
||
167 | ], $payloadSender); |
||
168 | |||
169 | // Make sure our styles are properly inlined |
||
170 | $this->assertEquals('red', $content['text']); |
||
171 | $this->assertEquals($result, $content['html']); |
||
172 | } |
||
174 |