Conditions | 13 |
Paths | 14 |
Total Lines | 42 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
100 | private function executeActionRequest($action, $payload) |
||
101 | { |
||
102 | if (is_string($payload)) { |
||
103 | $payload = json_decode($payload, true); |
||
104 | } |
||
105 | switch ($action) { |
||
106 | case ActionEnum::ACTION_SET_INVENTORY: |
||
107 | $this->inventoryApiClient->createInventory( |
||
108 | $payload instanceof InventoryCreateRequestEntity |
||
109 | ? $payload |
||
110 | : new InventoryCreateRequestEntity($payload) |
||
111 | ); |
||
112 | break; |
||
113 | case ActionEnum::ACTION_ADD_INVENTORY: |
||
114 | $this->inventoryApiClient->addInventory( |
||
115 | $payload instanceof InventoryChangedRequestEntity |
||
116 | ? $payload |
||
117 | : new InventoryChangedRequestEntity($payload) |
||
118 | ); |
||
119 | break; |
||
120 | case ActionEnum::ACTION_SUBTRACT_INVENTORY: |
||
121 | $this->inventoryApiClient->subtractInventory( |
||
122 | $payload instanceof InventoryChangedRequestEntity |
||
123 | ? $payload |
||
124 | : new InventoryChangedRequestEntity($payload) |
||
125 | ); |
||
126 | break; |
||
127 | case ActionEnum::ACTION_CREATE_PRODUCT: |
||
128 | case ActionEnum::ACTION_UPDATE_PRODUCT: |
||
129 | $this->productsApiClient->createOrUpdateProduct( |
||
130 | $payload instanceof ProductRequestEntity ? $payload : new ProductRequestEntity($payload) |
||
131 | ); |
||
132 | break; |
||
133 | case ActionEnum::ACTION_REMOVE_PRODUCT: |
||
134 | $this->productsApiClient->removeProduct( |
||
135 | $payload instanceof ProductRemovedRequestEntity |
||
136 | ? $payload |
||
137 | : new ProductRemovedRequestEntity($payload) |
||
138 | ); |
||
139 | break; |
||
140 | default: |
||
141 | throw new \RuntimeException(sprintf('Unknown action %s', $action)); |
||
142 | } |
||
145 |