runCommand $command as string

Sets typehint for runCommand argument as string.

Fixes original default behavior to send string $command rather than null.
This commit is contained in:
José Muñoz 2022-01-16 07:47:57 -07:00
parent e946ab071d
commit 3719cce178
3 changed files with 5 additions and 5 deletions

View file

@ -353,7 +353,7 @@ class Shell extends CakeObject {
* @return bool * @return bool
* @link https://book.cakephp.org/2.0/en/console-and-shells.html#Shell::hasMethod * @link https://book.cakephp.org/2.0/en/console-and-shells.html#Shell::hasMethod
*/ */
public function hasMethod($name) { public function hasMethod(string $name) {
try { try {
$method = new ReflectionMethod($this, $name); $method = new ReflectionMethod($this, $name);
if (!$method->isPublic() || substr($name, 0, 1) === '_') { if (!$method->isPublic() || substr($name, 0, 1) === '_') {
@ -418,7 +418,7 @@ class Shell extends CakeObject {
* @return int|bool * @return int|bool
* @link https://book.cakephp.org/2.0/en/console-and-shells.html#Shell::runCommand * @link https://book.cakephp.org/2.0/en/console-and-shells.html#Shell::runCommand
*/ */
public function runCommand($command, $argv) { public function runCommand(string $command, $argv) {
$isTask = $this->hasTask($command); $isTask = $this->hasTask($command);
$isMethod = $this->hasMethod($command); $isMethod = $this->hasMethod($command);
$isMain = $this->hasMethod('main'); $isMain = $this->hasMethod('main');

View file

@ -212,7 +212,7 @@ class ShellDispatcher {
$Shell = $this->_getShell($shell); $Shell = $this->_getShell($shell);
$command = null; $command = '';
if (isset($this->args[0])) { if (isset($this->args[0])) {
$command = $this->args[0]; $command = $this->args[0];
} }

View file

@ -724,7 +724,7 @@ class ShellTest extends CakeTestCase {
$Mock = $this->getMock('Shell', array('main', 'startup'), array(), '', false); $Mock = $this->getMock('Shell', array('main', 'startup'), array(), '', false);
$Mock->expects($this->once())->method('main')->will($this->returnValue(true)); $Mock->expects($this->once())->method('main')->will($this->returnValue(true));
$result = $Mock->runCommand(null, array()); $result = $Mock->runCommand('', array());
$this->assertTrue($result); $this->assertTrue($result);
} }
@ -815,7 +815,7 @@ class ShellTest extends CakeTestCase {
->will($this->returnValue($Parser)); ->will($this->returnValue($Parser));
$Shell->expects($this->once())->method('out'); $Shell->expects($this->once())->method('out');
$Shell->runCommand(null, array('--help')); $Shell->runCommand('', array('--help'));
} }
/** /**