GenerateGroupsCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5
Metric Value
wmc 3
lcom 0
cbo 5
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 5 1
A execute() 0 19 2
1
<?php
2
3
	namespace Vivait\AuthBundle\Command;
4
5
	use Vivait\AuthBundle\Entity\Group;
6
	use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7
	use Symfony\Component\Console\Input\InputInterface;
8
	use Symfony\Component\Console\Output\OutputInterface;
9
10
	class GenerateGroupsCommand extends ContainerAwareCommand {
11
12
		protected function configure() {
13
			$this
14
				->setName('auth:role:generate')
15
				->setDescription('Creates the standard set of roles into the database');
16
		}
17
18
19
		protected function execute(InputInterface $input, OutputInterface $output) {
20
			$em = $this->getContainer()->get('doctrine')->getManager();
21
			$array = array(
22
				array('ROLE_USER','User'),
23
				array('ROLE_ADMIN','Administrator'),
24
				array('ROLE_SUPER_ADMIN','Super Administrator'),
25
			);
26
27
			foreach($array as $row) {
28
				$obj = new Group();
29
				$obj->setRole($row[0]);
30
				$obj->setName($row[1]);
31
				$em->persist($obj);
32
				$output->writeln(sprintf('%s (%s), ', $obj->getRole(), $obj->getName()));
33
			}
34
			$em->flush();
35
36
			$output->writeln(sprintf('Created %s built-in groups/roles, ', count($array)));
37
		}
38
	}