Completed
Push — master ( a00223...b355d9 )
by Dmitry
01:57
created

TypeQuery::attributesMap()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 8
cp 0
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
crap 2
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\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
17
class TypeQuery extends \hiqdev\yii\DataMapper\query\Query
18
{
19
    /**
20
     * @var string
21
     */
22
    protected $modelClass = Type::class;
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    protected function attributesMap()
28
    {
29
        return [
30
            'id' => 'zr.obj_id',
31
            'name' => 'zr.name',
32
            //                                TODO: Drop ˯˯˯˯˯˯˯˯ this after removing models
33
            new JoinedField('fullName', 'zh.name', $this->getModel()->getAttribute('fullName'), 'fullRef'),
0 ignored issues
show
Documentation Bug introduced by
The method getModel does not exist on object<hiqdev\billing\hiapi\type\TypeQuery>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
34
        ];
35
    }
36
37
    public function joins()
38
    {
39
        return [
40
            'fullRef' => new Join('zref_h zh', 'zh.obj_id = zr.obj_id')
41
        ];
42
    }
43
44
    public function initFrom()
45
    {
46
        return $this
47
            ->from('zref zr');
48
    }
49
}
50