pongo /
firebase-php
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | namespace Firebase; |
||
| 3 | |||
| 4 | require_once __DIR__ . '/firebaseInterface.php'; |
||
| 5 | |||
| 6 | /** |
||
| 7 | * Class FirebaseStub |
||
| 8 | * |
||
| 9 | * Stubs the Firebase interface without issuing any cURL requests. |
||
| 10 | * |
||
| 11 | * @package Firebase |
||
| 12 | */ |
||
| 13 | class FirebaseStub implements FirebaseInterface |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var null|string |
||
| 17 | */ |
||
| 18 | private $_response = null; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var |
||
| 22 | */ |
||
| 23 | public $_baseURI; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var |
||
| 27 | */ |
||
| 28 | public $_token; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @param string $baseURI |
||
| 32 | * @param string $token |
||
| 33 | */ |
||
| 34 | function __construct($baseURI = '', $token = '') |
||
| 35 | { |
||
| 36 | if (!extension_loaded('curl')) { |
||
| 37 | trigger_error('Extension CURL is not loaded.', E_USER_ERROR); |
||
| 38 | } |
||
| 39 | |||
| 40 | $this->setBaseURI($baseURI); |
||
| 41 | $this->setTimeOut(10); |
||
| 42 | $this->setToken($token); |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param string $token |
||
| 47 | * @return null |
||
| 48 | */ |
||
| 49 | public function setToken($token) |
||
| 50 | { |
||
| 51 | $this->_token = $token; |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @param string $baseURI |
||
| 56 | * @return null |
||
| 57 | */ |
||
| 58 | public function setBaseURI($baseURI) |
||
| 59 | { |
||
| 60 | $baseURI .= (substr($baseURI, -1) == '/' ? '' : '/'); |
||
| 61 | $this->_baseURI = $baseURI; |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @param integer $seconds |
||
| 66 | * @return null |
||
| 67 | */ |
||
| 68 | public function setTimeOut($seconds) |
||
| 69 | { |
||
| 70 | $this->_timeout = $seconds; |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @param string $path |
||
| 75 | * @param string|null $data |
||
| 76 | * @param $options |
||
| 77 | * @return null |
||
| 78 | */ |
||
| 79 | public function set($path, $data, $options = array()) |
||
| 80 | { |
||
| 81 | return $this->_getSetResponse($data); |
||
| 82 | } |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @param string $path |
||
| 86 | * @param string $data |
||
| 87 | * @param $options |
||
| 88 | * @return null |
||
| 89 | */ |
||
| 90 | public function push($path, $data, $options = array()) |
||
| 91 | { |
||
| 92 | return $this->set($path, $data); |
||
| 93 | } |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @param string $path |
||
| 97 | * @param string $data |
||
| 98 | * @param $options |
||
| 99 | * @return null |
||
| 100 | */ |
||
| 101 | public function update($path, $data, $options = array()) |
||
| 102 | { |
||
| 103 | return $this->set($path, $data); |
||
| 104 | } |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @param $path |
||
| 108 | * @param $options |
||
| 109 | * @return null |
||
| 110 | */ |
||
| 111 | public function get($path, $options = array()) |
||
| 112 | { |
||
| 113 | return $this->_getGetResponse(); |
||
| 114 | } |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @param string $path |
||
| 118 | * @param $options |
||
| 119 | * @return null |
||
| 120 | */ |
||
| 121 | public function delete($path, $options = array()) |
||
| 122 | { |
||
| 123 | return $this->_getDeleteResponse(); |
||
| 124 | } |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @param string $expectedResponse |
||
| 128 | */ |
||
| 129 | public function setResponse($expectedResponse) |
||
| 130 | { |
||
| 131 | $this->_response = $expectedResponse; |
||
| 132 | } |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @uses $this->_baseURI |
||
| 136 | * @return Error |
||
| 137 | */ |
||
| 138 | private function _isBaseURIValid() |
||
| 139 | { |
||
| 140 | $error = preg_match('/^https:\/\//', $this->_baseURI); |
||
| 141 | return new Error(($error == 0 ? true : false), 'Firebase does not support non-ssl traffic. Please try your request again over https.'); |
||
| 142 | } |
||
| 143 | |||
| 144 | /** |
||
| 145 | * @param $data |
||
| 146 | * @return Error |
||
| 147 | */ |
||
| 148 | private function _isDataValid($data) |
||
| 149 | { |
||
| 150 | if ($data == "" || $data == null) { |
||
| 151 | return new Error(true, "Missing data; Perhaps you forgot to send the data."); |
||
| 152 | } |
||
| 153 | $error = json_decode($data); |
||
| 154 | return new Error(($error !== null ? false : true), "Invalid data; couldn't parse JSON object, array, or value. Perhaps you're using invalid characters in your key names."); |
||
| 155 | } |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @param string|null $data |
||
| 159 | * @return null |
||
| 160 | */ |
||
| 161 | private function _getSetResponse($data) |
||
| 162 | { |
||
| 163 | $validBaseUriObject = $this->_isBaseURIValid(); |
||
| 164 | if ($validBaseUriObject->error) { |
||
| 165 | return $validBaseUriObject->message; |
||
| 166 | } |
||
| 167 | |||
| 168 | $validDataObject = $this->_isDataValid($data); |
||
| 169 | if ($validDataObject->error) { |
||
| 170 | return $validDataObject->message; |
||
| 171 | } |
||
| 172 | |||
| 173 | return $this->_response; |
||
| 174 | } |
||
| 175 | |||
| 176 | /** |
||
| 177 | * @return null |
||
| 178 | */ |
||
| 179 | private function _getGetResponse() |
||
| 180 | { |
||
| 181 | $validBaseUriObject = $this->_isBaseURIValid(); |
||
| 182 | if ($validBaseUriObject->error) { |
||
| 183 | return $validBaseUriObject->message; |
||
| 184 | } |
||
| 185 | return $this->_response; |
||
| 186 | } |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @return null |
||
| 190 | */ |
||
| 191 | private function _getDeleteResponse() |
||
| 192 | { |
||
| 193 | return $this->_getGetResponse(); |
||
| 194 | } |
||
| 195 | } |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Class Error |
||
| 199 | * |
||
| 200 | * @package Firebase |
||
| 201 | */ |
||
| 202 | class Error |
||
| 203 | { |
||
| 204 | /** |
||
| 205 | * @param boolean $error |
||
| 206 | * @param string $message |
||
| 207 | */ |
||
| 208 | function __construct($error, $message) |
||
|
0 ignored issues
–
show
|
|||
| 209 | { |
||
| 210 | $this->error = $error; |
||
| 211 | $this->message = $message; |
||
| 212 | } |
||
| 213 | } |
||
| 214 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.