Passed
Push — master ( 3d7fba...dbde9b )
by Goffy
03:57
created

Repositories   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getReadme() 0 4 1
A getOrgRepositories() 0 6 1
A getUserRepositories() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace XoopsModules\Wggithub\Github;
6
7
/*
8
 * You may not change or alter any portion of this comment or credits
9
 * of supporting developers from this source code or any supporting source code
10
 * which is considered copyrighted (c) material of the original comment or credit authors.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
 */
16
/**
17
 * @copyright    XOOPS Project https://xoops.org/
18
 * @license      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
19
 * @since
20
 * @author       Goffy - XOOPS Development Team
21
 */
22
23
/**
24
 * Class Repositories
25
 */
26
class Repositories extends GitHub
27
{
28
29
    /**
30
     * Get repositories of given user
31
     *
32
     * @param $username
33
     * @return array
34
     */
35
    public function getUserRepositories($username)
36
    {
37
        $url = static::BASE_URL . 'users/' . $username . '/repos';
38
39
        return $this->_get($url);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->_get($url) also could return the type boolean which is incompatible with the documented return type array.
Loading history...
40
    }
41
42
    /**
43
     * Get repositories of given organisation
44
     *
45
     * @param $org
46
     * @return array
47
     */
48
    public function getOrgRepositories($org)
49
    {
50
        $url = static::BASE_URL . 'orgs/' . $org . '/repos';
51
        //$ret = $this->extractData($this->_get($url));
52
        //return $ret;
53
        return $this->_get($url);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->_get($url) also could return the type boolean which is incompatible with the documented return type array.
Loading history...
54
    }
55
56
    /**
57
     * Get the readme content for a repository by its username and repository name.
58
     *
59
     * @link http://developer.github.com/v3/repos/contents/#get-the-readme
60
     *
61
     * @param string $username   the user who owns the repository
62
     * @param string $repository the name of the repository
63
     *
64
     * @return string|array the readme content
65
     */
66
    public function getReadme($username, $repository)
67
    {
68
        $url = static::BASE_URL . 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/readme';
69
        return $this->_get($url, false, false);
0 ignored issues
show
Unused Code introduced by
The call to XoopsModules\Wggithub\Github\GithubClient::_get() has too many arguments starting with false. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
        return $this->/** @scrutinizer ignore-call */ _get($url, false, false);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
70
    }
71
72
73
    /*
74
    private function extractData($arrData) {
75
        $ret = [];
76
        foreach ($arrData as $key => $value) {
77
            $ret[$key]['id'] = $value['id'];
78
            $ret[$key]['node_id'] = $value['node_id'];
79
            $ret[$key]['name'] = $value['name'];
80
            $ret[$key]['full_name'] = $value['full_name'];
81
        }
82
83
        return $ret;
84
    }
85
    */
86
87
}
88