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

GitHub   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 102
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSetting() 0 22 3
A __construct() 0 3 1
A getInstance() 0 8 2
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 GitHub
25
 */
26
class GitHub extends GitHubClient
27
{
28
29
    public const BASE_URL = 'https://api.github.com/';
30
    /**
31
     * @var string
32
     */
33
    public $user = 'myusername';
34
    /**
35
     * @var string
36
     */
37
    public $token = 'mytoken';
38
    /**
39
     * Verbose debugging for curl (when putting)
40
     * @var bool
41
     */
42
    public $debug = false;
43
44
    /**
45
     * Constructor
46
     *
47
     * @param null
48
     */
49
    public function __construct()
50
    {
51
        $this->getSetting();
52
    }
53
54
    /**
55
     * @static function &getInstance
56
     *
57
     * @param null
58
     * @return GitHub of GitHub
59
     */
60
    public static function getInstance()
61
    {
62
        static $instance = false;
63
        if (!$instance) {
64
            $instance = new self();
65
        }
66
67
        return $instance;
68
    }
69
70
    /**
71
     * Get data of all repositories of given user
72
     *
73
     * @param string $user
74
     * @return array
75
76
    public function readUserRepositories($user)
77
    {
78
        $githubLib = new Repositories();
79
        $repos = $githubLib->getUserRepositories($user);
80
81
        return $repos;
82
    }
83
    */
84
85
    /**
86
     * Get data of all repositories of given organisation
87
     *
88
     * @param $org
89
     * @return array
90
91
    public function readOrgRepositories($org)
92
    {
93
        $githubLib = new Repositories();
94
        $repos = $githubLib->getOrgRepositories($org);
95
96
        return $repos;
97
    }
98
    */
99
100
    /**
101
     * Get primary setting
102
     *
103
     * @param bool $user
104
     * @return bool|array
105
     */
106
    private function getSetting($user = false)
0 ignored issues
show
Unused Code introduced by
The parameter $user is not used and could be removed. ( Ignorable by Annotation )

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

106
    private function getSetting(/** @scrutinizer ignore-unused */ $user = false)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
107
    {
108
109
        $this->user = 'ggoffy';
110
        $this->token = 'effca620d3b6a14813e53086c5477646743073aa';
111
112
        return true;
113
114
115
        $helper = Helper::getInstance();
0 ignored issues
show
Unused Code introduced by
$helper = XoopsModules\W...b\Helper::getInstance() is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
116
        $settingsHandler = $helper->getHandler('Settings');
117
        if ($user) {
118
            $setting = $settingsHandler->getRequestSetting();
119
        } else {
120
            $setting = $settingsHandler->getPrimarySetting();
121
        }
122
123
        if (0 == \count($setting)) {
124
            \redirect_header('settings.php', 3, \_AM_WGTRANSIFEX_THEREARENT_SETTINGS);
0 ignored issues
show
Bug introduced by
The constant _AM_WGTRANSIFEX_THEREARENT_SETTINGS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

124
            /** @scrutinizer ignore-call */ \redirect_header('settings.php', 3, \_AM_WGTRANSIFEX_THEREARENT_SETTINGS);
Loading history...
125
        }
126
127
        return $setting;
128
    }
129
130
131
}
132