| Conditions | 15 |
| Paths | 468 |
| Total Lines | 86 |
| Code Lines | 58 |
| Lines | 18 |
| Ratio | 20.93 % |
| 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 |
||
| 75 | protected function getSqlStatements() |
||
| 76 | { |
||
| 77 | $updateRule = []; |
||
| 78 | $condition = []; |
||
| 79 | $args = []; |
||
| 80 | |||
| 81 | $conditionFormat = '%s %s >= 0'; |
||
| 82 | if ($this->params['is_round']) { |
||
| 83 | $updateFormat = 'ROUND(%s %s, :round)'; |
||
| 84 | } else { |
||
| 85 | $updateFormat = '%s %s'; |
||
| 86 | } |
||
| 87 | |||
| 88 | // operation |
||
| 89 | if ($this->params['operation'] == self::BEP_INCREMENT) { |
||
| 90 | $operation = '+'; |
||
| 91 | } elseif ($this->params['operation'] == self::BEP_DECREMENT) { |
||
| 92 | $operation = '-'; |
||
| 93 | } |
||
| 94 | if ($this->params['kind'] == self::BEP_KIND_FIXED) { |
||
| 95 | $args['operation'] = $operation . ' :val'; |
||
| 96 | } elseif ($this->params['kind'] == self::BEP_KIND_PERCENT) { |
||
| 97 | $args['operation'] = " * (1 {$operation} :val / 100)"; |
||
| 98 | } |
||
| 99 | |||
| 100 | // price | old_price | both of them |
||
| 101 | if ($this->params['type'] == self::BEP_TYPE_NORMAL) { |
||
| 102 | View Code Duplication | if ($this->params['sel_field'] == self::BEP_FIELD_PRICE |
|
| 103 | || $this->params['sel_field'] == self::BEP_FIELD_ALL |
||
| 104 | ) { |
||
| 105 | $args['field_to'] = self::BEP_FIELD_PRICE; |
||
| 106 | $args['field_from'] = self::BEP_FIELD_PRICE; |
||
| 107 | } |
||
| 108 | View Code Duplication | if ($this->params['sel_field'] == self::BEP_FIELD_OLDPRICE) { |
|
| 109 | $args['field_to'] = self::BEP_FIELD_OLDPRICE; |
||
| 110 | $args['field_from'] = self::BEP_FIELD_OLDPRICE; |
||
| 111 | } |
||
| 112 | |||
| 113 | if ($this->params['sel_field'] == self::BEP_FIELD_ALL) { |
||
| 114 | $updateRule[$args['field_to']] = new \yii\db\Expression( |
||
| 115 | sprintf( |
||
| 116 | $updateFormat, |
||
| 117 | $args['field_from'], |
||
| 118 | $args['operation'] |
||
| 119 | ) |
||
| 120 | ); |
||
| 121 | |||
| 122 | $condition[] = $args['field_from'] . ' ' . $args['operation'] . '>= 0'; |
||
| 123 | $args['field_to'] = self::BEP_FIELD_OLDPRICE; |
||
| 124 | $args['field_from'] = self::BEP_FIELD_OLDPRICE; |
||
| 125 | } |
||
| 126 | } elseif ($this->params['type'] == self::BEP_TYPE_RELATIVE) { |
||
| 127 | View Code Duplication | if ($this->params['sel_field'] == self::BEP_FIELD_PRICE) { |
|
| 128 | $args['field_to'] = self::BEP_FIELD_OLDPRICE; |
||
| 129 | $args['field_from'] = self::BEP_FIELD_PRICE; |
||
| 130 | } |
||
| 131 | View Code Duplication | if ($this->params['sel_field'] == self::BEP_FIELD_OLDPRICE) { |
|
| 132 | $args['field_to'] = self::BEP_FIELD_PRICE; |
||
| 133 | $args['field_from'] = self::BEP_FIELD_OLDPRICE; |
||
| 134 | } |
||
| 135 | } |
||
| 136 | |||
| 137 | $updateRule[$args['field_to']] = new \yii\db\Expression( |
||
| 138 | sprintf( |
||
| 139 | $updateFormat, |
||
| 140 | $args['field_from'], |
||
| 141 | $args['operation'] |
||
| 142 | ) |
||
| 143 | ); |
||
| 144 | |||
| 145 | $condition[] = $args['field_from'] . ' ' . $args['operation'] . ' >= 0'; |
||
| 146 | $condition[] = 'currency_id = :currency'; |
||
| 147 | if ($this->params['context'] == self::BEP_CONTEXT_PRODUCT) { |
||
| 148 | $data = implode(',', $this->params['items']); |
||
| 149 | $condition['for_count'] = 'id IN (' . $data . ')'; |
||
| 150 | } else { |
||
| 151 | $data = implode(',', $this->getParentCategories($this->params['items'])); |
||
| 152 | $condition['for_count'] = 'main_category_id IN (' . $data . ')'; |
||
| 153 | } |
||
| 154 | |||
| 155 | return [ |
||
| 156 | 'rule' => $updateRule, |
||
| 157 | 'condition' => new \yii\db\Expression(implode(' AND ', $condition)), |
||
| 158 | 'condition_for_count' => new \yii\db\Expression($condition['for_count']) |
||
| 159 | ]; |
||
| 160 | } |
||
| 161 | |||
| 187 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.