Completed
Branch master (da4a0f)
by Frank
13:34 queued 11:18
created

GerritTrait::remoteCall()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 12
nc 2
nop 1
dl 0
loc 17
rs 9.4285
c 1
b 0
f 0
1
<?php
2
/**
3
 * T3Bot.
4
 *
5
 * @author Frank Nägler <[email protected]>
6
 *
7
 * @link http://www.t3bot.de
8
 * @link http://wiki.typo3.org/T3Bot
9
 */
10
11
namespace T3Bot\Traits;
12
13
trait GerritTrait
14
{
15
    /**
16
     * @param string $query
17
     *
18
     * @return \stdClass|array|bool
19
     */
20
    protected function queryGerrit($query)
21
    {
22
        return $this->remoteCall('https://review.typo3.org/changes/?q='.urlencode($query));
23
    }
24
25
    /**
26
     * @param int $changeId
27
     * @param int $revision
28
     *
29
     * @return mixed|string
30
     */
31
    protected function getFilesForPatch($changeId, $revision)
32
    {
33
        return $this->remoteCall(
34
            'https://review.typo3.org/changes/' . $changeId . '/revisions/' . $revision . '/files'
35
        );
36
    }
37
38
    /**
39
     * @param string $url
40
     *
41
     * @return bool|mixed
42
     */
43
    protected function remoteCall($url)
44
    {
45
        $ch = curl_init();
46
        $timeout = 5;
47
        curl_setopt($ch, CURLOPT_URL, $url);
48
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
49
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
50
        $data = curl_exec($ch);
51
52
        $result = false;
53
        if (!curl_errno($ch)) {
54
            curl_close($ch);
55
            $result = json_decode(str_replace(")]}'\n", '', $data), true);
56
        }
57
58
        return $result;
59
    }
60
}
61