Completed
Push — master ( 36a32a...6a1f1d )
by Andrii
02:36 queued 11s
created

QueryBuilder::buildUri()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
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