TypeQuery   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
c 2
b 0
f 0
dl 0
loc 32
ccs 0
cts 19
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A joins() 0 4 1
A initFrom() 0 5 1
A attributesMap() 0 7 1
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-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\billing\hiapi\type;
12
13
use hiqdev\billing\hiapi\models\Type;
14
use hiqdev\yii\DataMapper\query\join\Join;
15
use hiqdev\yii\DataMapper\query\JoinedField;
16
use yii\db\Expression;
17
18
class TypeQuery extends \hiqdev\yii\DataMapper\query\Query
19
{
20
    /**
21
     * @var string
22
     */
23
    protected $modelClass = Type::class;
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    protected function attributesMap()
29
    {
30
        return [
31
            'id' => 'zr.obj_id',
32
            'name' => new Expression("pr.name || ',' || zr.name as name"),
33
            //                                TODO: Drop ˯˯˯˯˯˯˯˯ this after removing models
34
            new JoinedField('fullName', 'zh.name', $this->getModel()->getAttribute('fullName'), 'fullRef'),
35
        ];
36
    }
37
38
    public function joins()
39
    {
40
        return [
41
            'fullRef' => new Join('zref_h zh', 'zh.obj_id = zr.obj_id'),
42
        ];
43
    }
44
45
    public function initFrom()
46
    {
47
        return $this
48
            ->from('zref zr')
49
            ->leftJoin('zref pr', 'pr.obj_id = zr._id');
50
    }
51
}
52