Completed
Push — master ( 05f0c6...d5b4df )
by Dmitry
03:21
created

CustomerQuery   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 34
ccs 0
cts 18
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getFields() 0 9 1
A initSelect() 0 6 1
A selectByFields() 0 10 3
1
<?php
2
3
namespace hiqdev\billing\hiapi\query;
4
5
use hiapi\query\Field;
6
use hiqdev\billing\hiapi\models\Customer;
7
8
class CustomerQuery extends \hiapi\query\Query
9
{
10
    public function getFields()
11
    {
12
        return $this->fieldFactory->createByModelAttributes(new Customer(), [
13
            'id' => 'zc.obj_id',
14
            'login' => 'zc.login',
15
            'seller-id' => 'cr.obj_id',
16
            'seller-login' => 'zc.login',
17
        ]);
18
    }
19
20
    public function initSelect()
21
    {
22
        return $this->selectByFields($this->getFields())
23
            ->from('zclient         zc')
24
            ->leftJoin('zclient     cr', 'cr.obj_id = zc.seller_id');
25
    }
26
27
    /**
28
     * @param Field[] $fields
29
     * @return $this
30
     */
31
    protected function selectByFields($fields)
32
    {
33
        foreach ($fields as $field) {
34
            if ($field->canBeSelected()) {
35
                $this->addSelect($field->getSql() . ' as ' . $field->getName());
36
            }
37
        }
38
39
        return $this;
40
    }
41
}
42