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 ( 507539...99b4b5 )
by Jared
02:21
created

JCFirebase::put()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 2
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
13
/**
14
 * Class JCFirebase
15
 * @package JCFirebase
16
 * reference https://www.firebase.com/docs/rest/api/
17
 */
18
class JCFirebase
19
{
20
    const OPTION_SHALLOW = 'shallow';
21
22
    public $firebaseSecret;
23
    public $firebaseURI;
24
    public $firebaseDefaultPath;
25
26
    public $requestHeader = array(
27
        'accept' => 'application/json',
28
        'contentType' => 'application/json; charset=utf-8',
29
        'dataType' => 'json'
30
    );
31
32
    public $requestOptions = array();
33
34
    public function __construct($firebaseURI,$firebaseSecret = '',$firebaseDefaultPath = '/')
35
    {
36
        $this->firebaseSecret = $firebaseSecret;
37
        $this->firebaseURI = $firebaseURI;
38
        $this->firebaseDefaultPath = $firebaseDefaultPath;
39
    }
40
41
    public function getPathURI($path = ''){
42
        //remove .json or last slash from firebaseURI
43
        $templates = array(
44
            '.json',
45
            '/.json',
46
            '/'
47
        );
48
        foreach ($templates as $template){
49
            $this->firebaseURI = rtrim($this->firebaseURI,$template);
50
        }
51
52
        //check https
53
        if(strpos($this->firebaseURI, 'http://') !== false){
54
            throw new \Exception("https is required.");
55
        }
56
57
        //check firebaseURI
58
        if(strlen($this->firebaseURI) == 0){
59
            throw new \Exception("firebase URI is required");
60
        }
61
62
        $pathURI = $this->firebaseURI.$this->firebaseDefaultPath.$path.".json";
63
        return $pathURI;
64
    }
65
66
    /**
67
     * @param string $path
68
     * @param array $options
69
     * @return \Requests_Response
70
     */
71
    public function get($path = '',$options = array()){
72
        return Requests::get($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::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...
73
    }
74
75
    public function getShallow($path = '',$options = array()){
76
        return Requests::get($this->getPathURI($path). '?' . http_build_query(array(self::OPTION_SHALLOW => 'true')),
77
            $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...
78
    }
79
80
    /**
81
     * @param string $path
82
     * @param array $options
83
     * @return \Requests_Response
84
     */
85
    public function put($path = '',$options = array()){
86
        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...
87
    }
88
89
    /**
90
     * @param string $path
91
     * @param array $options
92
     * @return \Requests_Response
93
     */
94
    public function post($path = '',$options = array()){
95
        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...
96
    }
97
98
    /**
99
     * @param string $path
100
     * @param array $options
101
     * @return \Requests_Response
102
     */
103
    public function patch($path = '',$options = array()){
104
        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...
105
    }
106
107
    /**
108
     * @param string $path
109
     * @param array $options
110
     * @return \Requests_Response
111
     */
112
    public function delete($path = '',$options = array()){
113
        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...
114
    }
115
116
    protected function mergeRequestOptions($options = array(),$encode = false){
117
        $requestOptions = array();
118
119
        if(isset($options['data'])){
120
            $requestOptions = array_merge($options['data'],$requestOptions);
121
        }
122
123
        if($encode){
124
            $requestOptions = json_encode($requestOptions);
125
        }
126
127
        return $requestOptions;
128
    }
129
}