Skip to content

Commit

Permalink
coding standards and simplification of else cases as well as some min…
Browse files Browse the repository at this point in the history
…or fixes
  • Loading branch information
euromark committed Jul 2, 2013
1 parent 58149f2 commit 7cb19b9
Show file tree
Hide file tree
Showing 31 changed files with 142 additions and 169 deletions.
3 changes: 1 addition & 2 deletions lib/Cake/Console/Command/BakeShell.php
Expand Up @@ -123,8 +123,7 @@ public function main() {
$this->Test->execute();
break;
case 'Q':
exit(0);
break;
return $this->_stop();
default:
$this->out(__d('cake_console', 'You have made an invalid selection. Please choose a type of class to Bake by entering D, M, V, F, T, or C.'));
}
Expand Down
23 changes: 11 additions & 12 deletions lib/Cake/Console/Command/ConsoleShell.php
Expand Up @@ -172,7 +172,7 @@ public function main($command = null) {
switch ($command) {
case 'help':
$this->help();
break;
break;
case 'quit':
case 'exit':
return true;
Expand All @@ -182,7 +182,7 @@ public function main($command = null) {
foreach ($this->models as $model) {
$this->out(" - {$model}");
}
break;
break;
case preg_match("/^(\w+) bind (\w+) (\w+)/", $command, $tmp):
foreach ($tmp as $data) {
$data = strip_tags($data);
Expand All @@ -200,7 +200,7 @@ public function main($command = null) {
} else {
$this->out(__d('cake_console', "Please verify you are using valid models and association types"));
}
break;
break;
case preg_match("/^(\w+) unbind (\w+) (\w+)/", $command, $tmp):
foreach ($tmp as $data) {
$data = strip_tags($data);
Expand Down Expand Up @@ -228,7 +228,7 @@ public function main($command = null) {
} else {
$this->out(__d('cake_console', "Please verify you are using valid models, valid current association, and valid association types"));
}
break;
break;
case (strpos($command, "->find") > 0):
// Remove any bad info
$command = strip_tags($command);
Expand Down Expand Up @@ -285,7 +285,7 @@ public function main($command = null) {
$this->out(__d('cake_console', "%s is not a valid model", $modelToCheck));
}

break;
break;
case (strpos($command, '->save') > 0):
// Validate the model we're trying to save here
$command = strip_tags($command);
Expand All @@ -302,7 +302,7 @@ public function main($command = null) {
//@codingStandardsIgnoreEnd
$this->out(__d('cake_console', 'Saved record for %s', $modelToSave));
}
break;
break;
case preg_match("/^(\w+) columns/", $command, $tmp):
$modelToCheck = strip_tags(str_replace($this->badCommandChars, "", $tmp[1]));

Expand All @@ -321,31 +321,30 @@ public function main($command = null) {
} else {
$this->out(__d('cake_console', "Please verify that you selected a valid model"));
}
break;
break;
case preg_match("/^routes\s+reload/i", $command, $tmp):
if (!$this->_loadRoutes()) {
$this->err(__d('cake_console', "There was an error loading the routes config. Please check that the file exists and is free of parse errors."));
break;
}
$this->out(__d('cake_console', "Routes configuration reloaded, %d routes connected", count(Router::$routes)));
break;
break;
case preg_match("/^routes\s+show/i", $command, $tmp):
$this->out(print_r(Hash::combine(Router::$routes, '{n}.template', '{n}.defaults'), true));
break;
break;
case (preg_match("/^route\s+(\(.*\))$/i", $command, $tmp) == true):
//@codingStandardsIgnoreStart
if ($url = eval('return array' . $tmp[1] . ';')) {
//@codingStandardsIgnoreEnd
$this->out(Router::url($url));
}
break;
break;
case preg_match("/^route\s+(.*)/i", $command, $tmp):
$this->out(var_export(Router::parse($tmp[1]), true));
break;
break;
default:
$this->out(__d('cake_console', "Invalid command"));
$this->out();
break;
}
$command = '';
}
Expand Down
9 changes: 4 additions & 5 deletions lib/Cake/Console/Command/I18nShell.php
Expand Up @@ -76,16 +76,15 @@ public function main() {
switch ($choice) {
case 'e':
$this->Extract->execute();
break;
break;
case 'i':
$this->initdb();
break;
break;
case 'h':
$this->out($this->OptionParser->help());
break;
break;
case 'q':
exit(0);
break;
return $this->_stop();
default:
$this->out(__d('cake_console', 'You have made an invalid selection. Please choose a command to execute by entering E, I, H, or Q.'));
}
Expand Down
12 changes: 5 additions & 7 deletions lib/Cake/Console/Command/SchemaShell.php
Expand Up @@ -107,11 +107,10 @@ public function view() {
if ($File->exists()) {
$this->out($File->read());
return $this->_stop();
} else {
$file = $this->Schema->path . DS . $this->params['file'];
$this->err(__d('cake_console', 'Schema file (%s) could not be found.', $file));
return $this->_stop();
}
$file = $this->Schema->path . DS . $this->params['file'];
$this->err(__d('cake_console', 'Schema file (%s) could not be found.', $file));
return $this->_stop();
}

/**
Expand Down Expand Up @@ -185,10 +184,9 @@ public function generate() {
if ($this->Schema->write($content)) {
$this->out(__d('cake_console', 'Schema file: %s generated', $content['file']));
return $this->_stop();
} else {
$this->err(__d('cake_console', 'Schema file: %s generated'));
return $this->_stop();
}
$this->err(__d('cake_console', 'Schema file: %s generated'));
return $this->_stop();
}

/**
Expand Down
16 changes: 8 additions & 8 deletions lib/Cake/Console/Command/Task/FixtureTask.php
Expand Up @@ -304,7 +304,7 @@ protected function _generateRecords($tableInfo, $recordCount = 1) {
case 'integer':
case 'float':
$insert = $i + 1;
break;
break;
case 'string':
case 'binary':
$isPrimaryUuid = (
Expand All @@ -319,22 +319,22 @@ protected function _generateRecords($tableInfo, $recordCount = 1) {
$insert = substr($insert, 0, (int)$fieldInfo['length'] - 2);
}
}
break;
break;
case 'timestamp':
$insert = time();
break;
break;
case 'datetime':
$insert = date('Y-m-d H:i:s');
break;
break;
case 'date':
$insert = date('Y-m-d');
break;
break;
case 'time':
$insert = date('H:i:s');
break;
break;
case 'boolean':
$insert = 1;
break;
break;
case 'text':
$insert = "Lorem ipsum dolor sit amet, aliquet feugiat.";
$insert .= " Convallis morbi fringilla gravida,";
Expand All @@ -343,7 +343,7 @@ protected function _generateRecords($tableInfo, $recordCount = 1) {
$insert .= " vestibulum massa neque ut et, id hendrerit sit,";
$insert .= " feugiat in taciti enim proin nibh, tempor dignissim, rhoncus";
$insert .= " duis vestibulum nunc mattis convallis.";
break;
break;
}
$record[$field] = $insert;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/Cake/Console/Command/Task/PluginTask.php
Expand Up @@ -65,9 +65,8 @@ public function execute() {
$this->out(__d('cake_console', 'Plugin: %s already exists, no action taken', $plugin));
$this->out(__d('cake_console', 'Path: %s', $pluginPath));
return false;
} else {
$this->_interactive($plugin);
}
$this->_interactive($plugin);
} else {
return $this->_interactive();
}
Expand Down
5 changes: 1 addition & 4 deletions lib/Cake/Console/Command/Task/ProjectTask.php
Expand Up @@ -368,12 +368,9 @@ public function cakeAdmin($name) {
if ($File->write($result)) {
Configure::write('Routing.prefixes', array($name));
return true;
} else {
return false;
}
} else {
return false;
}
return false;
}

/**
Expand Down
26 changes: 12 additions & 14 deletions lib/Cake/Controller/Scaffold.php
Expand Up @@ -250,9 +250,8 @@ protected function _scaffoldSave(CakeRequest $request, $action = 'edit') {
$success
);
return $this->_sendMessage($message);
} else {
return $this->controller->afterScaffoldSaveError($action);
}
return $this->controller->afterScaffoldSaveError($action);
} else {
if ($this->_validSession) {
$this->controller->Session->setFlash(__d('cake', 'Please correct errors below.'));
Expand Down Expand Up @@ -309,14 +308,13 @@ protected function _scaffoldDelete(CakeRequest $request) {
if ($this->ScaffoldModel->delete()) {
$message = __d('cake', 'The %1$s with id: %2$s has been deleted.', Inflector::humanize($this->modelClass), $id);
return $this->_sendMessage($message);
} else {
$message = __d('cake',
'There was an error deleting the %1$s with id: %2$s',
Inflector::humanize($this->modelClass),
$id
);
return $this->_sendMessage($message);
}
$message = __d('cake',
'There was an error deleting the %1$s with id: %2$s',
Inflector::humanize($this->modelClass),
$id
);
return $this->_sendMessage($message);
} elseif ($this->controller->scaffoldError('delete') === false) {
return $this->_scaffoldError();
}
Expand Down Expand Up @@ -388,21 +386,21 @@ protected function _scaffold(CakeRequest $request) {
case 'index':
case 'list':
$this->_scaffoldIndex($request);
break;
break;
case 'view':
$this->_scaffoldView($request);
break;
break;
case 'add':
case 'create':
$this->_scaffoldSave($request, 'add');
break;
break;
case 'edit':
case 'update':
$this->_scaffoldSave($request, 'edit');
break;
break;
case 'delete':
$this->_scaffoldDelete($request);
break;
break;
}
} else {
throw new MissingActionException(array(
Expand Down
23 changes: 11 additions & 12 deletions lib/Cake/Error/ErrorHandler.php
Expand Up @@ -198,14 +198,13 @@ public static function handleError($code, $description, $file = null, $line = nu
'path' => Debugger::trimPath($file)
);
return Debugger::getInstance()->outputError($data);
} else {
$message = $error . ' (' . $code . '): ' . $description . ' in [' . $file . ', line ' . $line . ']';
if (!empty($errorConfig['trace'])) {
$trace = Debugger::trace(array('start' => 1, 'format' => 'log'));
$message .= "\nTrace:\n" . $trace . "\n";
}
return CakeLog::write($log, $message);
}
$message = $error . ' (' . $code . '): ' . $description . ' in [' . $file . ', line ' . $line . ']';
if (!empty($errorConfig['trace'])) {
$trace = Debugger::trace(array('start' => 1, 'format' => 'log'));
$message .= "\nTrace:\n" . $trace . "\n";
}
return CakeLog::write($log, $message);
}

/**
Expand Down Expand Up @@ -254,28 +253,28 @@ public static function mapErrorCode($code) {
case E_USER_ERROR:
$error = 'Fatal Error';
$log = LOG_ERR;
break;
break;
case E_WARNING:
case E_USER_WARNING:
case E_COMPILE_WARNING:
case E_RECOVERABLE_ERROR:
$error = 'Warning';
$log = LOG_WARNING;
break;
break;
case E_NOTICE:
case E_USER_NOTICE:
$error = 'Notice';
$log = LOG_NOTICE;
break;
break;
case E_STRICT:
$error = 'Strict';
$log = LOG_NOTICE;
break;
break;
case E_DEPRECATED:
case E_USER_DEPRECATED:
$error = 'Deprecated';
$log = LOG_NOTICE;
break;
break;
}
return array($error, $log);
}
Expand Down
19 changes: 9 additions & 10 deletions lib/Cake/Model/Behavior/TreeBehavior.php
Expand Up @@ -762,17 +762,16 @@ public function removeFromTree(Model $Model, $id = null, $delete = false) {
array($Model->escapeField() => $id)
);
return $Model->delete($id);
} else {
$edge = $this->_getMax($Model, $scope, $right, $recursive);
if ($node[$right] == $edge) {
$edge = $edge - 2;
}
$Model->id = $id;
return $Model->save(
array($left => $edge + 1, $right => $edge + 2, $parent => null),
array('callbacks' => false, 'validate' => false)
);
}
$edge = $this->_getMax($Model, $scope, $right, $recursive);
if ($node[$right] == $edge) {
$edge = $edge - 2;
}
$Model->id = $id;
return $Model->save(
array($left => $edge + 1, $right => $edge + 2, $parent => null),
array('callbacks' => false, 'validate' => false)
);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Model/Datasource/DataSource.php
Expand Up @@ -357,7 +357,7 @@ public function insertQueryData($query, $data, $association, $assocData, Model $
}
}
$type = $model->getColumnType($model->primaryKey);
break;
break;
case '{$__cakeForeignKey__$}':
foreach ($model->associations() as $name) {
foreach ($model->$name as $assocName => $assoc) {
Expand Down Expand Up @@ -389,7 +389,7 @@ public function insertQueryData($query, $data, $association, $assocData, Model $
}
}
}
break;
break;
}
if (empty($val) && $val !== '0') {
return false;
Expand Down

0 comments on commit 7cb19b9

Please sign in to comment.