Conditions | 13 |
Paths | 7 |
Total Lines | 35 |
Code Lines | 27 |
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 |
||
87 | private function executeActionRequest($action, $payload) |
||
88 | { |
||
89 | switch ($action) { |
||
90 | case ActionEnum::ACTION_SET_INVENTORY: |
||
91 | $this->inventoryApiClient->createInventory( |
||
92 | $payload instanceof InventoryCreateRequestEntity ? $payload : new InventoryCreateRequestEntity($payload) |
||
|
|||
93 | ); |
||
94 | break; |
||
95 | case ActionEnum::ACTION_ADD_INVENTORY: |
||
96 | $this->inventoryApiClient->addInventory( |
||
97 | $payload instanceof InventoryChangedRequestEntity ? $payload : new InventoryChangedRequestEntity($payload) |
||
98 | ); |
||
99 | break; |
||
100 | case ActionEnum::ACTION_SUBTRACT_INVENTORY: |
||
101 | $this->inventoryApiClient->subtractInventory( |
||
102 | $payload instanceof InventoryChangedRequestEntity ? $payload : new InventoryChangedRequestEntity($payload) |
||
103 | ); |
||
104 | break; |
||
105 | case ActionEnum::ACTION_CREATE_PRODUCT: |
||
106 | $this->productsApiClient->createProduct( |
||
107 | $payload instanceof ProductRequestEntity ? $payload : new ProductRequestEntity($payload) |
||
108 | ); |
||
109 | break; |
||
110 | case ActionEnum::ACTION_UPDATE_PRODUCT: |
||
111 | $this->productsApiClient->updateProduct( |
||
112 | $payload instanceof ProductRequestEntity ? $payload : new ProductRequestEntity($payload) |
||
113 | ); |
||
114 | break; |
||
115 | case ActionEnum::ACTION_REMOVE_PRODUCT: |
||
116 | $this->productsApiClient->removeProduct( |
||
117 | $payload instanceof ProductRemovedRequestEntity ? $payload : new ProductRemovedRequestEntity($payload) |
||
118 | ); |
||
119 | break; |
||
120 | default: |
||
121 | throw new \RuntimeException(sprintf('Unknown action %s', $action)); |
||
122 | } |
||
125 |