DeleteWorkflowCommand::getOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php namespace Cerbero\Workflow\Console\Commands;
2
3
use Symfony\Component\Console\Input\InputOption;
4
5
class DeleteWorkflowCommand extends WorkflowGeneratorCommand {
6
7
	use DeleteIfForcedTrait;
8
9
	/**
10
	 * The console command name.
11
	 *
12
	 * @var string
13
	 */
14
	protected $name = 'workflow:delete';
15
16
	/**
17
	 * The console command description.
18
	 *
19
	 * @var string
20
	 */
21
	protected $description = 'Delete an existing workflow';
22
23
	/**
24
	 * Execute the console command.
25
	 *
26
	 * @return mixed
27
	 */
28
	public function fire()
29
	{
30
		$this->inflector->of($name = $this->getWorkflowName());
31
32
		if( ! $this->pipelines->exists($name))
33
		{
34
			return $this->error("The workflow [$name] does not exist.");
35
		}
36
37
		$this->deleteAllFilesOfWorkflowIfForced($name);
38
39
		$this->pipelines->destroy($name);
40
41
		$this->info('Workflow deleted successfully.');
42
	}
43
44
	/**
45
	 * Delete all the generated files of the given workflow if forced.
46
	 *
47
	 * @author	Andrea Marco Sartori
48
	 * @param	string	$workflow
49
	 * @return	void
50
	 */
51
	protected function deleteAllFilesOfWorkflowIfForced($workflow)
52
	{
53
		$files = $this->pipelines->getPipesByPipeline($workflow);
54
55
		$files[] = $this->inflector->getRequest();
56
57
		$files[] = $this->inflector->getJob();
58
59
		$this->deleteIfForced($files);
60
	}
61
62
	/**
63
	 * Get the console command options.
64
	 *
65
	 * @return array
66
	 */
67
	protected function getOptions()
68
	{
69
		return [
70
			['force', '-f', InputOption::VALUE_NONE, 'Delete all the generated files of a workflow.'],
71
		];
72
	}
73
74
}
75