Skip to content

Commit 92db76f

Browse files
authored
Update firebaseStub.php
1 parent 69499c9 commit 92db76f

File tree

1 file changed

+44
-37
lines changed

1 file changed

+44
-37
lines changed

src/firebaseStub.php

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
2-
namespace DataService;
2+
namespace Firebase;
3+
4+
require_once __DIR__ . '/firebaseInterface.php';
35

46
/**
57
* Class FirebaseStub
@@ -75,7 +77,7 @@ public function setTimeOut($seconds)
7577
*/
7678
public function set($path, $data)
7779
{
78-
return $this->_getSetResponse($data);
80+
return $this->_getSetResponse($data);
7981
}
8082

8183
/**
@@ -85,7 +87,7 @@ public function set($path, $data)
8587
*/
8688
public function push($path, $data)
8789
{
88-
return $this->set($path, $data);
90+
return $this->set($path, $data);
8991
}
9092

9193
/**
@@ -95,7 +97,7 @@ public function push($path, $data)
9597
*/
9698
public function update($path, $data)
9799
{
98-
return $this->set($path, $data);
100+
return $this->set($path, $data);
99101
}
100102

101103
/**
@@ -104,7 +106,7 @@ public function update($path, $data)
104106
*/
105107
public function get($path)
106108
{
107-
return $this->_getGetResponse();
109+
return $this->_getGetResponse();
108110
}
109111

110112
/**
@@ -113,7 +115,7 @@ public function get($path)
113115
*/
114116
public function delete($path)
115117
{
116-
return $this->_getDeleteResponse();
118+
return $this->_getDeleteResponse();
117119
}
118120

119121
/**
@@ -128,23 +130,23 @@ public function setResponse($expectedResponse)
128130
* @uses $this->_baseURI
129131
* @return Error
130132
*/
131-
private function _isBaseURIValid() {
132-
$error = preg_match('/^https:\/\//', $this->_baseURI);
133-
return new Error(($error == 0 ? true : false), 'Firebase does not support non-ssl traffic. Please try your request again over https.');
133+
private function _isBaseURIValid()
134+
{
135+
$error = preg_match('/^https:\/\//', $this->_baseURI);
136+
return new Error(($error == 0 ? true : false), 'Firebase does not support non-ssl traffic. Please try your request again over https.');
134137
}
135138

136139
/**
137140
* @param $data
138141
* @return Error
139142
*/
140-
private function _isDataValid($data) {
141-
142-
if ($data == "" || $data == null) {
143-
return new Error(true, "Missing data; Perhaps you forgot to send the data.");
144-
}
145-
146-
$error = json_decode($data);
147-
return new Error(($error ? false : true), "Invalid data; couldn't parse JSON object, array, or value. Perhaps you're using invalid characters in your key names.");
143+
private function _isDataValid($data)
144+
{
145+
if ($data == "" || $data == null) {
146+
return new Error(true, "Missing data; Perhaps you forgot to send the data.");
147+
}
148+
$error = json_decode($data);
149+
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.");
148150
}
149151

150152
/**
@@ -153,49 +155,54 @@ private function _isDataValid($data) {
153155
*/
154156
private function _getSetResponse($data)
155157
{
156-
$validBaseUriObject = $this->_isBaseURIValid();
157-
if ($validBaseUriObject->error) {
158-
return $validBaseUriObject->message;
159-
}
158+
$validBaseUriObject = $this->_isBaseURIValid();
159+
if ($validBaseUriObject->error) {
160+
return $validBaseUriObject->message;
161+
}
160162

161-
$validDataObject = $this->_isDataValid($data);
162-
if ($validDataObject->error) {
163-
return $validDataObject->message;
164-
}
163+
$validDataObject = $this->_isDataValid($data);
164+
if ($validDataObject->error) {
165+
return $validDataObject->message;
166+
}
165167

166-
return $this->_response;
168+
return $this->_response;
167169
}
168170

169171
/**
170172
* @return null
171173
*/
172174
private function _getGetResponse()
173175
{
174-
$validBaseUriObject = $this->_isBaseURIValid();
175-
if ($validBaseUriObject->error) {
176-
return $validBaseUriObject->message;
177-
}
178-
return $this->_response;
176+
$validBaseUriObject = $this->_isBaseURIValid();
177+
if ($validBaseUriObject->error) {
178+
return $validBaseUriObject->message;
179+
}
180+
return $this->_response;
179181
}
180182

181183
/**
182184
* @return null
183185
*/
184-
private function _getDeleteResponse() { return $this->_getGetResponse(); }
186+
private function _getDeleteResponse()
187+
{
188+
return $this->_getGetResponse();
189+
}
185190
}
186191

187192
/**
188193
* Class Error
194+
*
189195
* @package Firebase
190196
*/
191-
class Error {
197+
class Error
198+
{
192199
/**
193200
* @param $error
194201
* @param $message
195202
*/
196203
function __construct($error, $message)
197-
{
198-
$this->error = $error;
199-
$this->message = $message;
200-
}
204+
{
205+
$this->error = $error;
206+
$this->message = $message;
207+
}
201208
}

0 commit comments

Comments
 (0)