QueryBuilder   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 28
ccs 14
cts 15
cp 0.9333
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildUri() 0 8 2
A buildPrefix() 0 16 4
1
<?php
2
/**
3
 * GitHub API implementation for yii2-hiart.
4
 *
5
 * @link      https://github.com/hiqdev/yii2-hiart-github
6
 * @package   yii2-hiart-github
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\hiart\github;
12
13
use hiqdev\hiart\Query;
14
15
/**
16
 * Query builder for GitHub API.
17
 *
18
 * @author Andrii Vasyliev <[email protected]>
19
 */
20
class QueryBuilder extends \hiqdev\hiart\rest\QueryBuilder
21
{
22 2
    public function buildUri(Query $query)
23
    {
24 2
        $from = $query->from . 's';
25
26 2
        $prefix = $this->buildPrefix($query);
27
28 2
        return ($prefix ? $prefix . '/' : '') . $from;
29
    }
30
31 2
    public function buildPrefix(Query $query)
32
    {
33 2
        if ($query->from === 'repo') {
34 2
            if (!empty($query->where['organization'])) {
35 1
                $organization = $query->where['organization'];
36 1
                unset($query->where['organization']);
37
38 1
                return "orgs/$organization";
39 1
            } elseif (!empty($query->where['user'])) {
40 1
                $user = $query->where['user'];
41 1
                unset($query->where['user']);
42
43 1
                return "users/$user";
44
            }
45
        }
46
    }
47
}
48