Skip to content

Commit

Permalink
simplify else cases
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark committed Jul 2, 2013
1 parent 7cb19b9 commit a90cb29
Show file tree
Hide file tree
Showing 17 changed files with 105 additions and 130 deletions.
46 changes: 22 additions & 24 deletions lib/Cake/Model/Datasource/Database/Mysql.php
Expand Up @@ -195,17 +195,16 @@ public function listSources($data = null) {
if (!$result) {
$result->closeCursor();
return array();
} else {
$tables = array();

while ($line = $result->fetch(PDO::FETCH_NUM)) {
$tables[] = $line[0];
}
}
$tables = array();

$result->closeCursor();
parent::listSources($tables);
return $tables;
while ($line = $result->fetch(PDO::FETCH_NUM)) {
$tables[] = $line[0];
}

$result->closeCursor();
parent::listSources($tables);
return $tables;
}

/**
Expand Down Expand Up @@ -679,24 +678,23 @@ public function listDetailedSources($name = null) {
if (!$result) {
$result->closeCursor();
return array();
} else {
$tables = array();
foreach ($result as $row) {
$tables[$row['Name']] = (array)$row;
unset($tables[$row['Name']]['queryString']);
if (!empty($row['Collation'])) {
$charset = $this->getCharsetName($row['Collation']);
if ($charset) {
$tables[$row['Name']]['charset'] = $charset;
}
}
$tables = array();
foreach ($result as $row) {
$tables[$row['Name']] = (array)$row;
unset($tables[$row['Name']]['queryString']);
if (!empty($row['Collation'])) {
$charset = $this->getCharsetName($row['Collation']);
if ($charset) {
$tables[$row['Name']]['charset'] = $charset;
}
}
$result->closeCursor();
if (is_string($name) && isset($tables[$name])) {
return $tables[$name];
}
return $tables;
}
$result->closeCursor();
if (is_string($name) && isset($tables[$name])) {
return $tables[$name];
}
return $tables;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions lib/Cake/Model/Datasource/Database/Postgres.php
Expand Up @@ -300,9 +300,8 @@ public function getSequence($table, $field = 'id') {
}
if (isset($this->_sequenceMap[$table][$field])) {
return $this->_sequenceMap[$table][$field];
} else {
return "{$table}_{$field}_seq";
}
return "{$table}_{$field}_seq";
}

/**
Expand Down
5 changes: 2 additions & 3 deletions lib/Cake/Model/Datasource/Database/Sqlite.php
Expand Up @@ -362,10 +362,9 @@ public function fetchResult() {
}
}
return $resultRow;
} else {
$this->_result->closeCursor();
return false;
}
$this->_result->closeCursor();
return false;
}

/**
Expand Down
23 changes: 10 additions & 13 deletions lib/Cake/Model/Datasource/Database/Sqlserver.php
Expand Up @@ -167,17 +167,16 @@ public function listSources($data = null) {
if (!$result) {
$result->closeCursor();
return array();
} else {
$tables = array();

while ($line = $result->fetch(PDO::FETCH_NUM)) {
$tables[] = $line[0];
}
}
$tables = array();

$result->closeCursor();
parent::listSources($tables);
return $tables;
while ($line = $result->fetch(PDO::FETCH_NUM)) {
$tables[] = $line[0];
}

$result->closeCursor();
parent::listSources($tables);
return $tables;
}

/**
Expand Down Expand Up @@ -313,9 +312,8 @@ public function fields(Model $model, $alias = null, $fields = array(), $quote =
$result[] = $prepend . $fields[$i];
}
return $result;
} else {
return $fields;
}
return $fields;
}

/**
Expand Down Expand Up @@ -534,9 +532,8 @@ public function renderStatement($type, $data) {
";
} elseif (strpos($limit, 'FETCH') !== false) {
return "SELECT {$fields} FROM {$table} {$alias} {$joins} {$conditions} {$group} {$order} {$limit}";
} else {
return "SELECT {$limit} {$fields} FROM {$table} {$alias} {$joins} {$conditions} {$group} {$order}";
}
return "SELECT {$limit} {$fields} FROM {$table} {$alias} {$joins} {$conditions} {$group} {$order}";
case "schema":
extract($data);

Expand Down
35 changes: 16 additions & 19 deletions lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -592,25 +592,23 @@ public function query() {
$recursive = $params[5 + $off];
}
return $args[2]->find('all', compact('conditions', 'fields', 'order', 'limit', 'page', 'recursive'));
} else {
if (isset($params[3 + $off])) {
$recursive = $params[3 + $off];
}
return $args[2]->find('first', compact('conditions', 'fields', 'order', 'recursive'));
}
} else {
if (isset($args[1]) && $args[1] === true) {
return $this->fetchAll($args[0], true);
} elseif (isset($args[1]) && !is_array($args[1])) {
return $this->fetchAll($args[0], false);
} elseif (isset($args[1]) && is_array($args[1])) {
if (isset($args[2])) {
$cache = $args[2];
} else {
$cache = true;
}
return $this->fetchAll($args[0], $args[1], array('cache' => $cache));
if (isset($params[3 + $off])) {
$recursive = $params[3 + $off];
}
return $args[2]->find('first', compact('conditions', 'fields', 'order', 'recursive'));
}
if (isset($args[1]) && $args[1] === true) {
return $this->fetchAll($args[0], true);
} elseif (isset($args[1]) && !is_array($args[1])) {
return $this->fetchAll($args[0], false);
} elseif (isset($args[1]) && is_array($args[1])) {
if (isset($args[2])) {
$cache = $args[2];
} else {
$cache = true;
}
return $this->fetchAll($args[0], $args[1], array('cache' => $cache));
}
}

Expand All @@ -632,9 +630,8 @@ public function fetchRow($sql = null) {
$this->fetchVirtualField($resultRow);
}
return $resultRow;
} else {
return null;
}
return null;
}

/**
Expand Down
43 changes: 21 additions & 22 deletions lib/Cake/Model/Permission.php
Expand Up @@ -123,33 +123,32 @@ public function check($aro, $aco, $action = "*") {

if (empty($perms)) {
continue;
} else {
$perms = Hash::extract($perms, '{n}.' . $this->alias);
foreach ($perms as $perm) {
if ($action === '*') {
}
$perms = Hash::extract($perms, '{n}.' . $this->alias);
foreach ($perms as $perm) {
if ($action === '*') {

foreach ($permKeys as $key) {
if (!empty($perm)) {
if ($perm[$key] == -1) {
return false;
} elseif ($perm[$key] == 1) {
$inherited[$key] = 1;
}
foreach ($permKeys as $key) {
if (!empty($perm)) {
if ($perm[$key] == -1) {
return false;
} elseif ($perm[$key] == 1) {
$inherited[$key] = 1;
}
}
}

if (count($inherited) === count($permKeys)) {
if (count($inherited) === count($permKeys)) {
return true;
}
} else {
switch ($perm['_' . $action]) {
case -1:
return false;
case 0:
continue;
case 1:
return true;
}
} else {
switch ($perm['_' . $action]) {
case -1:
return false;
case 0:
continue;
case 1:
return true;
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions lib/Cake/Model/Validator/CakeValidationRule.php
Expand Up @@ -148,9 +148,8 @@ public function isRequired() {
if (in_array($this->required, array('create', 'update'), true)) {
if ($this->required === 'create' && !$this->isUpdate() || $this->required === 'update' && $this->isUpdate()) {
return true;
} else {
return false;
}
return false;
}

return $this->required;
Expand Down
7 changes: 3 additions & 4 deletions lib/Cake/Network/CakeSocket.php
Expand Up @@ -382,11 +382,10 @@ public function enableCrypto($type, $clientOrServer = 'client', $enable = true)
if ($enableCryptoResult === true) {
$this->encrypted = $enable;
return true;
} else {
$errorMessage = __d('cake_dev', 'Unable to perform enableCrypto operation on CakeSocket');
$this->setLastError(null, $errorMessage);
throw new SocketException($errorMessage);
}
$errorMessage = __d('cake_dev', 'Unable to perform enableCrypto operation on CakeSocket');
$this->setLastError(null, $errorMessage);
throw new SocketException($errorMessage);
}

}
3 changes: 1 addition & 2 deletions lib/Cake/Network/Email/CakeEmail.php
Expand Up @@ -1617,9 +1617,8 @@ protected function _getContentTypeCharset() {
$charset = strtoupper($this->charset);
if (array_key_exists($charset, $this->_contentTypeCharset)) {
return strtoupper($this->_contentTypeCharset[$charset]);
} else {
return strtoupper($this->charset);
}
return strtoupper($this->charset);
}

}
3 changes: 1 addition & 2 deletions lib/Cake/Test/Case/Model/Behavior/AclBehaviorTest.php
Expand Up @@ -87,9 +87,8 @@ public function parentNode() {
}
if (!$motherId) {
return null;
} else {
return array('AclPerson' => array('id' => $motherId));
}
return array('AclPerson' => array('id' => $motherId));
}

}
Expand Down
9 changes: 4 additions & 5 deletions lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php
Expand Up @@ -3672,11 +3672,10 @@ protected function _containments($Model, $contain = array()) {
if (!is_array($Model)) {
$result = $Model->containments($contain);
return $this->_containments($result['models']);
} else {
$result = $Model;
foreach ($result as $i => $containment) {
$result[$i] = array_diff_key($containment, array('instance' => true));
}
}
$result = $Model;
foreach ($result as $i => $containment) {
$result[$i] = array_diff_key($containment, array('instance' => true));
}
return $result;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/Cake/TestSuite/CakeTestSuiteCommand.php
Expand Up @@ -122,9 +122,8 @@ public function run(array $argv, $exit = true) {
exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
} elseif (!isset($result) || $result->errorCount() > 0) {
exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
} else {
exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
}
exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
}
}

Expand Down
10 changes: 4 additions & 6 deletions lib/Cake/Utility/Folder.php
Expand Up @@ -516,11 +516,10 @@ public function create($pathname, $mode = false) {
umask($old);
$this->_messages[] = __d('cake_dev', '%s created', $pathname);
return true;
} else {
umask($old);
$this->_errors[] = __d('cake_dev', '%s NOT created', $pathname);
return false;
}
umask($old);
$this->_errors[] = __d('cake_dev', '%s NOT created', $pathname);
return false;
}
}
return false;
Expand Down Expand Up @@ -810,9 +809,8 @@ public function realpath($path) {
if (!empty($newparts)) {
array_pop($newparts);
continue;
} else {
return false;
}
return false;
}
$newparts[] = $part;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/Cake/Utility/Validation.php
Expand Up @@ -816,9 +816,8 @@ protected static function _pass($method, $check, $classPrefix) {
protected static function _check($check, $regex) {
if (is_string($regex) && preg_match($regex, $check)) {
return true;
} else {
return false;
}
return false;
}

/**
Expand Down
11 changes: 4 additions & 7 deletions lib/Cake/View/Helper/FormHelper.php
Expand Up @@ -205,9 +205,8 @@ protected function _introspectModel($model, $key, $field = null) {
return $this->fieldset[$model]['fields'];
} elseif (isset($this->fieldset[$model]['fields'][$field])) {
return $this->fieldset[$model]['fields'][$field];
} else {
return isset($object->hasAndBelongsToMany[$field]) ? array('type' => 'multiple') : null;
}
return isset($object->hasAndBelongsToMany[$field]) ? array('type' => 'multiple') : null;
}

if ($key === 'errors' && !isset($this->validationErrors[$model])) {
Expand All @@ -232,10 +231,9 @@ protected function _introspectModel($model, $key, $field = null) {
if ($key === 'validates') {
if (empty($field)) {
return $this->fieldset[$model]['validates'];
} else {
return isset($this->fieldset[$model]['validates'][$field]) ?
$this->fieldset[$model]['validates'] : null;
}
return isset($this->fieldset[$model]['validates'][$field]) ?
$this->fieldset[$model]['validates'] : null;
}
}

Expand Down Expand Up @@ -2572,9 +2570,8 @@ protected function _name($options = array(), $field = null, $key = 'name') {
if (is_array($options)) {
$options[$key] = $name;
return $options;
} else {
return $name;
}
return $name;
}
return parent::_name($options, $field, $key);
}
Expand Down

0 comments on commit a90cb29

Please sign in to comment.