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 |
||
|
0 ignored issues
–
show
|
|||
| 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 = '') |
||
|
0 ignored issues
–
show
|
|||
| 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; |
||
|
0 ignored issues
–
show
The property
_timeout does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
Loading history...
|
|||
| 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) { |
||
|
0 ignored issues
–
show
The property
error does not seem to exist in Firebase\Error.
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. Loading history...
|
|||
| 165 | return $validBaseUriObject->message; |
||
|
0 ignored issues
–
show
The property
message does not seem to exist in Firebase\Error.
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. Loading history...
|
|||
| 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) { |
||
|
0 ignored issues
–
show
The property
error does not seem to exist in Firebase\Error.
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. Loading history...
|
|||
| 183 | return $validBaseUriObject->message; |
||
|
0 ignored issues
–
show
The property
message does not seem to exist in Firebase\Error.
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. Loading history...
|
|||
| 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 |
||
|
0 ignored issues
–
show
|
|||
| 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; |
||
|
0 ignored issues
–
show
The property
error does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
Loading history...
|
|||
| 211 | $this->message = $message; |
||
|
0 ignored issues
–
show
The property
message does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
Loading history...
|
|||
| 212 | } |
||
| 213 | } |
||
| 214 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.