Completed
Push — master ( b4fb45...fd4491 )
by dima
02:45
created

SeedCommand::execute()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 16
rs 8.8571
cc 5
eloc 10
nc 3
nop 2
1
<?php
2
3
namespace Frameworkless\Console\Commands;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Symfony\Component\Console\Input\InputDefinition;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\VarDumper\VarDumper;
12
13
/**
14
 * Description of HelloWorldCommand
15
 *
16
 * @author Dmitriy
17
 */
18
class SeedCommand extends Command
19
{
20
21
	protected function configure()
22
	{
23
		$this->setName('seed:build')
24
				->setDescription('Create seeds data')
25
				->setDefinition(
26
						new InputDefinition(array(
27
					new InputOption('class', 'c', InputOption::VALUE_REQUIRED),
28
					new InputOption('amount', 'a', InputOption::VALUE_OPTIONAL)
29
						))
30
		);
31
		$this->setName('seed:reset')
32
				->setDescription('Reset seeds data')
33
				->setDefinition(
34
						new InputDefinition(array(
35
					new InputOption('class', 'c', InputOption::VALUE_REQUIRED)
36
						))
37
		);
38
	}
39
40
	protected function execute(InputInterface $input, OutputInterface $output)
41
	{
42
	
43
		if (!$class = $input->getOption('class')) {
44
			$output->writeln("Model not set");
45
			return;
46
		}
47
48
		if ($input->getArgument('command') == "seed:reset" && $class::reset()) {
49
			$output->writeln(sprintf("Seed %s reset success!", $class));
50
		} else {
51
			$number = $input->getOption('amount');
52
			$class::build($number > 1 ? $number : 1);
53
			$output->writeln(sprintf("Seed %s amount %s create success!", $class, $number));
54
		}
55
	}
56
}
57