Skip to content

Commit

Permalink
Clear code second step (#1121)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenExe authored and ruflin committed Jun 22, 2016
1 parent 3e042da commit 6a6f796
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 90 deletions.
36 changes: 11 additions & 25 deletions lib/Elastica/Bulk/ResponseSet.php
Expand Up @@ -41,16 +41,13 @@ public function getBulkResponses()
*/
public function getError()
{
$error = '';

foreach ($this->getBulkResponses() as $bulkResponse) {
if ($bulkResponse->hasError()) {
$error = $bulkResponse->getError();
break;
return $bulkResponse->getError();
}
}

return $error;
return '';
}

/**
Expand All @@ -60,62 +57,51 @@ public function getError()
*/
public function getFullError()
{
$error = '';

foreach ($this->getBulkResponses() as $bulkResponse) {
if ($bulkResponse->hasError()) {
$error = $bulkResponse->getFullError();
break;
return $bulkResponse->getFullError();
}
}

return $error;
return '';
}

/**
* @return bool
*/
public function isOk()
{
$return = true;

foreach ($this->getBulkResponses() as $bulkResponse) {
if (!$bulkResponse->isOk()) {
$return = false;
break;
return false;
}
}

return $return;
return true;
}

/**
* @return bool
*/
public function hasError()
{
$return = false;

foreach ($this->getBulkResponses() as $bulkResponse) {
if ($bulkResponse->hasError()) {
$return = true;
break;
return true;
}
}

return $return;
return false;
}

/**
* @return bool|\Elastica\Bulk\Response
*/
public function current()
{
if ($this->valid()) {
return $this->_bulkResponses[$this->key()];
} else {
return false;
}
return $this->valid()
? $this->_bulkResponses[$this->key()]
: false;
}

/**
Expand Down
12 changes: 5 additions & 7 deletions lib/Elastica/Connection.php
Expand Up @@ -330,17 +330,15 @@ public function getConfig($key = '')
*/
public static function create($params = array())
{
$connection = null;
if (is_array($params)) {
return new self($params);
}

if ($params instanceof self) {
$connection = $params;
} elseif (is_array($params)) {
$connection = new self($params);
} else {
throw new InvalidException('Invalid data type');
return $params;
}

return $connection;
throw new InvalidException('Invalid data type');
}

/**
Expand Down
8 changes: 5 additions & 3 deletions lib/Elastica/Document.php
Expand Up @@ -350,10 +350,12 @@ public static function create($data)
{
if ($data instanceof self) {
return $data;
} elseif (is_array($data)) {
}

if (is_array($data)) {
return new self('', $data);
} else {
throw new InvalidException('Failed to create document. Invalid data passed.');
}

throw new InvalidException('Failed to create document. Invalid data passed.');
}
}
26 changes: 8 additions & 18 deletions lib/Elastica/Exception/Connection/HttpException.php
Expand Up @@ -46,32 +46,22 @@ public function getErrorMessage($error)
{
switch ($error) {
case CURLE_UNSUPPORTED_PROTOCOL:
$error = 'Unsupported protocol';
break;
return 'Unsupported protocol';
case CURLE_FAILED_INIT:
$error = 'Internal cUrl error?';
break;
return 'Internal cUrl error?';
case CURLE_URL_MALFORMAT:
$error = 'Malformed URL';
break;
return 'Malformed URL';
case CURLE_COULDNT_RESOLVE_PROXY:
$error = "Couldn't resolve proxy";
break;
return "Couldn't resolve proxy";
case CURLE_COULDNT_RESOLVE_HOST:
$error = "Couldn't resolve host";
break;
return "Couldn't resolve host";
case CURLE_COULDNT_CONNECT:
$error = "Couldn't connect to host, Elasticsearch down?";
break;
return "Couldn't connect to host, Elasticsearch down?";
case 28:
$error = 'Operation timed out';
break;
default:
$error = 'Unknown error:'.$error;
break;
return 'Operation timed out';
}

return $error;
return 'Unknown error:' . $error;
}

/**
Expand Down
4 changes: 0 additions & 4 deletions lib/Elastica/Param.php
Expand Up @@ -137,10 +137,6 @@ public function setParams(array $params)
public function addParam($key, $value)
{
if ($key != null) {
if (!isset($this->_params[$key])) {
$this->_params[$key] = array();
}

$this->_params[$key][] = $value;
} else {
$this->_params = $value;
Expand Down
18 changes: 6 additions & 12 deletions lib/Elastica/QueryBuilder/Version.php
Expand Up @@ -48,23 +48,17 @@ public function supports($name, $type)
{
switch ($type) {
case DSL::TYPE_QUERY:
$supports = in_array($name, $this->queries);
break;
return in_array($name, $this->queries);
case DSL::TYPE_FILTER:
$supports = in_array($name, $this->filters);
break;
return in_array($name, $this->filters);
case DSL::TYPE_AGGREGATION:
$supports = in_array($name, $this->aggregations);
break;
return in_array($name, $this->aggregations);
case DSL::TYPE_SUGGEST:
$supports = in_array($name, $this->suggesters);
break;
default:
// disables version check in Facade for custom DSL objects
$supports = true;
return in_array($name, $this->suggesters);
}

return $supports;
// disables version check in Facade for custom DSL objects
return true;
}

/**
Expand Down
18 changes: 10 additions & 8 deletions lib/Elastica/Script/Script.php
Expand Up @@ -95,16 +95,18 @@ public function getScript()
public static function create($data)
{
if ($data instanceof self) {
$script = $data;
} elseif (is_array($data)) {
$script = self::_createFromArray($data);
} elseif (is_string($data)) {
$script = new self($data);
} else {
throw new InvalidException('Failed to create script. Invalid data passed.');
return $data;
}

return $script;
if (is_array($data)) {
return self::_createFromArray($data);
}

if (is_string($data)) {
return new self($data);
}

throw new InvalidException('Failed to create script. Invalid data passed.');
}

/**
Expand Down
18 changes: 10 additions & 8 deletions lib/Elastica/Script/ScriptFile.php
Expand Up @@ -60,16 +60,18 @@ public function getScriptFile()
public static function create($data)
{
if ($data instanceof self) {
$scriptFile = $data;
} elseif (is_array($data)) {
$scriptFile = self::_createFromArray($data);
} elseif (is_string($data)) {
$scriptFile = new self($data);
} else {
throw new InvalidException('Failed to create scriptFile. Invalid data passed.');
return $data;
}

return $scriptFile;
if (is_array($data)) {
return self::_createFromArray($data);
}

if (is_string($data)) {
return new self($data);
}

throw new InvalidException('Failed to create scriptFile. Invalid data passed.');
}

/**
Expand Down
9 changes: 4 additions & 5 deletions lib/Elastica/Type/Mapping.php
Expand Up @@ -286,14 +286,13 @@ public static function create($mapping)
if (is_array($mapping)) {
$mappingObject = new self();
$mappingObject->setProperties($mapping);
} else {
$mappingObject = $mapping;
return $mappingObject;
}

if (!$mappingObject instanceof self) {
throw new InvalidException('Invalid object type');
if ($mapping instanceof self) {
return $mapping;
}

return $mappingObject;
throw new InvalidException('Invalid object type');
}
}

0 comments on commit 6a6f796

Please sign in to comment.