Skip to content
Permalink
Browse files

Fix most of the coding standards issues in Console/

  • Loading branch information...
markstory committed Mar 3, 2012
1 parent 2a7bee0 commit db8c6b5c788893de6704907228e3714c5baf3ffd
Showing with 146 additions and 158 deletions.
  1. +9 −6 lib/Cake/Console/Command/AclShell.php
  2. +11 −10 lib/Cake/Console/Command/ApiShell.php
  3. +3 −3 lib/Cake/Console/Command/BakeShell.php
  4. +2 −5 lib/Cake/Console/Command/CommandListShell.php
  5. +2 −5 lib/Cake/Console/Command/ConsoleShell.php
  6. +1 −0 lib/Cake/Console/Command/I18nShell.php
  7. +5 −4 lib/Cake/Console/Command/SchemaShell.php
  8. +4 −49 lib/Cake/Console/Command/Task/ControllerTask.php
  9. +2 −1 lib/Cake/Console/Command/Task/DbConfigTask.php
  10. +6 −3 lib/Cake/Console/Command/Task/ExtractTask.php
  11. +2 −2 lib/Cake/Console/Command/Task/FixtureTask.php
  12. +20 −10 lib/Cake/Console/Command/Task/ModelTask.php
  13. +2 −3 lib/Cake/Console/Command/Task/PluginTask.php
  14. +4 −5 lib/Cake/Console/Command/Task/ProjectTask.php
  15. +3 −2 lib/Cake/Console/Command/Task/TemplateTask.php
  16. +7 −5 lib/Cake/Console/Command/Task/TestTask.php
  17. +3 −2 lib/Cake/Console/Command/Task/ViewTask.php
  18. +3 −3 lib/Cake/Console/Command/TestShell.php
  19. +1 −0 lib/Cake/Console/Command/TestsuiteShell.php
  20. +7 −6 lib/Cake/Console/Command/UpgradeShell.php
  21. +3 −1 lib/Cake/Console/ConsoleInput.php
  22. +3 −1 lib/Cake/Console/ConsoleInputArgument.php
  23. +3 −1 lib/Cake/Console/ConsoleInputOption.php
  24. +1 −0 lib/Cake/Console/ConsoleInputSubcommand.php
  25. +1 −1 lib/Cake/Console/ConsoleOptionParser.php
  26. +1 −0 lib/Cake/Console/ConsoleOutput.php
  27. +2 −0 lib/Cake/Console/HelpFormatter.php
  28. +2 −1 lib/Cake/Console/Shell.php
  29. +1 −0 lib/Cake/Console/ShellDispatcher.php
  30. +1 −0 lib/Cake/Console/TaskCollection.php
  31. +11 −11 lib/Cake/Console/Templates/skel/Config/Schema/db_acl.php
  32. +8 −8 lib/Cake/Console/Templates/skel/Config/Schema/i18n.php
  33. +5 −5 lib/Cake/Console/Templates/skel/Config/Schema/sessions.php
  34. +1 −1 lib/Cake/Console/Templates/skel/Console/cake.php
  35. +5 −3 lib/Cake/Console/Templates/skel/Controller/PagesController.php
  36. +1 −1 lib/Cake/Console/cake.php
@@ -200,7 +200,7 @@ public function getPath() {
}
$this->out(__d('cake_console', 'Path:'));
$this->hr();
for ($i = 0; $i < count($nodes); $i++) {
for ($i = 0, $len = count($nodes); $i < $len; $i++) {
$this->_outputNode($class, $nodes[$i], $i);
}
}
@@ -218,7 +218,7 @@ protected function _outputNode($class, $node, $indent) {
$data = $node[$class];
if ($data['alias']) {
$this->out($indent . "[" . $data['id'] . "] " . $data['alias']);
} else {
} else {
$this->out($indent . "[" . $data['id'] . "] " . $data['model'] . '.' . $data['foreign_key']);
}
}
@@ -366,8 +366,9 @@ public function getOptionParser() {
'help' => __d('cake_console', 'Type of node to create.')
);
$parser->description(__d('cake_console', 'A console tool for managing the DbAcl'))
->addSubcommand('create', array(
$parser->description(
__d('cake_console', 'A console tool for managing the DbAcl')
)->addSubcommand('create', array(
'help' => __d('cake_console', 'Create a new ACL node'),
'parser' => array(
'description' => __d('cake_console', 'Creates a new ACL object <node> under the parent'),
@@ -514,8 +515,9 @@ public function nodeExists() {
if (!isset($this->args[0]) || !isset($this->args[1])) {
return false;
}
extract($this->_dataVars($this->args[0]));
$key = is_numeric($this->args[1]) ? $secondary_id : 'alias';
$dataVars = $this->_dataVars($this->args[0]);
extract($dataVars);
$key = is_numeric($this->args[1]) ? $dataVars['secondary_id'] : 'alias';
$conditions = array($class . '.' . $key => $this->args[1]);
$possibility = $this->Acl->{$class}->find('all', compact('conditions'));
if (empty($possibility)) {
@@ -602,4 +604,5 @@ protected function _dataVars($type = null) {
$vars['class'] = $class;
return $vars;
}
}
@@ -92,7 +92,7 @@ public function main() {
$this->error(__d('cake_console', '%s not found', $class));
}
$parsed = $this->_parseClass($path . $class .'.php', $class);
$parsed = $this->_parseClass($path . $class . '.php', $class);
if (!empty($parsed)) {
if (isset($this->params['method'])) {
@@ -166,14 +166,14 @@ public function help() {
$commands = array(
'path' => "\t<type>\n" .
"\t\tEither a full path or type of class (model, behavior, controller, component, view, helper).\n".
"\t\tAvailable values:\n\n".
"\t\tbehavior\tLook for class in CakePHP behavior path\n".
"\t\tcache\tLook for class in CakePHP cache path\n".
"\t\tcontroller\tLook for class in CakePHP controller path\n".
"\t\tcomponent\tLook for class in CakePHP component path\n".
"\t\thelper\tLook for class in CakePHP helper path\n".
"\t\tmodel\tLook for class in CakePHP model path\n".
"\t\tEither a full path or type of class (model, behavior, controller, component, view, helper).\n" .
"\t\tAvailable values:\n\n" .
"\t\tbehavior\tLook for class in CakePHP behavior path\n" .
"\t\tcache\tLook for class in CakePHP cache path\n" .
"\t\tcontroller\tLook for class in CakePHP controller path\n" .
"\t\tcomponent\tLook for class in CakePHP component path\n" .
"\t\thelper\tLook for class in CakePHP helper path\n" .
"\t\tmodel\tLook for class in CakePHP model path\n" .
"\t\tview\tLook for class in CakePHP view path\n",
'className' => "\t<className>\n" .
"\t\tA CakePHP core class name (e.g: Component, HtmlHelper).\n"
@@ -203,7 +203,7 @@ protected function _parseClass($path, $class) {
$parsed = array();
if (!class_exists($class)) {
if (!include_once($path)) {
if (!include_once $path) {
$this->err(__d('cake_console', '%s could not be found', $path));
}
}
@@ -234,4 +234,5 @@ protected function _parseClass($path, $class) {
ksort($parsed);
return $parsed;
}
}
@@ -209,9 +209,9 @@ public function all() {
public function getOptionParser() {
$parser = parent::getOptionParser();
return $parser->description(__d('cake_console',
'The Bake script generates controllers, views and models for your application.'
. ' If run with no command line arguments, Bake guides the user through the class creation process.'
. ' You can customize the generation process by telling Bake where different parts of your application are using command line arguments.'
'The Bake script generates controllers, views and models for your application.' .
' If run with no command line arguments, Bake guides the user through the class creation process.' .
' You can customize the generation process by telling Bake where different parts of your application are using command line arguments.'
))->addSubcommand('all', array(
'help' => __d('cake_console', 'Bake a complete MVC. optional <name> of a Model'),
))->addSubcommand('project', array(
@@ -1,9 +1,5 @@
<?php
/**
* Command list Shell
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
@@ -46,7 +42,7 @@ public function startup() {
public function main() {
if (empty($this->params['xml'])) {
$this->out(__d('cake_console', "<info>Current Paths:</info>"), 2);
$this->out(" -app: ". APP_DIR);
$this->out(" -app: " . APP_DIR);
$this->out(" -working: " . rtrim(APP, DS));
$this->out(" -root: " . rtrim(ROOT, DS));
$this->out(" -core: " . rtrim(CORE_PATH, DS));
@@ -234,4 +230,5 @@ public function getOptionParser() {
'boolean' => true
));
}
}
@@ -1,9 +1,5 @@
<?php
/**
* CakePHP Console Shell
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
@@ -343,7 +339,7 @@ protected function _loadRoutes() {
Router::reload();
extract(Router::getNamedExpressions());
if (!@include(APP . 'Config' . DS . 'routes.php')) {
if (!@include APP . 'Config' . DS . 'routes.php') {
return false;
}
CakePlugin::routes();
@@ -359,4 +355,5 @@ protected function _loadRoutes() {
}
return true;
}
}
@@ -117,4 +117,5 @@ public function getOptionParser() {
'parser' => $this->Extract->getOptionParser()
));
}
}
@@ -58,7 +58,7 @@ public function startup() {
$this->_welcome();
$this->out('Cake Schema Shell');
$this->hr();
$name = $path = $connection = $plugin = null;
if (!empty($this->params['name'])) {
$name = $this->params['name'];
@@ -168,7 +168,7 @@ public function generate() {
$count = 0;
if (!empty($result[1])) {
foreach ($result[1] as $file) {
if (preg_match('/'.preg_quote($fileName).'(?:[_\d]*)?\.php$/', $file)) {
if (preg_match('/' . preg_quote($fileName) . '(?:[_\d]*)?\.php$/', $file)) {
$count++;
}
}
@@ -216,7 +216,7 @@ public function dump() {
}
}
$db = ConnectionManager::getDataSource($this->Schema->connection);
$contents = "\n\n" . $db->dropSchema($Schema) . "\n\n". $db->createSchema($Schema);
$contents = "\n\n" . $db->dropSchema($Schema) . "\n\n" . $db->createSchema($Schema);
if ($write) {
if (strpos($write, '.sql') === false) {
@@ -419,7 +419,7 @@ protected function _run($contents, $event, &$Schema) {
try {
$db->execute($sql);
} catch (PDOException $e) {
$error = $table . ': ' . $e->getMessage();
$error = $table . ': ' . $e->getMessage();
}
$Schema->after(array($event => $table, 'errors' => $error));
@@ -529,4 +529,5 @@ public function getOptionParser() {
));
return $parser;
}
}
@@ -145,17 +145,16 @@ protected function _interactive() {
$useDynamicScaffold = 'n';
$wannaBakeCrud = 'y';
$question[] = __d('cake_console', "Would you like to build your controller interactively?");
if (file_exists($this->path . $controllerName .'Controller.php')) {
if (file_exists($this->path . $controllerName . 'Controller.php')) {
$question[] = __d('cake_console', "Warning: Choosing no will overwrite the %sController.", $controllerName);
}
$doItInteractive = $this->in(implode("\n", $question), array('y','n'), 'y');
$doItInteractive = $this->in(implode("\n", $question), array('y', 'n'), 'y');
if (strtolower($doItInteractive) == 'y') {
$this->interactive = true;
$useDynamicScaffold = $this->in(
__d('cake_console', "Would you like to use dynamic scaffolding?"), array('y','n'), 'n'
__d('cake_console', "Would you like to use dynamic scaffolding?"), array('y', 'n'), 'n'
);
if (strtolower($useDynamicScaffold) == 'y') {
@@ -233,7 +232,7 @@ public function confirmController($controllerName, $useDynamicScaffold, $helpers
$output = '';
$length = count($$var);
foreach ($$var as $i => $propElement) {
if ($i != $length -1) {
if ($i != $length - 1) {
$output .= ucfirst($propElement) . ', ';
} else {
$output .= ucfirst($propElement);
@@ -468,48 +467,4 @@ public function getOptionParser() {
))->epilog(__d('cake_console', 'Omitting all arguments and options will enter into an interactive mode.'));
}
/**
* Displays help contents
*
* @return void
*/
public function help() {
$this->hr();
$this->out("Usage: cake bake controller <arg1> <arg2>...");
$this->hr();
$this->out('Arguments:');
$this->out();
$this->out("<name>");
$this->out("\tName of the controller to bake. Can use Plugin.name");
$this->out("\tas a shortcut for plugin baking.");
$this->out();
$this->out('Params:');
$this->out();
$this->out('-connection <config>');
$this->out("\tset db config <config>. uses 'default' if none is specified");
$this->out();
$this->out('Commands:');
$this->out();
$this->out("controller <name>");
$this->out("\tbakes controller with var \$scaffold");
$this->out();
$this->out("controller <name> public");
$this->out("\tbakes controller with basic crud actions");
$this->out("\t(index, view, add, edit, delete)");
$this->out();
$this->out("controller <name> admin");
$this->out("\tbakes a controller with basic crud actions for one of the");
$this->out("\tConfigure::read('Routing.prefixes') methods.");
$this->out();
$this->out("controller <name> public admin");
$this->out("\tbakes a controller with basic crud actions for one");
$this->out("\tConfigure::read('Routing.prefixes') and non admin methods.");
$this->out("\t(index, view, add, edit, delete,");
$this->out("\tadmin_index, admin_view, admin_edit, admin_add, admin_delete)");
$this->out();
$this->out("controller all");
$this->out("\tbakes all controllers with CRUD methods.");
$this->out();
$this->_stop();
}
}
@@ -364,7 +364,7 @@ public function getConfig() {
$connections = array_keys($configs);
if (count($connections) > 1) {
$useDbConfig = $this->in(__d('cake_console', 'Use Database Config') .':', $connections, $useDbConfig);
$useDbConfig = $this->in(__d('cake_console', 'Use Database Config') . ':', $connections, $useDbConfig);
}
return $useDbConfig;
}
@@ -380,4 +380,5 @@ public function getOptionParser() {
__d('cake_console', 'Bake new database configuration settings.')
);
}
}
@@ -584,8 +584,10 @@ protected function _writeHeader() {
*/
protected function _getStrings(&$position, $target) {
$strings = array();
while (count($strings) < $target && ($this->_tokens[$position] == ',' || $this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING)) {
if ($this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING && $this->_tokens[$position+1] == '.') {
$count = count($strings);
while ($count < $target && ($this->_tokens[$position] == ',' || $this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING)) {
$count = count($strings);
if ($this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING && $this->_tokens[$position + 1] == '.') {
$string = '';
while ($this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING || $this->_tokens[$position] == '.') {
if ($this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) {
@@ -668,7 +670,7 @@ protected function _searchFiles() {
}
$exclude[] = preg_quote($e, '/');
}
$pattern = '/' . implode('|', $exclude) . '/';
$pattern = '/' . implode('|', $exclude) . '/';
}
foreach ($this->_paths as $path) {
$Folder = new Folder($path);
@@ -694,4 +696,5 @@ protected function _searchFiles() {
protected function _isExtractingApp() {
return $this->_paths === array(APP);
}
}
@@ -86,7 +86,7 @@ public function getOptionParser() {
'help' => __d('cake_console', 'Used with --count and <name>/all commands to pull [n] records from the live tables, where [n] is either --count or the default of 10'),
'short' => 'r',
'boolean' => true
))->epilog(__d('cake_console', 'Omitting all arguments and options will enter into an interactive mode.'));;
))->epilog(__d('cake_console', 'Omitting all arguments and options will enter into an interactive mode.'));
}
/**
@@ -388,7 +388,7 @@ protected function _getRecordsFromTable($modelName, $useTable = null) {
$condition = $this->in($prompt, null, 'WHERE 1=1');
}
$prompt = __d('cake_console', "How many records do you want to import?");
$recordCount = $this->in($prompt, null, 10);
$recordCount = $this->in($prompt, null, 10);
} else {
$condition = 'WHERE 1=1';
$recordCount = (isset($this->params['count']) ? $this->params['count'] : 10);
Oops, something went wrong.

0 comments on commit db8c6b5

Please sign in to comment.
You can’t perform that action at this time.