Conditions | 12 |
Paths | 1 |
Total Lines | 35 |
Code Lines | 23 |
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 |
||
101 | public function sort() |
||
102 | { |
||
103 | $Items = $this->toArray(); |
||
104 | usort($Items, function (ItemInterface $a, ItemInterface $b) { |
||
105 | if ($a->getOrderItemType() === $b->getOrderItemType()) { |
||
106 | return ($a->getId() < $b->getId()) ? -1 : 1; |
||
107 | } elseif ($a->isProduct()) { |
||
108 | return -1; |
||
109 | } elseif ($a->isDeliveryFee()) { |
||
110 | if ($b->isProduct()) { |
||
111 | return 1; |
||
112 | } |
||
113 | |||
114 | return -1; |
||
115 | } elseif ($a->isCharge()) { |
||
116 | if ($b->isDeliveryFee() || $b->isProduct()) { |
||
117 | return 1; |
||
118 | } |
||
119 | |||
120 | return -1; |
||
121 | } elseif ($a->isDiscount()) { |
||
122 | if (!$b->isTax()) { |
||
123 | return 1; |
||
124 | } |
||
125 | |||
126 | return -1; |
||
127 | } elseif ($a->isTax()) { |
||
128 | return 1; |
||
129 | } |
||
130 | |||
131 | return 0; |
||
132 | }); |
||
133 | |||
134 | return new self($Items); |
||
135 | } |
||
136 | } |
||
137 |