Conditions | 1 |
Paths | 1 |
Total Lines | 68 |
Code Lines | 50 |
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 |
||
53 | public function getProductResponseData(): array |
||
54 | { |
||
55 | $data1 = [[ |
||
56 | 'uuid' => (string) Uuid::uuid1(), |
||
57 | 'name' => 'Some Product', |
||
58 | 'description' => 'description', |
||
59 | 'imageLookupKeys' => [ |
||
60 | 'nice-image.jpeg', |
||
61 | ], |
||
62 | 'amount' => ['amount' => 1000, 'currencyId' => 'EUR'], |
||
63 | 'percentage' => null, |
||
64 | 'externalReference' => 'externalReference', |
||
65 | 'etag' => 'B1C54B44DB967F4240B59AFA30B1AC5E', |
||
66 | 'updated' => '2017-12-06T13:21:59.722+0000', |
||
67 | 'updatedBy' => (string) Uuid::uuid1(), |
||
68 | 'created' => '2017-12-21T13:12:49.272+0000', |
||
69 | ]]; |
||
70 | |||
71 | $mock1 = Mockery::mock(ResponseInterface::class); |
||
72 | $mock1->shouldReceive('getBody')->andReturnSelf(); |
||
73 | $mock1->shouldReceive('getContents')->andReturn(json_encode( |
||
74 | $data1 |
||
75 | )); |
||
76 | |||
77 | $data2 = [ |
||
78 | [ |
||
79 | 'uuid' => (string) Uuid::uuid1(), |
||
80 | 'name' => 'discount1', |
||
81 | 'description' => 'descriptionq', |
||
82 | 'imageLookupKeys' => [ |
||
83 | 'image1.jpeg', |
||
84 | ], |
||
85 | 'amount' => ['amount' => 100, 'currencyId' => 'EUR'], |
||
86 | 'percentage' => null, |
||
87 | 'externalReference' => 'externalReference', |
||
88 | 'etag' => '93D4F5F748933923890C91056A6F0230', |
||
89 | 'updated' => '2017-12-06T13:21:59.722+0000', |
||
90 | 'updatedBy' => (string) Uuid::uuid1(), |
||
91 | 'created' => '2017-12-21T13:12:49.272+0000', |
||
92 | ], |
||
93 | [ |
||
94 | 'uuid' => (string) Uuid::uuid1(), |
||
95 | 'name' => 'discount2', |
||
96 | 'description' => 'description2', |
||
97 | 'imageLookupKeys' => [ |
||
98 | 'image2.jpeg', |
||
99 | ], |
||
100 | 'amount' => null, |
||
101 | 'percentage' => '10', |
||
102 | 'externalReference' => 'externalReference2', |
||
103 | 'etag' => '35D7775289BC0A05E580BE3B466C927B', |
||
104 | 'updated' => '2017-12-06T13:21:59.722+0000', |
||
105 | 'updatedBy' => (string) Uuid::uuid1(), |
||
106 | 'created' => '2017-12-21T13:12:49.272+0000', |
||
107 | ] |
||
108 | ]; |
||
109 | |||
110 | $mock2 = Mockery::mock(ResponseInterface::class); |
||
111 | $mock2->shouldReceive('getBody')->andReturnSelf(); |
||
112 | $mock2->shouldReceive('getContents')->andReturn(json_encode( |
||
113 | $data2 |
||
114 | )); |
||
115 | |||
116 | return [ |
||
117 | 'single discount' => [ $mock1, $data1 ], |
||
118 | 'multiple discount' => [ $mock2, $data2 ], |
||
119 | ]; |
||
120 | } |
||
121 | } |
||
122 |