From 5e1bc5532ac769d986e3d9dfc42786b2df862687 Mon Sep 17 00:00:00 2001 From: Lee Rowlands Date: Mon, 21 Jan 2019 13:44:00 +1000 Subject: [PATCH] [#jira] Handle invalid ticket IDs --- src/Commands/Start.php | 3 +++ src/Commands/Visit.php | 25 ++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Commands/Start.php b/src/Commands/Start.php index 821800b..67143b6 100644 --- a/src/Commands/Start.php +++ b/src/Commands/Start.php @@ -79,6 +79,9 @@ protected function execute(InputInterface $input, OutputInterface $output) { else { $connector_id = $this->connector->spotConnector($ticket_id, $input, $output); } + if (!$connector_id) { + throw new \InvalidArgumentException('No such ticket was found in any backends.'); + } if ($alias = $this->connector->loadAlias($ticket_id, $connector_id)) { $ticket_id = $alias; } diff --git a/src/Commands/Visit.php b/src/Commands/Visit.php index d246a1b..a428057 100644 --- a/src/Commands/Visit.php +++ b/src/Commands/Visit.php @@ -59,7 +59,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('No active ticket, please use tl visit {ticket_id} to specifiy a ticket.'); return; } - $url = $this->connector->ticketUrl($issue_number, isset($data) ? $data->connector_id : $this->connector->spotConnector($issue_number, $input, $output)); + $url = $this->connector->ticketUrl($issue_number, isset($data) ? $data->connector_id : $this->getConnector($input, $output, $issue_number)); $this->open($url, $output); } @@ -94,4 +94,27 @@ protected function open($url, OutputInterface $output) { } } + /** + * Gets connector ID. + * @param \Symfony\Component\Console\Input\InputInterface $input + * Input. + * @param \Symfony\Component\Console\Output\OutputInterface $output + * Output. + * @param mixed $issue_number + * Issue number. + * + * @return string + * Connector ID. + * + * @throws \InvalidArgumentException + * When no such ticket exists. + */ + protected function getConnector(InputInterface $input, OutputInterface $output, $issue_number) { + $connector_id = $this->connector->spotConnector($issue_number, $input, $output); + if (!$connector_id) { + throw new \InvalidArgumentException('No such ticket was found in any backends.'); + } + return $connector_id; + } + }