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.
Test Setup Failed
Push — google-feed ( 14c86b...39b9ea )
by
unknown
10:22
created

DefaultHandler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 26.19 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 1
dl 11
loc 42
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B processData() 11 39 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace app\modules\shop\components\GoogleMerchants;
4
5
6
use app\modules\shop\helpers\CurrencyHelper;
7
use yii\helpers\Url;
8
9
10
class DefaultHandler implements ModificationDataInterface
11
{
12
    public static function processData(ModificationDataEvent $event)
13
    {
14
        $url = htmlspecialchars(Url::toRoute(['@product', 'model' => $event->model]));
15
        $image = htmlspecialchars($event->model->image->getOriginalUrl());
16 View Code Duplication
        if ($event->model->unlimited_count === 1) {
17
            $inStock = 'in stock';
18
        } else {
19
            $inStock = 'out of stock';
20
            foreach ($event->model->getWarehousesState() as $warehouse) {
21
                if ($warehouse->in_warehouse > 0) {
22
                    $inStock = 'in stock';
23
                    break;
24
                }
25
            }
26
        }
27
28
        $price = number_format(
29
                CurrencyHelper::convertCurrencies($event->model->price, $event->model->currency,
30
                    $event->sender->mainCurrency),
31
                2,
32
                '.',
33
                ''
34
            ) . ' ' . $event->sender->mainCurrency->iso_code;
35
36
        $event->data = [
37
            'title' => $event->model->name,
38
            'description' => $event->model->announce,
39
            'link' => $event->sender->host . $url,
40
            'g:id' => $event->model->id,
41
            'g:image_link' => $image,
42
            'g:condition' => 'new',
43
            'g:availability' => $inStock,
44
            'g:price' => $price
45
        ];
46
        if ($event->model->parent_id !== 0) {
47
            $event->data['g:item_group_id'] = $event->model->parent_id;
48
        }
49
50
    }
51
}