Skip to content

Commit

Permalink
Split up more $this|other mixed methods into separate getter/setter m…
Browse files Browse the repository at this point in the history
…ethods.
  • Loading branch information
dereuromark committed Nov 12, 2016
1 parent d39336f commit 8eb4ecf
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 32 deletions.
103 changes: 86 additions & 17 deletions src/Console/ConsoleOptionParser.php
Expand Up @@ -270,64 +270,133 @@ public function merge($spec)
return $this;
}

/**
* Sets the command name for shell/task.
*
* @param string $text The text to set.
* @return $this
*/
public function setCommand($text)
{
$this->_command = Inflector::underscore($text);

return $this;
}

/**
* Gets the command name for shell/task.
*
* @return string The value of the command.
*/
public function getCommand()
{
return $this->_command;
}

/**
* Gets or sets the command name for shell/task.
*
* @deprecated 3.4.0 Use setCommand()/getCommand() instead.
* @param string|null $text The text to set, or null if you want to read
* @return string|$this If reading, the value of the command. If setting $this will be returned.
*/
public function command($text = null)
{
if ($text !== null) {
$this->_command = Inflector::underscore($text);
return $this->setCommand($text);
}

return $this->getCommand();
}

return $this;
/**
* Sets the description text for shell/task.
*
* @param string|array $text The text to set. If an array the
* text will be imploded with "\n".
* @return $this
*/
public function setDescription($text)
{
if (is_array($text)) {
$text = implode("\n", $text);
}
$this->_description = $text;

return $this->_command;
return $this;
}

/**
* Gets the description text for shell/task.
*
* @return string The value of the description
*/
public function getDescription()
{
return $this->_description;
}

/**
* Get or set the description text for shell/task.
*
* @deprecated 3.4.0 Use setDescription()/getDescription() instead.
* @param string|array|null $text The text to set, or null if you want to read. If an array the
* text will be imploded with "\n".
* @return string|$this If reading, the value of the description. If setting $this will be returned.
*/
public function description($text = null)
{
if ($text !== null) {
if (is_array($text)) {
$text = implode("\n", $text);
}
$this->_description = $text;
return $this->setDescription($text);
}

return $this;
return $this->getDescription();
}

/**
* Sets an epilog to the parser. The epilog is added to the end of
* the options and arguments listing when help is generated.
*
* @param string|array $text The text to set. If an array the text will
* be imploded with "\n".
* @return $this
*/
public function setEpilog($text)
{
if (is_array($text)) {
$text = implode("\n", $text);
}
$this->_epilog = $text;

return $this->_description;
return $this;
}

/**
* Gets the epilog.
*
* @return string The value of the epilog.
*/
public function getEpilog()
{
return $this->_epilog;
}

/**
* Get or set an epilog to the parser. The epilog is added to the end of
* Gets or sets an epilog to the parser. The epilog is added to the end of
* the options and arguments listing when help is generated.
*
* @deprecated 3.4.0 Use setEpilog()/getEpilog() instead.
* @param string|array|null $text Text when setting or null when reading. If an array the text will
* be imploded with "\n".
* @return string|$this If reading, the value of the epilog. If setting $this will be returned.
*/
public function epilog($text = null)
{
if ($text !== null) {
if (is_array($text)) {
$text = implode("\n", $text);
}
$this->_epilog = $text;

return $this;
return $this->setEpilog($text);
}

return $this->_epilog;
return $this->getEpilog();
}

/**
Expand Down
52 changes: 41 additions & 11 deletions src/Validation/Validator.php
Expand Up @@ -173,6 +173,43 @@ public function hasField($name)
return isset($this->_fields[$name]);
}

/**
* Associates an object to a name so it can be used as a provider. Providers are
* objects or class names that can contain methods used during validation of for
* deciding whether a validation rule can be applied. All validation methods,
* when called will receive the full list of providers stored in this validator.
*
* @param string $name The name under which the provider should be set.
* @param object|string $object Provider object or class name.
* @return $this
*/
public function setProvider($name, $object)
{
$this->_providers[$name] = $object;

return $this;
}

/**
* Returns the provider stored under that name if it exists.
*
* @param string $name The name under which the provider should be set.
* @return object|string|null
*/
public function getProvider($name)
{
if (isset($this->_providers[$name])) {
return $this->_providers[$name];
}
if ($name !== 'default') {
return null;
}

$this->_providers[$name] = new RulesProvider();

return $this->_providers[$name];
}

/**
* Associates an object to a name so it can be used as a provider. Providers are
* objects or class names that can contain methods used during validation of for
Expand All @@ -182,25 +219,18 @@ public function hasField($name)
* If called with no arguments, it will return the provider stored under that name if
* it exists, otherwise it returns this instance of chaining.
*
* @deprecated 3.4.0 Use setProvider()/getProvider() instead.
* @param string $name The name under which the provider should be set.
* @param null|object|string $object Provider object or class name.
* @return $this|object|string|null
*/
public function provider($name, $object = null)
{
if ($object === null) {
if (isset($this->_providers[$name])) {
return $this->_providers[$name];
}
if ($name === 'default') {
return $this->_providers[$name] = new RulesProvider();
}

return null;
if ($object !== null) {
return $this->setProvider($name, $object);
}
$this->_providers[$name] = $object;

return $this;
return $this->getProvider($name);
}

/**
Expand Down
33 changes: 29 additions & 4 deletions src/View/StringTemplateTrait.php
Expand Up @@ -29,8 +29,33 @@ trait StringTemplateTrait
protected $_templater;

/**
* Get/set templates to use.
* Sets templates to use.
*
* @param array $templates Templates to be added.
* @return $this
*/
public function setTemplates(array $templates)
{
$this->templater()->add($templates);

return $this;
}

/**
* Gets templates to use or a specific template.
*
* @param string|null $template String for reading a specific template, null for all.
* @return string|array
*/
public function getTemplates($template = null)
{
return $this->templater()->get($template);
}

/**
* Gets/sets templates to use.
*
* @deprecated 3.4.0 Use setTemplates()/getTemplates() instead.
* @param string|null|array $templates null or string allow reading templates. An array
* allows templates to be added.
* @return $this|string|array
Expand All @@ -47,7 +72,7 @@ public function templates($templates = null)
}

/**
* Format a template string with $data
* Formats a template string with $data
*
* @param string $name The template name.
* @param array $data The data to insert.
Expand All @@ -59,13 +84,13 @@ public function formatTemplate($name, $data)
}

/**
* templater
* Returns the templater instance.
*
* @return \Cake\View\StringTemplate
*/
public function templater()
{
if (empty($this->_templater)) {
if ($this->_templater === null) {
$class = $this->config('templateClass') ?: 'Cake\View\StringTemplate';
$this->_templater = new $class();

Expand Down

0 comments on commit 8eb4ecf

Please sign in to comment.