From ee3152272e7c7924c31360af062f90a90d5af06f Mon Sep 17 00:00:00 2001 From: Ivan Brezhnev Date: Sat, 20 Feb 2016 17:44:06 +0200 Subject: [PATCH] Reformat. PSR-2 --- src/Body.php | 21 +++++++++------------ src/MyAjaxResponse.php | 17 ++++++++--------- src/Response.php | 20 +++++++++++++++++--- 3 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/Body.php b/src/Body.php index 71ea4b2..4da20e7 100644 --- a/src/Body.php +++ b/src/Body.php @@ -25,8 +25,8 @@ class Body implements Arrayable, Jsonable * ReponseData constructor. * * @param string $message - * @param bool $success - * @param array $data + * @param bool $success + * @param array $data */ public function __construct($message = '', $success = true, array $data = []) { @@ -85,18 +85,15 @@ public function message($message) * Set response data * * @param array $data - * @param bool $merge + * @param bool $merge * * @return self */ - public function data($data, $merge = false) + public function data(array $data, $merge = false) { - if ($merge) - { + if ($merge) { $this->data = array_merge($this->data, $data); - } - else - { + } else { $this->data += $data; } @@ -112,15 +109,15 @@ public function toArray() { return [ 'success' => $this->success, - 'error' => ! $this->success, - 'message' => $this->message + 'error' => !$this->success, + 'message' => $this->message, ] + $this->data; } /** * Convert the object to its JSON representation * - * @param int $options + * @param int $options * * @return string */ diff --git a/src/MyAjaxResponse.php b/src/MyAjaxResponse.php index 3479c82..89f7a23 100644 --- a/src/MyAjaxResponse.php +++ b/src/MyAjaxResponse.php @@ -18,20 +18,19 @@ class MyAjaxResponse extends AjaxResponse * ['id' => 11, 'title' => 'Еще одна важная задача'] * ); * - * @param $name - * @param $arguments + * @param string $name + * @param array $arguments * * @return $this */ - function __call($name, $arguments) + public function __call($name, $arguments) { - if (count($arguments) == 1) - { + if (count($arguments) == 1) { $this->body[$name] = $arguments[0]; - } - else if (count($arguments) > 1) - { - $this->body[$name] = $arguments; + } else { + if (count($arguments) > 1) { + $this->body[$name] = $arguments; + } } return $this; diff --git a/src/Response.php b/src/Response.php index 9fff231..3f16c68 100644 --- a/src/Response.php +++ b/src/Response.php @@ -18,8 +18,14 @@ */ class Response extends JsonResponse { + /** + * @var Body + */ protected $body; + /** + * Response constructor. + */ public function __construct() { $this->body = new Body(); @@ -27,6 +33,9 @@ public function __construct() parent::__construct(); } + /** + * @return mixed + */ public function send() { $this->setData($this->body); @@ -34,10 +43,15 @@ public function send() return parent::send(); } - function __call($name, $arguments) + /** + * @param string $name + * @param array $arguments + * + * @return $this + */ + public function __call($name, $arguments) { - if (method_exists($this->body, $name)) - { + if (method_exists($this->body, $name)) { call_user_func_array([$this->body, $name], $arguments); return $this;