From cfe467b162ecb877d64911c5f221fb4c893ed28e Mon Sep 17 00:00:00 2001 From: "tien.xuan.vo" Date: Fri, 12 Apr 2019 09:53:29 +0700 Subject: [PATCH] Throw exceptions --- src/Command/CaptureScreenshotsCommand.php | 8 ++++++++ src/Command/RemoveScreenshotsCommand.php | 4 ++++ src/Command/ReportBugCommand.php | 4 ++++ src/Maker/MakeSubject.php | 5 +++++ src/PathReducer/AbstractPathReducer.php | 4 ++++ 5 files changed, 25 insertions(+) diff --git a/src/Command/CaptureScreenshotsCommand.php b/src/Command/CaptureScreenshotsCommand.php index 2faa946c..40cd3373 100644 --- a/src/Command/CaptureScreenshotsCommand.php +++ b/src/Command/CaptureScreenshotsCommand.php @@ -83,6 +83,14 @@ protected function execute(InputInterface $input, OutputInterface $output) return; } + if (!$this->workflowRegistry instanceof Registry) { + throw new Exception('Can not capture screenshots: No workflows were defined'); + } + + if (!$this->filesystem instanceof Filesystem) { + throw new Exception("Can not capture screenshots: No filesystems with name 'mbt' were defined"); + } + $this->setAnonymousToken(); $path = Path::unserialize($bug->getPath()); diff --git a/src/Command/RemoveScreenshotsCommand.php b/src/Command/RemoveScreenshotsCommand.php index 57b9ff2e..9598b6fa 100644 --- a/src/Command/RemoveScreenshotsCommand.php +++ b/src/Command/RemoveScreenshotsCommand.php @@ -64,6 +64,10 @@ protected function execute(InputInterface $input, OutputInterface $output) $bugId = $input->getArgument('bug-id'); $model = $input->getArgument('model'); + if (!$this->filesystem instanceof Filesystem) { + throw new Exception("Can not remove screenshots: No filesystems with name 'mbt' were defined"); + } + $subject = $this->subjectManager->createSubject($model); $subject->setFilesystem($this->filesystem); $subject->removeScreenshots($bugId); diff --git a/src/Command/ReportBugCommand.php b/src/Command/ReportBugCommand.php index 78e4ae65..683230b1 100644 --- a/src/Command/ReportBugCommand.php +++ b/src/Command/ReportBugCommand.php @@ -77,6 +77,10 @@ protected function execute(InputInterface $input, OutputInterface $output) throw new Exception("Can not report bug: No monolog's handlers with channel 'mbt' were defined"); } + if (!$this->filesystem instanceof Filesystem) { + throw new Exception("Can not report bug: No filesystems with name 'mbt' were defined"); + } + $bugId = $input->getArgument('bug-id'); $callback = function () use ($bugId) { diff --git a/src/Maker/MakeSubject.php b/src/Maker/MakeSubject.php index b8402c14..75803e64 100644 --- a/src/Maker/MakeSubject.php +++ b/src/Maker/MakeSubject.php @@ -3,6 +3,7 @@ namespace Tienvx\Bundle\MbtBundle\Maker; use Doctrine\Common\Annotations\Annotation; +use Exception; use Symfony\Bundle\MakerBundle\ConsoleStyle; use Symfony\Bundle\MakerBundle\DependencyBuilder; use Symfony\Bundle\MakerBundle\Generator; @@ -62,6 +63,10 @@ public function configureCommand(Command $command, InputConfiguration $inputConf */ public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator) { + if (!$this->workflowRegistry instanceof Registry) { + throw new Exception('Can not make subject: No workflows were defined'); + } + $model = $input->getArgument('model'); $workflow = WorkflowHelper::get($this->workflowRegistry, $model); diff --git a/src/PathReducer/AbstractPathReducer.php b/src/PathReducer/AbstractPathReducer.php index 8256b41d..891433c2 100644 --- a/src/PathReducer/AbstractPathReducer.php +++ b/src/PathReducer/AbstractPathReducer.php @@ -101,6 +101,10 @@ public function handle(int $bugId, int $length, int $from, int $to) return; } + if (!$this->workflowRegistry instanceof Registry) { + throw new Exception('Can not handle reduce path message: No workflows were defined'); + } + $model = $bug->getTask()->getModel(); $workflow = WorkflowHelper::get($this->workflowRegistry, $model);