| Conditions | 10 |
| Paths | 256 |
| Total Lines | 58 |
| Code Lines | 40 |
| 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 |
||
| 23 | public static function processData(ModificationDataEvent $event) |
||
| 24 | { |
||
| 25 | if (!self::$modelSetting) { |
||
| 26 | self::$modelSetting = new GoogleFeed(); |
||
| 27 | self::$modelSetting->loadConfig(); |
||
| 28 | } |
||
| 29 | $event->dataArray = [ |
||
| 30 | 'title' => self::getRelation($event->model, 'item_title', $event->model->name), |
||
| 31 | 'description' => self::getRelation($event->model, 'item_description', $event->model->announce), |
||
| 32 | 'link' => $event->sender->host . htmlspecialchars(Url::toRoute(['@product', 'model' => $event->model])), |
||
| 33 | 'g:id' => $event->model->id, |
||
| 34 | 'g:condition' => self::$modelSetting->item_condition, |
||
| 35 | 'g:product_type' => self::getProductType($event->model), |
||
| 36 | 'g:availability' => static::getAvailability($event->model) |
||
| 37 | ]; |
||
| 38 | if ($manufacturer = self::getRelation($event->model, 'item_brand', false)) { |
||
|
|
|||
| 39 | $event->dataArray['g:brand'] = $manufacturer; |
||
| 40 | } |
||
| 41 | if ($gin = self::getRelation($event->model, 'item_gtin', false)) { |
||
| 42 | $event->dataArray['g:gtin'] = $gin; |
||
| 43 | } |
||
| 44 | if ($mpn = self::getRelation($event->model, 'item_mpn', false)) { |
||
| 45 | $event->dataArray['g:mpn'] = $mpn; |
||
| 46 | } |
||
| 47 | |||
| 48 | if ($item_google_product_category = self::getRelation($event->model, 'item_google_product_category', false)) { |
||
| 49 | $event->dataArray['g:google_product_category'] = $item_google_product_category; |
||
| 50 | } |
||
| 51 | |||
| 52 | if (!empty($event->model->old_price) && $event->model->old_price > $event->model->price) { |
||
| 53 | $event->dataArray['g:price'] = static::getPrice( |
||
| 54 | $event->model, |
||
| 55 | $event->sender->mainCurrency, |
||
| 56 | $event->model->old_price |
||
| 57 | ); |
||
| 58 | $event->dataArray['g:sale_price'] = static::getPrice( |
||
| 59 | $event->model, |
||
| 60 | $event->sender->mainCurrency, |
||
| 61 | $event->model->price |
||
| 62 | ); |
||
| 63 | } else { |
||
| 64 | |||
| 65 | $event->dataArray['g:price'] = static::getPrice( |
||
| 66 | $event->model, |
||
| 67 | $event->sender->mainCurrency, |
||
| 68 | $event->model->price |
||
| 69 | ); |
||
| 70 | } |
||
| 71 | $imageObject = $event->model->image; |
||
| 72 | if ($imageObject) { |
||
| 73 | $event->dataArray['g:image_link'] = htmlspecialchars( |
||
| 74 | $event->sender->host . $event->model->image->getOriginalUrl() |
||
| 75 | ); |
||
| 76 | } |
||
| 77 | if ($event->model->parent_id !== 0) { |
||
| 78 | $event->dataArray['g:item_group_id'] = $event->model->parent_id; |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 152 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: