mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Pulling out some duplicated code into methods.
This commit is contained in:
parent
5e8222ef39
commit
8261581b3b
2 changed files with 24 additions and 10 deletions
|
@ -53,6 +53,15 @@ class ConsoleInputOption {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name of the argument
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function name() {
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate the help for this this option.
|
* Generate the help for this this option.
|
||||||
*
|
*
|
||||||
|
|
|
@ -390,11 +390,7 @@ class ConsoleOptionParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($this->_options)) {
|
if (!empty($this->_options)) {
|
||||||
$max = 0;
|
$max = $this->_getMaxLength($this->_options) + 8;
|
||||||
foreach ($this->_options as $description) {
|
|
||||||
$max = (strlen($description->name) > $max) ? strlen($description->name) : $max;
|
|
||||||
}
|
|
||||||
$max += 8;
|
|
||||||
$out[] = '<info>Options:</info>';
|
$out[] = '<info>Options:</info>';
|
||||||
$out[] = '';
|
$out[] = '';
|
||||||
foreach ($this->_options as $option) {
|
foreach ($this->_options as $option) {
|
||||||
|
@ -403,11 +399,7 @@ class ConsoleOptionParser {
|
||||||
$out[] = '';
|
$out[] = '';
|
||||||
}
|
}
|
||||||
if (!empty($this->_args)) {
|
if (!empty($this->_args)) {
|
||||||
$max = 0;
|
$max = $this->_getMaxLength($this->_args) + 2;
|
||||||
foreach ($this->_args as $argument) {
|
|
||||||
$max = (strlen($argument->name) > $max) ? strlen($argument->name) : $max;
|
|
||||||
}
|
|
||||||
$max += 2;
|
|
||||||
$out[] = '<info>Arguments:</info>';
|
$out[] = '<info>Arguments:</info>';
|
||||||
$out[] = '';
|
$out[] = '';
|
||||||
foreach ($this->_args as $argument) {
|
foreach ($this->_args as $argument) {
|
||||||
|
@ -547,4 +539,17 @@ class ConsoleOptionParser {
|
||||||
protected function _nextToken() {
|
protected function _nextToken() {
|
||||||
return isset($this->_tokens[0]) ? $this->_tokens[0] : '';
|
return isset($this->_tokens[0]) ? $this->_tokens[0] : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterate over a collection and find the longest named thing.
|
||||||
|
*
|
||||||
|
* @return integer
|
||||||
|
*/
|
||||||
|
protected function _getMaxLength($collection) {
|
||||||
|
$max = 0;
|
||||||
|
foreach ($collection as $item) {
|
||||||
|
$max = (strlen($item->name()) > $max) ? strlen($item->name()) : $max;
|
||||||
|
}
|
||||||
|
return $max;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue