Skip to content

Commit

Permalink
Fix most of the coding standards issues in Console/
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Mar 3, 2012
1 parent 2a7bee0 commit db8c6b5
Show file tree
Hide file tree
Showing 36 changed files with 146 additions and 158 deletions.
15 changes: 9 additions & 6 deletions lib/Cake/Console/Command/AclShell.php
Expand Up @@ -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);
}
}
Expand All @@ -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']);
}
}
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -602,4 +604,5 @@ protected function _dataVars($type = null) {
$vars['class'] = $class;
return $vars;
}

}
21 changes: 11 additions & 10 deletions lib/Cake/Console/Command/ApiShell.php
Expand Up @@ -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'])) {
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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));
}
}
Expand Down Expand Up @@ -234,4 +234,5 @@ protected function _parseClass($path, $class) {
ksort($parsed);
return $parsed;
}

}
6 changes: 3 additions & 3 deletions lib/Cake/Console/Command/BakeShell.php
Expand Up @@ -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(
Expand Down
7 changes: 2 additions & 5 deletions lib/Cake/Console/Command/CommandListShell.php
@@ -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)
*
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -234,4 +230,5 @@ public function getOptionParser() {
'boolean' => true
));
}

}
7 changes: 2 additions & 5 deletions lib/Cake/Console/Command/ConsoleShell.php
@@ -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)
*
Expand Down Expand Up @@ -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();
Expand All @@ -359,4 +355,5 @@ protected function _loadRoutes() {
}
return true;
}

}
1 change: 1 addition & 0 deletions lib/Cake/Console/Command/I18nShell.php
Expand Up @@ -117,4 +117,5 @@ public function getOptionParser() {
'parser' => $this->Extract->getOptionParser()
));
}

}
9 changes: 5 additions & 4 deletions lib/Cake/Console/Command/SchemaShell.php
Expand Up @@ -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'];
Expand Down Expand Up @@ -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++;
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -529,4 +529,5 @@ public function getOptionParser() {
));
return $parser;
}

}
53 changes: 4 additions & 49 deletions lib/Cake/Console/Command/Task/ControllerTask.php
Expand Up @@ -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') {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
}
3 changes: 2 additions & 1 deletion lib/Cake/Console/Command/Task/DbConfigTask.php
Expand Up @@ -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;
}
Expand All @@ -380,4 +380,5 @@ public function getOptionParser() {
__d('cake_console', 'Bake new database configuration settings.')
);
}

}
9 changes: 6 additions & 3 deletions lib/Cake/Console/Command/Task/ExtractTask.php
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -694,4 +696,5 @@ protected function _searchFiles() {
protected function _isExtractingApp() {
return $this->_paths === array(APP);
}

}
4 changes: 2 additions & 2 deletions lib/Cake/Console/Command/Task/FixtureTask.php
Expand Up @@ -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.'));
}

/**
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit db8c6b5

Please sign in to comment.