Conditions | 1 |
Paths | 1 |
Total Lines | 67 |
Code Lines | 44 |
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 |
||
18 | public function testDsn001(): void |
||
19 | { |
||
20 | $deliveryStatus = (new DsnParser())->parse($this->loadDsn('dsn001.txt')); |
||
21 | |||
22 | $this->assertCount(1, $deliveryStatus->getRecipientFields()); |
||
23 | $this->assertSame(1, $deliveryStatus->countRecipientFields()); |
||
24 | |||
25 | $messageFields = $deliveryStatus->getMessageFields(); |
||
26 | $this->assertCount(4, $messageFields->getAll()); |
||
27 | |||
28 | /** @var MtaNameTypeField $reportingMtaField */ |
||
29 | $reportingMtaField = $messageFields->get('Reporting-MTA'); |
||
30 | $this->assertInstanceOf(MtaNameTypeField::class, $reportingMtaField); |
||
31 | $this->assertSame('dns', $reportingMtaField->getType()); |
||
32 | $this->assertSame('googlemail.com', $reportingMtaField->getValue()); |
||
33 | |||
34 | /** @var MtaNameTypeField $receivedFromMtaField */ |
||
35 | $receivedFromMtaField = $messageFields->get('Received-From-MTA'); |
||
36 | $this->assertInstanceOf(MtaNameTypeField::class, $receivedFromMtaField); |
||
37 | $this->assertSame('dns', $receivedFromMtaField->getType()); |
||
38 | $this->assertSame('[email protected]', $receivedFromMtaField->getValue()); |
||
39 | |||
40 | /** @var DateField $arrivalDateField */ |
||
41 | $arrivalDateField = $messageFields->get('Arrival-Date'); |
||
42 | $arrivalDateTime = new \DateTimeImmutable('2019-03-24 12:52:25 PDT'); |
||
43 | $this->assertInstanceOf(DateField::class, $arrivalDateField); |
||
44 | $this->assertEquals($arrivalDateTime, $arrivalDateField->getDateTime()); |
||
45 | |||
46 | $recipientFields = $deliveryStatus->getRecipientFields()[0]; |
||
47 | |||
48 | /** @var AddressTypeField $finalRecipientField */ |
||
49 | $finalRecipientField = $recipientFields->get('Final-Recipient'); |
||
50 | $this->assertInstanceOf(AddressTypeField::class, $finalRecipientField); |
||
51 | $this->assertSame('rfc822', $finalRecipientField->getType()); |
||
52 | $this->assertSame('[email protected]', $finalRecipientField->getValue()); |
||
53 | |||
54 | /** @var ActionField $actionField */ |
||
55 | $actionField = $recipientFields->get('Action'); |
||
56 | $this->assertInstanceOf(ActionField::class, $actionField); |
||
57 | $this->assertSame('failed', $actionField->getAction()); |
||
58 | |||
59 | /** @var StatusField $statusField */ |
||
60 | $statusField = $recipientFields->get('Status'); |
||
61 | $this->assertInstanceOf(StatusField::class, $statusField); |
||
62 | $this->assertSame(5, $statusField->getCodeClass()); |
||
63 | $this->assertSame(1, $statusField->getCodeSubject()); |
||
64 | $this->assertSame(1, $statusField->getCodeEnumerated()); |
||
65 | $this->assertSame('5.1.1', $statusField->getCode()); |
||
66 | |||
67 | /** @var MtaNameTypeField $remoteMtaField */ |
||
68 | $remoteMtaField = $recipientFields->get('Remote-MTA'); |
||
69 | $this->assertInstanceOf(MtaNameTypeField::class, $remoteMtaField); |
||
70 | $this->assertSame('dns', $remoteMtaField->getType()); |
||
71 | $this->assertSame('mxbw.lb.bluewin.ch.', $remoteMtaField->getValue()); |
||
72 | $this->assertSame('195.186.227.50, the server for the domain bluewin.ch.', $remoteMtaField->getComment()); |
||
73 | |||
74 | /** @var DiagnosticTypeField $diagnosticCodeField */ |
||
75 | $diagnosticCodeField = $recipientFields->get('Diagnostic-Code'); |
||
76 | $this->assertInstanceOf(DiagnosticTypeField::class, $diagnosticCodeField); |
||
77 | $this->assertSame('smtp', $diagnosticCodeField->getType()); |
||
78 | $this->assertSame('550 5.1.1 <[email protected]> recipient rejected, address unknown', $diagnosticCodeField->getValue()); |
||
79 | |||
80 | /** @var DateField $lastAttemptDateField */ |
||
81 | $lastAttemptDateField = $recipientFields->get('Last-Attempt-Date'); |
||
82 | $lastAttemptDateTime = new \DateTimeImmutable('2019-03-24 12:52:26 PDT'); |
||
83 | $this->assertInstanceOf(DateField::class, $lastAttemptDateField); |
||
84 | $this->assertEquals($lastAttemptDateTime, $lastAttemptDateField->getDateTime()); |
||
85 | } |
||
140 |