From 3719cce1788773efee08ab315a38d45e38387f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Mu=C3=B1oz?= Date: Sun, 16 Jan 2022 07:47:57 -0700 Subject: [PATCH] runCommand $command as string Sets typehint for runCommand argument as string. Fixes original default behavior to send string $command rather than null. --- lib/Cake/Console/Shell.php | 4 ++-- lib/Cake/Console/ShellDispatcher.php | 2 +- lib/Cake/Test/Case/Console/ShellTest.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Console/Shell.php b/lib/Cake/Console/Shell.php index c8033e695..2e9cebf25 100644 --- a/lib/Cake/Console/Shell.php +++ b/lib/Cake/Console/Shell.php @@ -353,7 +353,7 @@ class Shell extends CakeObject { * @return bool * @link https://book.cakephp.org/2.0/en/console-and-shells.html#Shell::hasMethod */ - public function hasMethod($name) { + public function hasMethod(string $name) { try { $method = new ReflectionMethod($this, $name); if (!$method->isPublic() || substr($name, 0, 1) === '_') { @@ -418,7 +418,7 @@ class Shell extends CakeObject { * @return int|bool * @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); $isMethod = $this->hasMethod($command); $isMain = $this->hasMethod('main'); diff --git a/lib/Cake/Console/ShellDispatcher.php b/lib/Cake/Console/ShellDispatcher.php index 22a4e53f7..2238257b2 100644 --- a/lib/Cake/Console/ShellDispatcher.php +++ b/lib/Cake/Console/ShellDispatcher.php @@ -212,7 +212,7 @@ class ShellDispatcher { $Shell = $this->_getShell($shell); - $command = null; + $command = ''; if (isset($this->args[0])) { $command = $this->args[0]; } diff --git a/lib/Cake/Test/Case/Console/ShellTest.php b/lib/Cake/Test/Case/Console/ShellTest.php index fd461a98e..25ddb5857 100644 --- a/lib/Cake/Test/Case/Console/ShellTest.php +++ b/lib/Cake/Test/Case/Console/ShellTest.php @@ -724,7 +724,7 @@ class ShellTest extends CakeTestCase { $Mock = $this->getMock('Shell', array('main', 'startup'), array(), '', false); $Mock->expects($this->once())->method('main')->will($this->returnValue(true)); - $result = $Mock->runCommand(null, array()); + $result = $Mock->runCommand('', array()); $this->assertTrue($result); } @@ -815,7 +815,7 @@ class ShellTest extends CakeTestCase { ->will($this->returnValue($Parser)); $Shell->expects($this->once())->method('out'); - $Shell->runCommand(null, array('--help')); + $Shell->runCommand('', array('--help')); } /**