Skip to content

Commit

Permalink
code reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
ktamas77 committed Jun 14, 2016
1 parent 95b4d9b commit e80bb3c
Show file tree
Hide file tree
Showing 6 changed files with 308 additions and 286 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -7,7 +7,7 @@
"REST",
"wrapper"
],
"version": "2.1.0",
"version": "2.1.1",
"authors": [
{
"name": "Tamas Kalman",
Expand Down
16 changes: 11 additions & 5 deletions src/firebaseInterface.php
Expand Up @@ -3,6 +3,7 @@

/**
* Interface FirebaseInterface
*
* @package Firebase
*/
interface FirebaseInterface
Expand All @@ -28,33 +29,38 @@ public function setTimeOut($seconds);
/**
* @param $path
* @param $data
* @param $options
* @return mixed
*/
public function set($path, $data);
public function set($path, $data, $options = array());

/**
* @param $path
* @param $data
* @param $options
* @return mixed
*/
public function push($path, $data);
public function push($path, $data, $options = array());

/**
* @param $path
* @param $data
* @param $options
* @return mixed
*/
public function update($path, $data);
public function update($path, $data, $options = array());

/**
* @param $path
* @param $options
* @return mixed
*/
public function get($path);
public function get($path, $options = array());

/**
* @param $path
* @param $options
* @return mixed
*/
public function delete($path);
public function delete($path, $options = array());
}
44 changes: 21 additions & 23 deletions src/firebaseLib.php
Expand Up @@ -12,15 +12,13 @@
* @author Tamas Kalman <ktamas77@gmail.com>
* @url https://github.com/ktamas77/firebase-php/
* @link https://www.firebase.com/docs/rest-api.html
*
*/

/**
* Firebase PHP Class
*
* @author Tamas Kalman <ktamas77@gmail.com>
* @link https://www.firebase.com/docs/rest-api.html
*
*/
class FirebaseLib implements FirebaseInterface
{
Expand Down Expand Up @@ -77,8 +75,8 @@ public function setBaseURI($baseURI)
/**
* Returns with the normalized JSON absolute path
*
* @param string $path Path
* @param array $options Options
* @param string $path Path
* @param array $options Options
* @return string
*/
private function _getJsonPath($path, $options = array())
Expand Down Expand Up @@ -107,53 +105,53 @@ public function setTimeOut($seconds)
* Writing data into Firebase with a PUT request
* HTTP 200: Ok
*
* @param string $path Path
* @param mixed $data Data
* @param array $options Options
* @param string $path Path
* @param mixed $data Data
* @param array $options Options
*
* @return array Response
*/
public function set($path, $data, $options = array())
{
return $this->_writeData($path, $data, 'PUT', $options);
return $this->_writeData($path, $data, 'PUT', $options);
}

/**
* Pushing data into Firebase with a POST request
* HTTP 200: Ok
*
* @param string $path Path
* @param mixed $data Data
* @param array $options Options
* @param string $path Path
* @param mixed $data Data
* @param array $options Options
*
* @return array Response
*/
public function push($path, $data, $options = array())
{
return $this->_writeData($path, $data, 'POST', $options);
return $this->_writeData($path, $data, 'POST', $options);
}

/**
* Updating data into Firebase with a PATH request
* HTTP 200: Ok
*
* @param string $path Path
* @param mixed $data Data
* @param array $options Options
* @param string $path Path
* @param mixed $data Data
* @param array $options Options
*
* @return array Response
*/
public function update($path, $data, $options = array())
{
return $this->_writeData($path, $data, 'PATCH', $options);
return $this->_writeData($path, $data, 'PATCH', $options);
}

/**
* Reading data from Firebase
* HTTP 200: Ok
*
* @param string $path Path
* @param array $options Options
* @param string $path Path
* @param array $options Options
*
* @return array Response
*/
Expand All @@ -173,8 +171,8 @@ public function get($path, $options = array())
* Deletes data from Firebase
* HTTP 204: Ok
*
* @param string $path Path
* @param array $options Options
* @param string $path Path
* @param array $options Options
*
* @return array Response
*/
Expand All @@ -193,9 +191,9 @@ public function delete($path, $options = array())
/**
* Returns with Initialized CURL Handler
*
* @param string $path Path
* @param string $mode Mode
* @param array $options Options
* @param string $path Path
* @param string $mode Mode
* @param array $options Options
*
* @return resource Curl Handler
*/
Expand Down
90 changes: 51 additions & 39 deletions src/firebaseStub.php
Expand Up @@ -73,49 +73,54 @@ public function setTimeOut($seconds)
/**
* @param $path
* @param $data
* @param $options
* @return null
*/
public function set($path, $data)
public function set($path, $data, $options = array())
{
return $this->_getSetResponse($data);
return $this->_getSetResponse($data);
}

/**
* @param $path
* @param $data
* @param $options
* @return null
*/
public function push($path, $data)
public function push($path, $data, $options = array())
{
return $this->set($path, $data);
return $this->set($path, $data);
}

/**
* @param $path
* @param $data
* @param $options
* @return null
*/
public function update($path, $data)
public function update($path, $data, $options = array())
{
return $this->set($path, $data);
return $this->set($path, $data);
}

/**
* @param $path
* @param $options
* @return null
*/
public function get($path)
public function get($path, $options = array())
{
return $this->_getGetResponse();
return $this->_getGetResponse();
}

/**
* @param $path
* @param $options
* @return null
*/
public function delete($path)
public function delete($path, $options = array())
{
return $this->_getDeleteResponse();
return $this->_getDeleteResponse();
}

/**
Expand All @@ -130,21 +135,23 @@ public function setResponse($expectedResponse)
* @uses $this->_baseURI
* @return Error
*/
private function _isBaseURIValid() {
$error = preg_match('/^https:\/\//', $this->_baseURI);
return new Error(($error == 0 ? true : false), 'Firebase does not support non-ssl traffic. Please try your request again over https.');
private function _isBaseURIValid()
{
$error = preg_match('/^https:\/\//', $this->_baseURI);
return new Error(($error == 0 ? true : false), 'Firebase does not support non-ssl traffic. Please try your request again over https.');
}

/**
* @param $data
* @return Error
*/
private function _isDataValid($data) {
if ($data == "" || $data == null) {
return new Error(true, "Missing data; Perhaps you forgot to send the data.");
}
$error = json_decode($data);
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.");
private function _isDataValid($data)
{
if ($data == "" || $data == null) {
return new Error(true, "Missing data; Perhaps you forgot to send the data.");
}
$error = json_decode($data);
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.");
}

/**
Expand All @@ -153,49 +160,54 @@ private function _isDataValid($data) {
*/
private function _getSetResponse($data)
{
$validBaseUriObject = $this->_isBaseURIValid();
if ($validBaseUriObject->error) {
return $validBaseUriObject->message;
}
$validBaseUriObject = $this->_isBaseURIValid();
if ($validBaseUriObject->error) {
return $validBaseUriObject->message;
}

$validDataObject = $this->_isDataValid($data);
if ($validDataObject->error) {
return $validDataObject->message;
}
$validDataObject = $this->_isDataValid($data);
if ($validDataObject->error) {
return $validDataObject->message;
}

return $this->_response;
return $this->_response;
}

/**
* @return null
*/
private function _getGetResponse()
{
$validBaseUriObject = $this->_isBaseURIValid();
if ($validBaseUriObject->error) {
return $validBaseUriObject->message;
}
return $this->_response;
$validBaseUriObject = $this->_isBaseURIValid();
if ($validBaseUriObject->error) {
return $validBaseUriObject->message;
}
return $this->_response;
}

/**
* @return null
*/
private function _getDeleteResponse() { return $this->_getGetResponse(); }
private function _getDeleteResponse()
{
return $this->_getGetResponse();
}
}

/**
* Class Error
*
* @package Firebase
*/
class Error {
class Error
{
/**
* @param $error
* @param $message
*/
function __construct($error, $message)
{
$this->error = $error;
$this->message = $message;
}
{
$this->error = $error;
$this->message = $message;
}
}

0 comments on commit e80bb3c

Please sign in to comment.