Completed
Push — master ( 9c7fd0...afc45c )
by Andrii
10:58
created

PriceQuery   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 22.22 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 10
loc 45
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B attributesMap() 0 26 1
A initFrom() 10 10 1

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
 * API for Billing
4
 *
5
 * @link      https://github.com/hiqdev/billing-hiapi
6
 * @package   billing-hiapi
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\billing\hiapi\price;
12
13
use hiqdev\billing\hiapi\models\Price;
14
use yii\db\Expression;
15
16
class PriceQuery extends \hiqdev\yii\DataMapper\query\Query
17
{
18
    /**
19
     * @var string
20
     */
21
    protected $modelClass = Price::class;
22
23
    protected function attributesMap()
24
    {
25
        return [
26
            'id' => 'zp.id',
27
            'plan' => [
28
                'id' => 'zp.tariff_id',
29
            ],
30
            'target' => [
31
                'id' => 'zp.object_id',
32
                'type' => 'oc.name',
33
            ],
34
            'type' => [
35
                'id' => 'zp.type_id',
36
                'name' => 'rt.name',
37
            ],
38
            'price' => [
39
                'currency' => 'cu.name',
40
                'amount' => 'zp.price',
41
            ],
42
            'prepaid' => [
43
                'unit' => 'tu.name',
44
                'quantity' => 'zp.quantity',
45
            ],
46
            'data' => 'zp.data',
47
        ];
48
    }
49
50 View Code Duplication
    public function initFrom()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
51
    {
52
        return $this
53
            ->from('uprice              zp')
54
            ->leftJoin('zref            rt', 'rt.obj_id = zp.type_id')
55
            ->leftJoin('zref            tu', 'tu.obj_id = zp.unit_id')
56
            ->leftJoin('zref            cu', 'cu.obj_id = zp.currency_id')
57
            ->leftJoin('obj             zo', 'zo.obj_id = zp.object_id')
58
            ->leftJoin('zref            oc', 'oc.obj_id = zo.class_id');
59
    }
60
}
61