Conditions | 1 |
Paths | 1 |
Total Lines | 81 |
Code Lines | 67 |
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 |
||
59 | public function testSendOrderToMailChimpSuccess() |
||
60 | { |
||
61 | $method = RequestTypes::$POST; |
||
62 | $resource = '/orders'; |
||
63 | $body = [ |
||
64 | 'landing_site' => "landing_site", |
||
65 | 'financial_status' => "processing", |
||
66 | 'fulfillment_status' => "", |
||
67 | 'currency_code' => "EUR", |
||
68 | 'order_total' => 21, |
||
69 | 'tax_total' => 4.48, |
||
70 | 'shipping_total' => 0, |
||
71 | 'tracking_code' => "prec", |
||
72 | 'processed_at_foreign' => "", |
||
73 | 'cancelled_at_foreign' => "", |
||
74 | 'updated_at_foreign' => "", |
||
75 | 'id' => "1234", |
||
76 | 'campaign_id' => "", |
||
77 | 'customer' => [ |
||
78 | 'id' => "50", |
||
79 | 'email_address' => "[email protected]", |
||
80 | 'opt_in_status' => true, |
||
81 | 'company' => "", |
||
82 | 'first_name' => "Kevin", |
||
83 | 'last_name' => "Murillo", |
||
84 | 'orders_count' => 5, |
||
85 | 'total_spent' => 50.75, |
||
86 | 'address' => [ |
||
87 | 'address1' => "Av. Test nº 92", |
||
88 | 'address2' => "", |
||
89 | 'city' => "Barcelona", |
||
90 | 'province' => "Barcelona", |
||
91 | 'province_code' => "BCN", |
||
92 | 'postal_code' => "08080", |
||
93 | 'country' => "Spain", |
||
94 | 'country_code' => "ESP", |
||
95 | ] |
||
96 | ], |
||
97 | 'shipping_address' => [ |
||
98 | 'name' => "shipping_address address for [email protected]", |
||
99 | 'address1' => "Av. Test nº 92", |
||
100 | 'address2' => "", |
||
101 | 'city' => "Barcelona", |
||
102 | 'province' => "Barcelona", |
||
103 | 'province_code' => "BCN", |
||
104 | 'postal_code' => "08080", |
||
105 | 'country' => "Spain", |
||
106 | 'country_code' => "ESP", |
||
107 | ], |
||
108 | 'billing_address' => [ |
||
109 | 'name' => "billing_address address for [email protected]", |
||
110 | 'address1' => "Av. Test nº 92", |
||
111 | 'address2' => "", |
||
112 | 'city' => "Barcelona", |
||
113 | 'province' => "Barcelona", |
||
114 | 'province_code' => "BCN", |
||
115 | 'postal_code' => "08080", |
||
116 | 'country' => "Spain", |
||
117 | 'country_code' => "ESP", |
||
118 | ] |
||
119 | ]; |
||
120 | |||
121 | // Create mocks |
||
122 | $this->setCustomerMock(); |
||
123 | $this->setAddressMock(); |
||
124 | $this->setOrderMock($this->mcCustomer, $this->mcAddress); |
||
125 | |||
126 | // Check that doRequest call have the right params |
||
127 | $this->mailChimpStub |
||
128 | ->expects($this->once()) |
||
129 | ->method('doRequest') |
||
130 | ->with( |
||
131 | $method, |
||
132 | $body, |
||
133 | $resource |
||
134 | ); |
||
135 | |||
136 | // Call method to test |
||
137 | $orderService = new OrderService($this->mailChimpStub); |
||
138 | $orderService->create($this->mcOrder); |
||
139 | } |
||
140 | |||
265 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.