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

SeedCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 0
cbo 5
dl 0
loc 39
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 18 1
B execute() 0 16 5
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