Skip to content

Commit

Permalink
Turning __get() back into methods. There were so few properties being…
Browse files Browse the repository at this point in the history
… accessed that it didn't make sense to have __get(), over a handful of methods.

Tests updated.
  • Loading branch information
markstory committed Nov 13, 2010
1 parent f9b7cbc commit 6c8c7ca
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 33 deletions.
12 changes: 4 additions & 8 deletions cake/console/libs/console_input_argument.php
Expand Up @@ -51,16 +51,12 @@ public function __construct($name, $help = '', $required = false, $choices = arr
}

/**
* Protected attribute accessor.
* Get the value of the name attribute.
*
* @param string $name Name of attribute to read.
* @return mixed.
* @return string Value of this->_name.
*/
public function __get($name) {
if (isset($this->{'_' . $name})) {
return $this->{'_' . $name};
}
return null;
public function name() {
return $this->_name;
}

/**
Expand Down
21 changes: 13 additions & 8 deletions cake/console/libs/console_input_option.php
Expand Up @@ -56,16 +56,21 @@ public function __construct($name, $short = null, $help = '', $boolean = false,
}

/**
* Protected attribute accessor.
* Get the value of the name attribute.
*
* @param string $name Name of attribute to read.
* @return mixed.
* @return string Value of this->_name.
*/
public function __get($name) {
if (isset($this->{'_' . $name})) {
return $this->{'_' . $name};
}
return null;
public function name() {
return $this->_name;
}

/**
* Get the value of the short attribute.
*
* @return string Value of this->_short.
*/
public function short() {
return $this->_short;
}

/**
Expand Down
12 changes: 4 additions & 8 deletions cake/console/libs/console_input_subcommand.php
Expand Up @@ -54,16 +54,12 @@ public function __construct($name, $help = '', $parser = null) {
}

/**
* Protected attribute accessor.
* Get the value of the name attribute.
*
* @param string $name Name of attribute to read.
* @return mixed.
* @return string Value of this->_name.
*/
public function __get($name) {
if (isset($this->{'_' . $name})) {
return $this->{'_' . $name};
}
return null;
public function name() {
return $this->_name;
}

/**
Expand Down
12 changes: 6 additions & 6 deletions cake/console/libs/console_option_parser.php
Expand Up @@ -267,7 +267,7 @@ public function epilog($text = null) {
public function addOption($name, $params = array()) {
if (is_object($name) && $name instanceof ConsoleInputOption) {
$option = $name;
$name = $option->name;
$name = $option->name();
} else {
$defaults = array(
'name' => $name,
Expand All @@ -281,8 +281,8 @@ public function addOption($name, $params = array()) {
$option = new ConsoleInputOption($options);
}
$this->_options[$name] = $option;
if ($option->short !== null) {
$this->_shortOptions[$option->short] = $name;
if ($option->short() !== null) {
$this->_shortOptions[$option->short()] = $name;
}
return $this;
}
Expand Down Expand Up @@ -374,7 +374,7 @@ public function addOptions(array $options) {
public function addSubcommand($name, $params = array()) {
if (is_object($name) && $name instanceof ConsoleInputSubcommand) {
$command = $name;
$name = $command->name;
$name = $command->name();
} else {
$defaults = array(
'name' => $name,
Expand Down Expand Up @@ -458,12 +458,12 @@ public function parse($argv, $command = null) {
foreach ($this->_args as $i => $arg) {
if ($arg->isRequired() && !isset($args[$i]) && empty($params['help'])) {
throw new RuntimeException(
sprintf(__('Missing required arguments. %s is required.'), $arg->name)
sprintf(__('Missing required arguments. %s is required.'), $arg->name())
);
}
}
foreach ($this->_options as $option) {
$name = $option->name;
$name = $option->name();
$isBoolean = $option->isBoolean();
$default = $option->defaultValue();

Expand Down
2 changes: 1 addition & 1 deletion cake/console/libs/help_formatter.php
Expand Up @@ -141,7 +141,7 @@ protected function _generateUsage() {
protected function _getMaxLength($collection) {
$max = 0;
foreach ($collection as $item) {
$max = (strlen($item->name) > $max) ? strlen($item->name) : $max;
$max = (strlen($item->name()) > $max) ? strlen($item->name()) : $max;
}
return $max;
}
Expand Down
4 changes: 2 additions & 2 deletions cake/tests/cases/console/libs/console_option_parser.test.php
Expand Up @@ -277,7 +277,7 @@ function testAddArgumentObject() {
$parser->addArgument(new ConsoleInputArgument('test'));
$result = $parser->arguments();
$this->assertEquals(1, count($result));
$this->assertEquals('test', $result[0]->name);
$this->assertEquals('test', $result[0]->name());
}

/**
Expand Down Expand Up @@ -385,7 +385,7 @@ function testAddSubcommandObject() {
$parser->addSubcommand(new ConsoleInputSubcommand('test'));
$result = $parser->subcommands();
$this->assertEquals(1, count($result));
$this->assertEquals('test', $result['test']->name);
$this->assertEquals('test', $result['test']->name());
}

/**
Expand Down

0 comments on commit 6c8c7ca

Please sign in to comment.