| Conditions | 8 |
| Paths | 48 |
| Total Lines | 52 |
| 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 |
||
| 47 | public function actionRepeatOrder() |
||
| 48 | {
|
||
| 49 | $data = Yii::app()->request->getPost($this->basket->keyCollection); |
||
| 50 | $orderId = Arr::get($data, 'order-id'); |
||
| 51 | |||
| 52 | try |
||
| 53 | {
|
||
| 54 | /** |
||
| 55 | * @var OrderHistory $order |
||
| 56 | */ |
||
| 57 | if( $order = OrderHistory::model()->findByPk($orderId) ) |
||
| 58 | {
|
||
| 59 | foreach($order->products as $orderProduct) |
||
| 60 | {
|
||
| 61 | $data = array( |
||
| 62 | 'type' => 'product', |
||
| 63 | 'id' => $orderProduct->history->product_id, |
||
| 64 | 'amount' => $orderProduct->count, |
||
| 65 | 'items' => array() |
||
| 66 | ); |
||
| 67 | |||
| 68 | if( $options = $orderProduct->getItems('ProductOption') )
|
||
| 69 | {
|
||
| 70 | foreach($options as $option) |
||
| 71 | {
|
||
| 72 | $data['items']['options'][] = array('id' => $option->pk, 'type' => $option->type);
|
||
| 73 | } |
||
| 74 | } |
||
| 75 | |||
| 76 | if( $ingredients = $orderProduct->getItems('ProductIngredientAssignment') )
|
||
| 77 | {
|
||
| 78 | foreach($ingredients as $ingredient) |
||
| 79 | {
|
||
| 80 | $data['items']['ingredients'][] = array( |
||
| 81 | 'id' => $ingredient->pk, |
||
| 82 | 'type' => $ingredient->type, |
||
| 83 | 'amount' => $ingredient->amount |
||
| 84 | ); |
||
| 85 | } |
||
| 86 | } |
||
| 87 | $this->basket->add($data); |
||
| 88 | } |
||
| 89 | |||
| 90 | $this->renderAjax(); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | catch(CHttpException $e) |
||
| 94 | {
|
||
| 95 | $e->handled = true; |
||
| 96 | throw new CHttpException(500, 'Ошибка. Невозможно выполнить повтрный заказ'); |
||
| 97 | } |
||
| 98 | } |
||
| 99 | |||
| 156 | } |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: