Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add the numbers format console menus, showing the validation options in 2 columns. #682

Closed
wants to merge 5 commits into from

4 participants

@fitorec

Add the numbers format console menus(on CotrollerTask, ModelTask), showing the validation options in 2 columns(ModelTask), Normalizing the array $ConsoleOutput::_styles.

fitorec added some commits
@fitorec fitorec Add the numbers format console menus, showing the validation options …
…in 2 columns.

 Author:      @Fitorec <chanerec@gmail.com>
 Date:        lun jun  4 01:01:22 CDT 2012
 Description: Add the numbers format console menus(on CotrollerTask, ModelTask), showing the validation options in 2 columns(ModelTask), Normalizing the array $ConsoleOutput::_styles
 -------------------------------------------------------------------------
 lib/Cake/Console/Command/Task/ControllerTask.php |    3 +-
 lib/Cake/Console/Command/Task/ModelTask.php      |   25 +++++++++++++--------
 lib/Cake/Console/ConsoleOutput.php               |    2 +-
 3 files changed, 18 insertions(+), 12 deletions(-)
c7b821f
@fitorec fitorec Removing the case
 Author:      @Fitorec <chanerec@gmail.com>
 Date:        lun jun  4 01:20:27 CDT 2012
 Description: Removing the case in ModelTask - pull request #682
 -------------------------------------------------------------------------
 lib/Cake/Console/Command/Task/ModelTask.php |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
d39e062
lib/Cake/Console/Command/Task/ModelTask.php
((12 lines not shown))
- $prompt = '';
- for ($i = 1; $i < $defaultChoice; $i++) {
- $prompt .= $i . ' - ' . $this->_validations[$i] . "\n";
+ for ($i = 1, $m=$defaultChoice/2; $i < $m; $i++) {
+ $str_aux = sprintf("%2d. %s", $i, $this->_validations[$i]);
@markstory Owner

variable names should be camelBacked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/Cake/Console/Command/Task/ModelTask.php
((12 lines not shown))
- $prompt = '';
- for ($i = 1; $i < $defaultChoice; $i++) {
- $prompt .= $i . ' - ' . $this->_validations[$i] . "\n";
+ for ($i = 1, $m=$defaultChoice/2; $i < $m; $i++) {
@markstory Owner

Missing spaces around operators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/Cake/Console/Command/Task/ModelTask.php
((5 lines not shown))
foreach ($options as $i => $option) {
- $this->out($i + 1 . '. ' . $option);
+ $this->out(sprintf("%${len}d. %s", $i+1, $option));
@markstory Owner

spaces are required around operators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@fitorec fitorec Adding coding style.
 Author:      @Fitorec <chanerec@gmail.com>
 Date:        lun jun  4 07:57:14 CDT 2012
 Description: Add coding style from @ markstory comments.
 -------------------------------------------------------------------------
 lib/Cake/Console/Command/Task/ModelTask.php |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)
ae4aed1
@fitorec

Hi!, I just made the changes relevant to the style of coding, the curious thing is that before I pull requests I had tested with phpcs.

@fitorec

The tests I did with https://github.com/jrbasso/CodeSniffer_CakePHP

These rules of spaces between operators, so camel for variables, is not the CodeSniffer_CakePHP detected?,or maybe I have it configured incorrectly.

@fitorec

@sitedyno thanks for the info now install this version.

@markstory
Owner

Why do your commit messages contain the shortlog of changes made?

lib/Cake/Console/Command/Task/ModelTask.php
((12 lines not shown))
- $prompt = '';
- for ($i = 1; $i < $defaultChoice; $i++) {
- $prompt .= $i . ' - ' . $this->_validations[$i] . "\n";
+ for ($i = 1, $m = $defaultChoice / 2; $i < $m; $i++) {
+ $strAux = sprintf("%2d. %s", $i, $this->_validations[$i]);
+ strAux = $strAux.str_repeat(" ", 31 - strlen(strAux));
@markstory Owner

This and the line below contain parse errors.

Parse error: syntax error, unexpected '=' in lib/Cake/Console/Command/Task/ModelTask.php on line 415

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@fitorec fitorec Repairing error of the variable named.
 Author:      @Fitorec <chanerec@gmail.com>
 Date:        lun jun  4 19:54:45 CDT 2012
 Description: I'm wrong and give an error of substituting the name of the variable $strAux does not add the prefix '$', so I just checked.
32a5eac
@fitorec

@markstory some people like this information in the commits/pullRequests, is my hook prepare-commit-msg(is basically a git diff - stat - staged).

@rchavik
Collaborator

i don't think these stats are relevant for commit messages. They are relevant for merges though.

@markstory
Owner

@fitorec Ah ok, I'll just take them out as they aren't necessary in CakePHP. We're not nearly as picky :)

@fitorec

I'm thinking of adding support for type "Enum-> inlist" (MySQL) and "dateTime" in the ModelTask->fieldValidation.

Maybe the following instructions:

<?php
if ($metaData['null'] != 1 && !in_array($fieldName, array($primaryKey, 'created', 'modified', 'updated'))) {
    if ($fieldName == 'email') {
        $guess = $methods['email'];
    } 
    /*... */
    } elseif ($metaData['type'] == 'datetime') { //datetime support
        $guess = $methods['datetime'];
    } elseif (strrpos($metaData['type'], 'enum') === 0) { //Enum support
        $guess = $methods['inlist'];
    }
}

What do you think?

@markstory
Owner

Enum column types are not supported, so I don't know why they'd have validation suggestions.

@fitorec

@markstory I made the change locally, in the run it to create the test files I generate a error.

I think the enum could do with the type inlist.

I would like to review in the near future, if they think the support to enum is a good change, I can try to add this support to cake :cake:

Just add the change to datetime?:

<?php
    /*... */
    } elseif ($metaData['type'] == 'datetime') { //datetime support
        $guess = $methods['datetime'];
    }
@fitorec fitorec Adding case 'datetime' for the selection of $guess
 Description: in ModelTask->fieldValidation added option "datetime"
b6e99f6
@markstory
Owner

I reworded the commits and merged it into 2.2

@markstory markstory closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 4, 2012
  1. @fitorec

    Add the numbers format console menus, showing the validation options …

    fitorec authored
    …in 2 columns.
    
     Author:      @Fitorec <chanerec@gmail.com>
     Date:        lun jun  4 01:01:22 CDT 2012
     Description: Add the numbers format console menus(on CotrollerTask, ModelTask), showing the validation options in 2 columns(ModelTask), Normalizing the array $ConsoleOutput::_styles
     -------------------------------------------------------------------------
     lib/Cake/Console/Command/Task/ControllerTask.php |    3 +-
     lib/Cake/Console/Command/Task/ModelTask.php      |   25 +++++++++++++--------
     lib/Cake/Console/ConsoleOutput.php               |    2 +-
     3 files changed, 18 insertions(+), 12 deletions(-)
  2. @fitorec

    Removing the case

    fitorec authored
     Author:      @Fitorec <chanerec@gmail.com>
     Date:        lun jun  4 01:20:27 CDT 2012
     Description: Removing the case in ModelTask - pull request #682
     -------------------------------------------------------------------------
     lib/Cake/Console/Command/Task/ModelTask.php |    4 ++--
     1 files changed, 2 insertions(+), 2 deletions(-)
  3. @fitorec

    Adding coding style.

    fitorec authored
     Author:      @Fitorec <chanerec@gmail.com>
     Date:        lun jun  4 07:57:14 CDT 2012
     Description: Add coding style from @ markstory comments.
     -------------------------------------------------------------------------
     lib/Cake/Console/Command/Task/ModelTask.php |   16 ++++++++--------
     1 files changed, 8 insertions(+), 8 deletions(-)
Commits on Jun 5, 2012
  1. @fitorec

    Repairing error of the variable named.

    fitorec authored
     Author:      @Fitorec <chanerec@gmail.com>
     Date:        lun jun  4 19:54:45 CDT 2012
     Description: I'm wrong and give an error of substituting the name of the variable $strAux does not add the prefix '$', so I just checked.
Commits on Jun 8, 2012
  1. @fitorec

    Adding case 'datetime' for the selection of $guess

    fitorec authored
     Description: in ModelTask->fieldValidation added option "datetime"
This page is out of date. Refresh to see the latest.
View
3  lib/Cake/Console/Command/Task/ControllerTask.php
@@ -397,11 +397,12 @@ public function listAll($useDbConfig = null) {
if ($this->interactive == true) {
$this->out(__d('cake_console', 'Possible Controllers based on your current database:'));
+ $this->hr();
$this->_controllerNames = array();
$count = count($this->__tables);
for ($i = 0; $i < $count; $i++) {
$this->_controllerNames[] = $this->_controllerName($this->_modelName($this->__tables[$i]));
- $this->out($i + 1 . ". " . $this->_controllerNames[$i]);
+ $this->out(sprintf("%2d. %s", $i + 1, $this->_controllerNames[$i]));
}
return $this->_controllerNames;
}
View
27 lib/Cake/Console/Command/Task/ModelTask.php
@@ -169,8 +169,9 @@ public function inOptions($options, $prompt = null, $default = null) {
$valid = false;
$max = count($options);
while (!$valid) {
+ $len = strlen((count($options)+1));
foreach ($options as $i => $option) {
- $this->out($i + 1 . '. ' . $option);
+ $this->out(sprintf("%${len}d. %s", $i + 1, $option));
}
if (empty($prompt)) {
$prompt = __d('cake_console', 'Make a selection from the choices above');
@@ -403,20 +404,23 @@ public function fieldValidation($fieldName, $metaData, $primaryKey = 'id') {
while ($anotherValidator == 'y') {
if ($this->interactive) {
$this->out();
- $this->out(__d('cake_console', 'Field: %s', $fieldName));
- $this->out(__d('cake_console', 'Type: %s', $metaData['type']));
+ $this->out(__d('cake_console', 'Field: <info>%s</info>', $fieldName));
+ $this->out(__d('cake_console', 'Type: <info>%s</info>', $metaData['type']));
$this->hr();
$this->out(__d('cake_console', 'Please select one of the following validation options:'));
$this->hr();
- }
- $prompt = '';
- for ($i = 1; $i < $defaultChoice; $i++) {
- $prompt .= $i . ' - ' . $this->_validations[$i] . "\n";
+ for ($i = 1, $m = $defaultChoice / 2; $i < $m; $i++) {
+ $strAux = sprintf("%2d. %s", $i, $this->_validations[$i]);
+ $strAux = $strAux.str_repeat(" ", 31 - strlen($strAux));
+ $strAux .= sprintf("%2d. %s", $m + $i, $this->_validations[$m + $i]);
+ $this->out($strAux);
+ }
+ $this->out(__d('cake_console', "%s - Do not do any validation on this field.", $defaultChoice));
+ $this->hr();
}
- $prompt .= __d('cake_console', "%s - Do not do any validation on this field.\n", $defaultChoice);
- $prompt .= __d('cake_console', "... or enter in a valid regex validation string.\n");
+ $prompt = __d('cake_console', "... or enter in a valid regex validation string.\n");
$methods = array_flip($this->_validations);
$guess = $defaultChoice;
if ($metaData['null'] != 1 && !in_array($fieldName, array($primaryKey, 'created', 'modified', 'updated'))) {
@@ -436,6 +440,8 @@ public function fieldValidation($fieldName, $metaData, $primaryKey = 'id') {
$guess = $methods['date'];
} elseif ($metaData['type'] == 'time') {
$guess = $methods['time'];
+ } elseif ($metaData['type'] == 'datetime') {
+ $guess = $methods['datetime'];
} elseif ($metaData['type'] == 'inet') {
$guess = $methods['ip'];
}
@@ -842,8 +848,9 @@ public function listAll($useDbConfig = null) {
}
if ($this->interactive === true) {
$this->out(__d('cake_console', 'Possible Models based on your current database:'));
+ $len = strlen(($count + 1));
for ($i = 0; $i < $count; $i++) {
- $this->out($i + 1 . ". " . $this->_modelNames[$i]);
+ $this->out(sprintf("%${len}d. %s", $i + 1, $this->_modelNames[$i]));
}
}
return $this->_tables;
View
2  lib/Cake/Console/ConsoleOutput.php
@@ -133,7 +133,7 @@ class ConsoleOutput {
'info' => array('text' => 'cyan'),
'success' => array('text' => 'green'),
'comment' => array('text' => 'blue'),
- 'question' => array('text' => "magenta"),
+ 'question' => array('text' => 'magenta'),
);
/**
Something went wrong with that request. Please try again.