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

Releases::getLatestRelease()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 6
nop 3
dl 0
loc 18
rs 9.9
c 0
b 0
f 0
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 Releases
25
 */
26
class Releases extends GitHub
27
{
28
    /**
29
     * Get all releases
30
     *
31
     * @param $user
32
     * @param $repository
33
     * @return array
34
     */
35
    public function getReleases($user, $repository)
36
    {
37
        $url = static::BASE_URL . 'repos/' . $user . '/' . $repository . '/releases';
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 latest release
44
     *
45
     * @param $user
46
     * @param $repository
47
     * @param bool $prerelease
48
     * @return array
49
     */
50
    public function getLatestRelease($user, $repository, $prerelease = false)
51
    {
52
        if ($prerelease) {
53
            $url = static::BASE_URL . 'repos/' . $user . '/' . $repository . '/releases';
54
        } else {
55
            $url = static::BASE_URL . 'repos/' . $user . '/' . $repository . '/releases/latest';
56
        }
57
        $result = $this->_get($url);
58
59
        if ($prerelease) {
60
            if (\is_array($result)) {
61
                return $result[0];
62
            } else {
63
                return [];
64
            }
65
        }
66
67
        return $result;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result also could return the type boolean which is incompatible with the documented return type array.
Loading history...
68
    }
69
70
}
71