From fd0c789f48881fb485e12fa342dd89068924d3f3 Mon Sep 17 00:00:00 2001 From: dongasai <1514582970@qq.com> Date: Mon, 28 Dec 2020 17:12:10 +0800 Subject: [PATCH 1/5] Parser add unRegister method Add the unRegister method to unRegister --- src/Input/Parser.php | 19 +++++++++++++++++++ tests/Input/CommandTest.php | 10 ++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/Input/Parser.php b/src/Input/Parser.php index ba1c81a..f2ef58c 100644 --- a/src/Input/Parser.php +++ b/src/Input/Parser.php @@ -247,6 +247,25 @@ protected function register(Parameter $param) $this->set($name, $param->default()); } + /** + * + * @param string $name + */ + public function unRegister($name) + { + if(isset($this->_values[$name])){ + unset($this->_values[$name]); + } + + if(isset($this->_arguments[$name])){ + unset($this->_arguments[$name]); + } + + if(isset($this->_options[$name])){ + unset($this->_options[$name]); + } + return $this; + } /** * What if the given name is already registered. diff --git a/tests/Input/CommandTest.php b/tests/Input/CommandTest.php index f385641..24ececd 100644 --- a/tests/Input/CommandTest.php +++ b/tests/Input/CommandTest.php @@ -261,6 +261,16 @@ public function test_bind() $this->assertNull($c->app()); } + public function test_unregister() + { + $c = $this->newCommand(); + $this->assertCount(3,$c->allOptions()); + $this->assertArrayHasKey('verbosity', $c->allOptions()); + $c->unRegister('verbosity'); + $this->assertCount(2,$c->allOptions()); + $this->assertArrayNotHasKey('verbosity', $c->allOptions()); + } + protected function newCommand(string $version = '0.0.1', string $desc = '', bool $allowUnknown = false, $app = null) { $p = new Command('cmd', $desc, $allowUnknown, $app); From 5547592801569e54b7ce0de51a5daa18ccc31a07 Mon Sep 17 00:00:00 2001 From: dongasai <1514582970@qq.com> Date: Mon, 28 Dec 2020 17:50:16 +0800 Subject: [PATCH 2/5] phpcbf phpcbf --- src/Input/Parser.php | 13 +++++++------ tests/Input/CommandTest.php | 6 +++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Input/Parser.php b/src/Input/Parser.php index f2ef58c..43fa2fa 100644 --- a/src/Input/Parser.php +++ b/src/Input/Parser.php @@ -248,22 +248,23 @@ protected function register(Parameter $param) $this->set($name, $param->default()); } /** - * + * unRegister a new argument/option. * @param string $name */ public function unRegister($name) { - if(isset($this->_values[$name])){ + if (isset($this->_values[$name])) { unset($this->_values[$name]); } - - if(isset($this->_arguments[$name])){ + + if (isset($this->_arguments[$name])) { unset($this->_arguments[$name]); } - - if(isset($this->_options[$name])){ + + if (isset($this->_options[$name])) { unset($this->_options[$name]); } + return $this; } diff --git a/tests/Input/CommandTest.php b/tests/Input/CommandTest.php index 24ececd..acdc6b9 100644 --- a/tests/Input/CommandTest.php +++ b/tests/Input/CommandTest.php @@ -264,13 +264,13 @@ public function test_bind() public function test_unregister() { $c = $this->newCommand(); - $this->assertCount(3,$c->allOptions()); + $this->assertCount(3, $c->allOptions()); $this->assertArrayHasKey('verbosity', $c->allOptions()); $c->unRegister('verbosity'); - $this->assertCount(2,$c->allOptions()); + $this->assertCount(2, $c->allOptions()); $this->assertArrayNotHasKey('verbosity', $c->allOptions()); } - + protected function newCommand(string $version = '0.0.1', string $desc = '', bool $allowUnknown = false, $app = null) { $p = new Command('cmd', $desc, $allowUnknown, $app); From d41974ecb177277d9838a61979452ce12b01de8b Mon Sep 17 00:00:00 2001 From: dongasai <1514582970@qq.com> Date: Mon, 28 Dec 2020 17:52:13 +0800 Subject: [PATCH 3/5] Fixed format --- src/Input/Parser.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Input/Parser.php b/src/Input/Parser.php index 43fa2fa..c228caa 100644 --- a/src/Input/Parser.php +++ b/src/Input/Parser.php @@ -247,8 +247,10 @@ protected function register(Parameter $param) $this->set($name, $param->default()); } + /** * unRegister a new argument/option. + * * @param string $name */ public function unRegister($name) From e4de321fae52bcf521074916c616691bd1dc9849 Mon Sep 17 00:00:00 2001 From: dongasai <1514582970@qq.com> Date: Sat, 2 Jan 2021 21:34:02 +0800 Subject: [PATCH 4/5] fixed --- src/Input/Parser.php | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/Input/Parser.php b/src/Input/Parser.php index c228caa..3a635cf 100644 --- a/src/Input/Parser.php +++ b/src/Input/Parser.php @@ -247,25 +247,15 @@ protected function register(Parameter $param) $this->set($name, $param->default()); } - + /** * unRegister a new argument/option. - * + * * @param string $name */ public function unRegister($name) { - if (isset($this->_values[$name])) { - unset($this->_values[$name]); - } - - if (isset($this->_arguments[$name])) { - unset($this->_arguments[$name]); - } - - if (isset($this->_options[$name])) { - unset($this->_options[$name]); - } + unset($this->_values[$name], $this->_arguments[$name], $this->_options[$name]); return $this; } From e7757a2560dc71c24bc5739dcd1c5b718593a600 Mon Sep 17 00:00:00 2001 From: dongasai <1514582970@qq.com> Date: Tue, 5 Jan 2021 13:41:22 +0800 Subject: [PATCH 5/5] fixed function name to unset --- src/Input/Parser.php | 4 ++-- tests/Input/CommandTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Input/Parser.php b/src/Input/Parser.php index 3a635cf..f710d68 100644 --- a/src/Input/Parser.php +++ b/src/Input/Parser.php @@ -249,11 +249,11 @@ protected function register(Parameter $param) } /** - * unRegister a new argument/option. + * unset a registered argument/option. * * @param string $name */ - public function unRegister($name) + public function unset($name) { unset($this->_values[$name], $this->_arguments[$name], $this->_options[$name]); diff --git a/tests/Input/CommandTest.php b/tests/Input/CommandTest.php index acdc6b9..4f3059b 100644 --- a/tests/Input/CommandTest.php +++ b/tests/Input/CommandTest.php @@ -261,12 +261,12 @@ public function test_bind() $this->assertNull($c->app()); } - public function test_unregister() + public function test_unset() { $c = $this->newCommand(); $this->assertCount(3, $c->allOptions()); $this->assertArrayHasKey('verbosity', $c->allOptions()); - $c->unRegister('verbosity'); + $c->unset('verbosity'); $this->assertCount(2, $c->allOptions()); $this->assertArrayNotHasKey('verbosity', $c->allOptions()); }