GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

BasketController::renderPanel()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Alexey Tatarinov <[email protected]>
4
 * @link https://github.com/shogodev/argilla/
5
 * @copyright Copyright &copy; 2003-2014 Shogo
6
 * @license http://argilla.ru/LICENSE
7
 * @package frontend.controllers
8
 */
9
class BasketController extends FController
10
{
11
  private $renderPanel = false;
12
13
  public function filter()
14
  {
15
    return array('ajaxOnly + ajax, fastOrder, favoriteToBasket, repeatOrder');
16
  }
17
18
  public function actionAjax()
19
  {
20
    $this->processBasketAction();
21
    $this->renderAjax();
22
  }
23
24
  public function actionFastOrder()
25
  {
26
    $form = $this->fastOrderForm;
27
    $form->ajaxValidation();
28
29
    $fastOrderBasket = new FBasket('fastOrderBasket', array(), false);
30
    $fastOrderBasket->add(Yii::app()->request->getPost($this->basket->keyCollection));
31
    $form->model->setFastOrderBasket($fastOrderBasket);
32
33
    if( !$fastOrderBasket->isEmpty() && $form->save() )
34
    {
35
      Yii::app()->notification->send('FastOrderBackend', array('model' => $form->model), null, 'backend');
36
      Yii::app()->notification->send('FastOrder', array('model' => $form->model), $form->model->email);
37
38
      echo CJSON::encode(array(
39
        'status' => 'ok',
40
        'hideElements' => array($form->id),
41
        'showElements' => array($this->basket->fastOrderFormSuccessId)
42
      ));
43
      Yii::app()->end();
0 ignored issues
show
Bug introduced by
The method end does only exist in BTestApplication and FTestApplication, but not in BApplication and FApplication.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
44
    }
45
  }
46
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)
0 ignored issues
show
Bug introduced by
The class CHttpException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
94
    {
95
      $e->handled = true;
96
      throw new CHttpException(500, 'Ошибка. Невозможно выполнить повтрный заказ');
97
    }
98
  }
99
100
  protected function processBasketAction()
101
  {
102
    $request = Yii::app()->request;
103
    $data = $request->getPost($this->basket->keyCollection);
104
    $action = $request->getPost('action');
105
106
    if( $data && $action )
107
    {
108
      switch($action)
109
      {
110 View Code Duplication
        case 'remove':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
111
          $index = Arr::get($data, 'index');
112
113
          if( is_null($index) )
114
            $index = $this->basket->getIndex($data);
115
116
          if( is_null($index) || !$this->basket->exists($index) )
117
            throw new CHttpException(500, 'Данный продукт уже удален. Обновите страницу.');
118
119
          $this->basket->remove($index);
120
        break;
121
122
        case 'changeAmount':
123
          if( !$this->basket->exists($data['index']) )
124
            throw new CHttpException(500, 'Продукт не найден. Обновите страницу.');
125
          $amount = intval($data['amount']);
126
          $this->basket->changeAmount($data['index'], $amount > 0 ? $amount : 1);
127
        break;
128
129
        case 'changeItems':
130
          if( !$this->basket->exists($data['index']) )
131
            throw new CHttpException(500, 'Продукт не найден. Обновите страницу.');
132
133
          $items = Arr::get($this->basket[$data['index']]->getCollectionElement()->toArray(), 'items', array());
0 ignored issues
show
Unused Code introduced by
$items is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
134
          $items = $data;
135
          $this->basket->changeItems($data['index'], $items);
136
        break;
137
138
        case 'add':
139
          $this->basket->add($data);
140
        break;
141
      }
142
    }
143
  }
144
145
  protected function renderAjax()
146
  {
147
    $this->renderPartial('/_basket_header');
148
    $this->renderPanel();
149
  }
150
151
  private function renderPanel()
152
  {
153
    if( $this->renderPanel )
154
      $this->renderPartial('/panel/panel');
155
  }
156
}