Conditions | 11 |
Paths | 58 |
Total Lines | 34 |
Code Lines | 24 |
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 |
||
52 | public function getPayloadEntity() |
||
53 | { |
||
54 | if (!$this->rawPayload) { |
||
55 | $this->rawPayload = $this->getRequestPayload(); |
||
56 | } |
||
57 | |||
58 | if (!$this->rawPayload) { |
||
59 | throw new \UnexpectedValueException('Got empty action request payload.', 40); |
||
60 | } |
||
61 | |||
62 | if (is_string($this->rawPayload)) { |
||
63 | $payload = $this->unserializePayload($this->rawPayload); |
||
64 | } else { |
||
65 | $payload = $this->rawPayload; |
||
66 | } |
||
67 | |||
68 | if (isset($payload['payload'])) { |
||
69 | $payload = $payload['payload']; |
||
70 | } |
||
71 | |||
72 | switch ($this->action) { |
||
73 | case ActionEnum::ACTION_CREATE_PRODUCT: |
||
74 | case ActionEnum::ACTION_UPDATE_PRODUCT: |
||
75 | return new ProductRequestEntity($payload); |
||
76 | case ActionEnum::ACTION_REMOVE_PRODUCT: |
||
77 | return new ProductRemovedRequestEntity($payload); |
||
78 | case ActionEnum::ACTION_ADD_INVENTORY: |
||
79 | case ActionEnum::ACTION_SET_INVENTORY: |
||
80 | case ActionEnum::ACTION_SUBTRACT_INVENTORY: |
||
81 | return new InventoryChangedEntity($payload); |
||
82 | default: |
||
83 | throw new \RuntimeException( |
||
84 | sprintf('Payload entity not found for action %s', $this->action), |
||
85 | 41 |
||
86 | ); |
||
115 |