From 795a0e32c71ce6e924dfaeda5276c074d61735c5 Mon Sep 17 00:00:00 2001 From: Daniel Leech Date: Fri, 25 Mar 2022 17:01:06 +0100 Subject: [PATCH] Update --- composer.json | 2 +- src/Console/src/Application/Application.php | 4 ++-- src/Console/src/Application/Executor.php | 14 +++++++------- .../tests/Test/Usage/Parser/UsageParserTest.php | 4 ++-- .../tests/Test/Runner/BacktrackingRunnerTest.php | 2 +- src/FSM/tests/Test/Runner/SequenceRunnerTest.php | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index e51859b..d817715 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "php": ">=7.3", + "php": ">=7.3||^8.0", "symfony/event-dispatcher": "^4.0" }, diff --git a/src/Console/src/Application/Application.php b/src/Console/src/Application/Application.php index db0a630..6054efe 100644 --- a/src/Console/src/Application/Application.php +++ b/src/Console/src/Application/Application.php @@ -118,14 +118,14 @@ public function section($name): Section return $this->root->get($this->root->getName().' '.$name); } - public function run(?array $argv = null): void + public function run(?array $argv = null): int { if ($argv === null) { global $argv; $argv[0] = $this->root->getName(); } - $this->executor->run($this->root, $argv); + return $this->executor->run($this->root, $argv); } public function getRootSection(): Section diff --git a/src/Console/src/Application/Executor.php b/src/Console/src/Application/Executor.php index 109d889..992442a 100644 --- a/src/Console/src/Application/Executor.php +++ b/src/Console/src/Application/Executor.php @@ -85,7 +85,7 @@ public function getActionCollection(): ActionCollection return $this->actions; } - public function run(Section $section, $argv = []): void + public function run(Section $section, $argv = []): int { $this->argv = $argv; @@ -94,18 +94,18 @@ public function run(Section $section, $argv = []): void if ($this->matchedSection === null || $this->matchedInput === null) { $this->invalidUsage($argv); - return; + return 1; } if ($this->beforeAction()->isActionPrevented()) { - return; + return 0; } if (($action = $this->matchedSection->getAction()) === null) { - return; + return 0; } - $this->invokeAction($action); + return $this->invokeAction($action); } public function visit(Section $section): bool @@ -193,12 +193,12 @@ private function beforeAction(): BeforeActionEvent return $event; } - private function invokeAction($action) + private function invokeAction($action): int { if (!is_callable($action)) { $action = $this->actions->get($action); } - $action($this->matchedInput); + return $action($this->matchedInput) ?? 0; } } diff --git a/src/Console/tests/Test/Usage/Parser/UsageParserTest.php b/src/Console/tests/Test/Usage/Parser/UsageParserTest.php index dd5ed1a..207091c 100644 --- a/src/Console/tests/Test/Usage/Parser/UsageParserTest.php +++ b/src/Console/tests/Test/Usage/Parser/UsageParserTest.php @@ -19,7 +19,7 @@ public function an_argument_is_defined_as_an_alpha_numeric_string_between_angle_ { $result = usage('', 'development'); - $this->assertIsArray($result); + self::assertIsArray($result); $this->assertTrue(count($result) == 1); } @@ -331,4 +331,4 @@ public function passed_options_must_be_part_of_usage_definition() $result = usage('[-hv] foo bar', '--unknown foo bar'); $this->assertFalse($result); } -} \ No newline at end of file +} diff --git a/src/FSM/tests/Test/Runner/BacktrackingRunnerTest.php b/src/FSM/tests/Test/Runner/BacktrackingRunnerTest.php index 144c081..2dcb1e1 100644 --- a/src/FSM/tests/Test/Runner/BacktrackingRunnerTest.php +++ b/src/FSM/tests/Test/Runner/BacktrackingRunnerTest.php @@ -55,4 +55,4 @@ public function it_must_end_on_a_terminal_state_to_return_result() $this->assertEquals(['S3', 'S5'], $this->fsm->input(['t1', 't2'])); $this->assertEquals(false, $this->fsm->input(['t1'])); } -} \ No newline at end of file +} diff --git a/src/FSM/tests/Test/Runner/SequenceRunnerTest.php b/src/FSM/tests/Test/Runner/SequenceRunnerTest.php index ec05aea..aab2ac2 100644 --- a/src/FSM/tests/Test/Runner/SequenceRunnerTest.php +++ b/src/FSM/tests/Test/Runner/SequenceRunnerTest.php @@ -54,4 +54,4 @@ public function it_must_end_on_a_terminal_state_to_return_result() $this->assertEquals(['S2', 'S4'], $this->fsm->input(['t1', 't3'])); $this->assertEquals(false, $this->fsm->input(['t1'])); } -} \ No newline at end of file +}