ReadWorkflowCommand::fire()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
1
<?php namespace Cerbero\Workflow\Console\Commands;
2
3
use Cerbero\Workflow\Repositories\PipelineRepositoryInterface;
4
use Symfony\Component\Console\Input\InputArgument;
5
use Cerbero\Workflow\Console\Drawing\Drawer;
6
use Illuminate\Console\Command;
7
8
class ReadWorkflowCommand extends Command {
9
10
	/**
11
	 * The console command name.
12
	 *
13
	 * @var string
14
	 */
15
	protected $name = 'workflow:read';
16
17
	/**
18
	 * The console command description.
19
	 *
20
	 * @var string
21
	 */
22
	protected $description = 'Show an existing workflow';
23
24
	/**
25
	 * @author	Andrea Marco Sartori
26
	 * @var		Cerbero\Workflow\Repositories\PipelineRepositoryInterface	$pipelines	Pipeline repository.
27
	 */
28
	protected $pipelines;
29
30
	/**
31
	 * @author	Andrea Marco Sartori
32
	 * @var		Cerbero\Workflow\Console\Drawing\Drawer	$drawer	The workflow drawer.
33
	 */
34
	protected $drawer;
35
36
	/**
37
	 * Set the dependencies.
38
	 *
39
	 * @param  \Cerbero\Workflow\Repositories\PipelineRepositoryInterface  $pipelines
40
	 * @param  \Cerbero\Workflow\Console\Drawing\Drawer  $drawer
41
	 * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
42
	 */
43
	public function __construct(PipelineRepositoryInterface $pipelines, Drawer $drawer)
44
	{
45
		parent::__construct();
46
47
		$this->pipelines = $pipelines;
0 ignored issues
show
Documentation Bug introduced by
It seems like $pipelines of type object<Cerbero\Workflow\...ineRepositoryInterface> is incompatible with the declared type object<Cerbero\Workflow\...ineRepositoryInterface> of property $pipelines.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
48
49
		$this->drawer = $drawer;
0 ignored issues
show
Documentation Bug introduced by
It seems like $drawer of type object<Cerbero\Workflow\Console\Drawing\Drawer> is incompatible with the declared type object<Cerbero\Workflow\...Console\Drawing\Drawer> of property $drawer.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
50
	}
51
52
	/**
53
	 * Execute the console command.
54
	 *
55
	 * @return mixed
56
	 */
57
	public function fire()
58
	{
59
		$workflow = ucfirst($this->argument('name'));
60
61
		if( ! $this->pipelines->exists($workflow))
62
		{
63
			return $this->error("The workflow [$workflow] does not exist.");
64
		}
65
66
		$this->info($this->drawer->draw($workflow));
67
	}
68
69
	/**
70
	 * Get the console command arguments.
71
	 *
72
	 * @return array
73
	 */
74
	protected function getArguments()
75
	{
76
		return [
77
			['name', InputArgument::REQUIRED, 'The name of the workflow.'],
78
		];
79
	}
80
81
}
82