Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

Commit

Permalink
Corrections suggested by Scrutinizer
Browse files Browse the repository at this point in the history
  • Loading branch information
ker0x committed Dec 1, 2015
1 parent e340072 commit 07b67b2
Showing 1 changed file with 14 additions and 37 deletions.
51 changes: 14 additions & 37 deletions src/Controller/Component/GcmComponent.php
Expand Up @@ -15,7 +15,6 @@

use Cake\Controller\Component;
use Cake\Controller\ComponentRegistry;
use Cake\Core\Exception\Exception;
use Cake\Network\Http\Client;
use Cake\Utility\Hash;

Expand Down Expand Up @@ -60,25 +59,13 @@ class GcmComponent extends Component
*/
protected $_response = null;

/**
* Controller reference
*/
protected $Controller = null;

/**
* A Component collection, used to get more components.
*
* @var ComponentCollection
*/
protected $Collection;

/**
* Constructor
*
* @param ComponentRegistry $collection A ComponentRegistry
* @param array $config Array of configuration settings
*/
public function __construct(ComponentRegistry $collection, array $config = [])
public function __construct(ComponentRegistry $registry, array $config = [])
{
$this->_errorMessages = [
'400' => __('Error 400. The request could not be parsed as JSON.'),
Expand All @@ -88,23 +75,13 @@ public function __construct(ComponentRegistry $collection, array $config = [])
];
}

/**
* Called before the Controller::beforeFilter().
*
* @param Controller $controller Controller with components to initialize
* @return void
*/
public function initialize(Controller $controller) {
$this->Controller = $controller;
}

/**
* send method
*
* @param string|array $ids
* @param array $data
* @param array $payload
* @param array $parameters
* @return void
* @return boolean
*/
public function send($ids = false, array $payload = [], array $parameters = [])
{
Expand Down Expand Up @@ -143,12 +120,12 @@ public function send($ids = false, array $payload = [], array $parameters = [])
throw new \ErrorException(__('Unable to check parameters.'));
}

$notification = $this->_buildMessage($ids, $payload, $parameters);
if ($notification === false) {
throw new \ErrorException(__('Unable to build the notification.'));
$message = $this->_buildMessage($ids, $payload, $parameters);
if ($message === false) {
throw new \ErrorException(__('Unable to build the message.'));
}

return $this->_executePush($notification);
return $this->_executePush($message);
}

/**
Expand Down Expand Up @@ -194,12 +171,12 @@ public function response()
/**
* _executePush method
*
* @param json $notification
* @return bool
* @param json $message
* @return boolean
*/
protected function _executePush($notification = false)
protected function _executePush($message = false)
{
if ($notification === false) {
if ($message === false) {
return false;
}

Expand All @@ -208,7 +185,7 @@ protected function _executePush($notification = false)
}

$http = new Client();
$this->_response = $http->post($this->_config['api']['url'], $notification, [
$this->_response = $http->post($this->_config['api']['url'], $message, [
'type' => 'json',
'header' => [
'Authorization' => 'key=' . $this->config['api']['key'],
Expand All @@ -224,10 +201,10 @@ protected function _executePush($notification = false)
}

/**
* _buildNotification method
* _buildMessage method
*
* @param array $ids
* @param array $data
* @param array $payload
* @param array $parameters
* @return json
*/
Expand Down

0 comments on commit 07b67b2

Please sign in to comment.