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 ( c739f3...388e4c )
by Jared
02:16
created

JCFirebase   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 14
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 106
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B getPathURI() 0 24 4
A get() 0 3 1
A put() 0 3 1
A post() 0 3 1
A patch() 0 3 1
A delete() 0 3 1
A mergeRequestOptions() 0 16 4
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
    public $firebaseSecret;
21
    public $firebaseURI;
22
    public $firebaseDefaultPath;
23
24
    public $auth;
25
    public $shallow;
26
    public $print;
27
    public $callback;
28
    public $format;
29
    public $download;
30
    public $orderBy;
31
    public $limitToFirst;
32
    public $limitToLast;
33
    public $startAt;
34
    public $endAt;
35
    public $equalTo;
36
37
    public $streaming = 'text/event-stream';
38
    public $priority = '.priority';
39
    public $serverValues = '.sv';
40
41
    public $rulePath = '.settings/rules.json';
42
43
    public $requestHeader = array(
44
        'accept' => 'application/json',
45
        'contentType' => 'application/json; charset=utf-8',
46
        'dataType' => 'json'
47
    );
48
    public $requestOptions = array();
49
50
    public function __construct($firebaseURI,$firebaseSecret = '',$firebaseDefaultPath = '/')
51
    {
52
        $this->firebaseSecret = $firebaseSecret;
53
        $this->firebaseURI = $firebaseURI;
54
        $this->firebaseDefaultPath = $firebaseDefaultPath;
55
    }
56
57
    public function getPathURI($path = ''){
58
        //remove .json or last slash from firebaseURI
59
        $templates = array(
60
            '.json',
61
            '/.json',
62
            '/'
63
        );
64
        foreach ($templates as $template){
65
            $this->firebaseURI = rtrim($this->firebaseURI,$template);
66
        }
67
68
        //check https
69
        if(strpos($this->firebaseURI, 'http://') !== false){
70
            throw new \Exception("https is required.");
71
        }
72
73
        //check firebaseURI
74
        if(strlen($this->firebaseURI) == 0){
75
            throw new \Exception("firebase URI is required");
76
        }
77
78
        $pathURI = $this->firebaseURI.$this->firebaseDefaultPath.$path.".json";
79
        return $pathURI;
80
    }
81
82
83
    /**
84
     * @param array $options
85
     * @return \Requests_Response
86
     */
87
    public function get($path = '',$options = array()){
88
        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...
89
    }
90
91
    public function put($path = '',$options = array()){
92
        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...
93
    }
94
95
    public function post($path = '',$options = array()){
96
        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...
97
    }
98
99
    public function patch($path = '',$options = array()){
100
        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...
101
    }
102
103
    public function delete($path = '',$options = array()){
104
        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...
105
    }
106
107
    protected function mergeRequestOptions($options = array(),$encode = false){
108
        $requestOptions = array();
109
        if(isset($options['settings'])){
110
            $requestOptions = array_merge($options['settings'],$requestOptions);
111
        }
112
113
        if(isset($options['data'])){
114
            $requestOptions = array_merge($options['data'],$requestOptions);
115
        }
116
117
        if($encode){
118
            $requestOptions = json_encode($requestOptions);
119
        }
120
121
        return $requestOptions;
122
    }
123
}