| Conditions | 3 |
| Paths | 3 |
| Total Lines | 68 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 30 | public function testCrudDocument(): void |
||
| 31 | { |
||
| 32 | // $counterpartyModel = new \SergeyNezbritskiy\NovaPoshta\Models\Counterparty($this->getConnection()); |
||
| 33 | // $addressModel = new \SergeyNezbritskiy\NovaPoshta\Models\Address($this->getConnection()); |
||
| 34 | |||
| 35 | // $recipient = $counterpartyModel->savePrivatePerson([ |
||
| 36 | // 'FirstName' => 'Петро', |
||
| 37 | // 'MiddleName' => 'Григорович', |
||
| 38 | // 'LastName' => 'Порошенко', |
||
| 39 | // 'Phone' => 380501112233, |
||
| 40 | // 'Email' => '[email protected]', |
||
| 41 | // 'CounterpartyProperty' => Counterparty::COUNTERPARTY_PROPERTY_RECIPIENT, |
||
| 42 | // ]); // 4d21c8c7-b88e-11ed-a60f-48df37b921db |
||
| 43 | $recipientRef = '4d21c8c7-b88e-11ed-a60f-48df37b921db'; |
||
| 44 | |||
| 45 | // $address = $addressModel->save($recipientRef, [ |
||
| 46 | // 'StreetRef' => self::KHRESHCHATYK_STREET_REF, |
||
| 47 | // 'BuildingNumber' => '20', |
||
| 48 | // 'Flat' => '12', |
||
| 49 | // ]); |
||
| 50 | $addressRef = 'cecaac32-25bb-11ee-a60f-48df37b921db'; |
||
| 51 | |||
| 52 | // $contactPersons = $counterpartyModel->getCounterpartyContactPersons(self::COUNTERPARTY_REF); |
||
| 53 | $senderContactRef = '4d06cbac-b88e-11ed-a60f-48df37b921db'; |
||
| 54 | |||
| 55 | // $contactPersons = $counterpartyModel->getCounterpartyContactPersons($recipientRef); |
||
| 56 | $recipientContactRef = '45b55250-25bb-11ee-a60f-48df37b921db'; |
||
| 57 | |||
| 58 | //create document |
||
| 59 | $params = [ |
||
| 60 | 'Sender' => self::COUNTERPARTY_REF, |
||
| 61 | 'CitySender' => self::CITY_REF_KHARKIV, |
||
| 62 | 'SenderAddress' => self::ADDRESS_REF_KHARKIV, |
||
| 63 | 'ContactSender' => $senderContactRef, |
||
| 64 | 'SendersPhone' => 380505511696, |
||
| 65 | |||
| 66 | 'Recipient' => $recipientRef, |
||
| 67 | 'CityRecipient' => self::CITY_REF_KYIV, |
||
| 68 | 'RecipientAddress' => $addressRef, |
||
| 69 | 'ContactRecipient' => $recipientContactRef, |
||
| 70 | 'RecipientsPhone' => 380505511696, |
||
| 71 | |||
| 72 | 'DateTime' => date('d.m.Y'), |
||
| 73 | 'CargoType' => InternetDocument::CARGO_TYPE_CARGO, |
||
| 74 | 'Weight' => '0.5', |
||
| 75 | 'SeatsAmount' => '1', |
||
| 76 | 'ServiceType' => 'DoorsDoors', |
||
| 77 | 'PayerType' => 'Recipient', |
||
| 78 | 'PaymentMethod' => 'Cash', |
||
| 79 | 'Description' => 'TEST, DO NOT PROCEED WITH THIS' |
||
| 80 | ]; |
||
| 81 | |||
| 82 | $actualResult = $this->model->save($params); |
||
| 83 | $this->assertNotEmpty($actualResult['Ref']); |
||
| 84 | sleep(15); |
||
| 85 | |||
| 86 | //delete document |
||
| 87 | $this->model->delete($actualResult['Ref']); |
||
| 88 | |||
| 89 | $documents = $this->model->getDocumentList([ |
||
| 90 | 'DateTimeFrom' => date('d.m.Y'), |
||
| 91 | 'DateTimeTo' => date('d.m.Y'), |
||
| 92 | 'GetFullList' => 1, |
||
| 93 | 'DateTime' => date('d.m.Y'), |
||
| 94 | ], 1); |
||
| 95 | foreach ($documents as $document) { |
||
| 96 | if ($document['Ref'] === $actualResult['Ref']) { |
||
| 97 | $this->fail('Failed to delete document.'); |
||
| 98 | } |
||
| 102 |