GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 99b4b5...41712d )
by Jared
02:02
created

JCFirebase::mergeRequestPathURI()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 3
eloc 6
nc 3
nop 3
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: jaredchu
5
 * Date: 11/29/16
6
 * Time: 3:47 PM
7
 */
8
9
namespace JCFirebase;
10
11
use Requests;
12
use JCFirebase\JCFirebaseOption;
13
14
/**
15
 * Class JCFirebase
16
 * @package JCFirebase
17
 * reference https://www.firebase.com/docs/rest/api/
18
 */
19
class JCFirebase
20
{
21
    public $firebaseSecret;
22
    public $firebaseURI;
23
    public $firebaseDefaultPath;
24
25
    public $requestHeader = array(
26
        'accept' => 'application/json',
27
        'contentType' => 'application/json; charset=utf-8',
28
        'dataType' => 'json'
29
    );
30
31
    public $requestOptions = array();
32
33
    public function __construct($firebaseURI,$firebaseSecret = '',$firebaseDefaultPath = '/')
34
    {
35
        $this->firebaseSecret = $firebaseSecret;
36
        $this->firebaseURI = $firebaseURI;
37
        $this->firebaseDefaultPath = $firebaseDefaultPath;
38
    }
39
40
    public function getPathURI($path = '',$print = ''){
41
        //remove .json or last slash from firebaseURI
42
        $templates = array(
43
            '.json',
44
            '/.json',
45
            '/'
46
        );
47
        foreach ($templates as $template){
48
            $this->firebaseURI = rtrim($this->firebaseURI,$template);
49
        }
50
51
        //check https
52
        if(strpos($this->firebaseURI, 'http://') !== false){
53
            throw new \Exception("https is required.");
54
        }
55
56
        //check firebaseURI
57
        if(strlen($this->firebaseURI) == 0){
58
            throw new \Exception("firebase URI is required");
59
        }
60
61
        $pathURI = $this->firebaseURI.$this->firebaseDefaultPath.$path.".json";
62
63
        $queryData = array();
64
65
        if(strlen($print) > 0){
66
            $queryData[JCFirebaseOption::OPTION_PRINT] = $print;
67
        }
68
69
        if(count($queryData) > 0){
70
            $pathURI = $pathURI . '?' . http_build_query($queryData);
71
        }
72
73
        return $pathURI;
74
    }
75
76
    /**
77
     * @param string $path
78
     * @param array $options
79
     * @return \Requests_Response
80
     */
81
    public function get($path = '',$options = array()){
82
        return Requests::get(
83
            $this->mergeRequestPathURI($path,$options),$this->requestHeader,
84
            $this->mergeRequestOptions($options)
0 ignored issues
show
Bug introduced by
It seems like $this->mergeRequestOptions($options) targeting JCFirebase\JCFirebase::mergeRequestOptions() can also be of type string; however, Requests::get() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
85
        );
86
    }
87
88
    public function getShallow($path = '',$options = array()){
89
        return Requests::get($this->getPathURI(
90
            $path). '?' . http_build_query(array(JCFirebaseOption::OPTION_SHALLOW => JCFirebaseOption::SHALLOW_TRUE)),
91
            $this->mergeRequestOptions($options)
0 ignored issues
show
Bug introduced by
It seems like $this->mergeRequestOptions($options) targeting JCFirebase\JCFirebase::mergeRequestOptions() can also be of type string; however, Requests::get() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
92
        );
93
    }
94
95
    /**
96
     * @param string $path
97
     * @param array $options
98
     * @return \Requests_Response
99
     */
100
    public function put($path = '',$options = array()){
101
        return Requests::put($this->getPathURI($path),$this->requestHeader,$this->mergeRequestOptions($options,true));
0 ignored issues
show
Bug introduced by
It seems like $this->mergeRequestOptions($options, true) targeting JCFirebase\JCFirebase::mergeRequestOptions() can also be of type string; however, Requests::put() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
102
    }
103
104
    /**
105
     * @param string $path
106
     * @param array $options
107
     * @return \Requests_Response
108
     */
109
    public function post($path = '',$options = array()){
110
        return Requests::post($this->getPathURI($path),$this->requestHeader,$this->mergeRequestOptions($options,true));
0 ignored issues
show
Bug introduced by
It seems like $this->mergeRequestOptions($options, true) targeting JCFirebase\JCFirebase::mergeRequestOptions() can also be of type string; however, Requests::post() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
111
    }
112
113
    /**
114
     * @param string $path
115
     * @param array $options
116
     * @return \Requests_Response
117
     */
118
    public function patch($path = '',$options = array()){
119
        return Requests::patch($this->getPathURI($path),$this->requestHeader,$this->mergeRequestOptions($options,true));
0 ignored issues
show
Bug introduced by
It seems like $this->mergeRequestOptions($options, true) targeting JCFirebase\JCFirebase::mergeRequestOptions() can also be of type string; however, Requests::patch() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
120
    }
121
122
    /**
123
     * @param string $path
124
     * @param array $options
125
     * @return \Requests_Response
126
     */
127
    public function delete($path = '',$options = array()){
128
        return Requests::delete($this->getPathURI($path),$this->requestHeader,$this->mergeRequestOptions($options));
0 ignored issues
show
Bug introduced by
It seems like $this->mergeRequestOptions($options) targeting JCFirebase\JCFirebase::mergeRequestOptions() can also be of type string; however, Requests::delete() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
129
    }
130
131
    protected function mergeRequestOptions($options = array(),$encode = false){
132
        $requestOptions = array();
133
134
        if(isset($options['data'])){
135
            $requestOptions = array_merge($options['data'],$requestOptions);
136
        }
137
138
        if($encode){
139
            $requestOptions = json_encode($requestOptions);
140
        }
141
142
        return $requestOptions;
143
    }
144
145
    protected function mergeRequestPathURI($path='',$options = array(),$reqType = JCFirebaseOption::REQ_TYPE_GET){
146
        $print = '';
147
        if(isset($options['print'])){
148
            if(JCFirebaseOption::isAllowPrint($reqType,$options['print'])){
149
                $print = $options['print'];
150
            }
151
        }
152
        return $pathURI = $this->getPathURI($path,$print);
0 ignored issues
show
Unused Code introduced by
$pathURI is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
153
    }
154
}