Code Duplication    Length = 24-24 lines in 3 locations

Controller/GroupController.php 1 location

@@ 44-67 (lines=24) @@
41
		############################################################################################################
42
43
44
		if(!$key) {
45
			### CREATING A NEW OBJECT ###
46
47
			#if there are foreign objects that should be bound to this object, bind them all here
48
			foreach($foreign_objs as $fo) {
49
				$foreign_obj = $this->getDoctrine()
50
					->getRepository($fo['repo'])
51
					->find($fo['key']);
52
				if(!$foreign_obj) {
53
					$this->get('session')->getFlashBag()->add('error', sprintf("Could not find the %s", $fo['name']));
54
					return $this->redirect($request->query->get('parent', $request->request->get('parent', $request->headers->get('referer'))));
55
				}
56
				call_user_func(array($obj, $fo['method'], $foreign_obj));
57
			}
58
		} else {
59
			### EDITING AN EXISTING OBJECT ###
60
			$obj = $this->getDoctrine()
61
				->getRepository($repo)
62
				->find($key);
63
64
			if(!$obj) {
65
				$this->get('session')->getFlashBag()->add('error', sprintf("Could not find the %s", $name));
66
			}
67
		}
68
		
69
70
		##############################################  CREATE FORM  ###############################################

Controller/TenantController.php 1 location

@@ 38-61 (lines=24) @@
35
			);
36
			############################################################################################################
37
38
			if(!$key) {
39
				### CREATING A NEW OBJECT ###
40
41
				#if there are foreign objects that should be bound to this object, bind them all here
42
				foreach($foreign_objs as $fo) {
43
					$foreign_obj = $this->getDoctrine()
44
						->getRepository($fo['repo'])
45
						->find($fo['key']);
46
					if(!$foreign_obj) {
47
						$this->get('session')->getFlashBag()->add('error', sprintf("Could not find the %s", $fo['name']));
48
						return $this->redirect($request->query->get('parent', $request->request->get('parent', $request->headers->get('referer'))));
49
					}
50
					call_user_func(array($obj, $fo['method'], $foreign_obj));
51
				}
52
			} else {
53
				### EDITING AN EXISTING OBJECT ###
54
				$obj = $this->getDoctrine()
55
					->getRepository($repo)
56
					->find($key);
57
58
				if(!$obj) {
59
					$this->get('session')->getFlashBag()->add('error', sprintf("Could not find the %s", $name));
60
				}
61
			}
62
63
			##############################################  CREATE FORM  ###############################################
64
			$form = $this->createFormBuilder($obj)

Controller/UserController.php 1 location

@@ 42-65 (lines=24) @@
39
			);
40
			############################################################################################################
41
42
			if(!$key) {
43
				### CREATING A NEW OBJECT ###
44
45
				#if there are foreign objects that should be bound to this object, bind them all here
46
				foreach($foreign_objs as $fo) {
47
					$foreign_obj = $this->getDoctrine()
48
					                    ->getRepository($fo['repo'])
49
					                    ->find($fo['key']);
50
					if(!$foreign_obj) {
51
						$this->get('session')->getFlashBag()->add('error', sprintf("Could not find the %s", $fo['name']));
52
						return $this->redirect($request->query->get('parent', $request->request->get('parent', $request->headers->get('referer'))));
53
					}
54
					call_user_func(array($obj, $fo['method'], $foreign_obj));
55
				}
56
			} else {
57
				### EDITING AN EXISTING OBJECT ###
58
				$obj = $this->getDoctrine()
59
				            ->getRepository($repo)
60
				            ->find($key);
61
62
				if(!$obj) {
63
					$this->get('session')->getFlashBag()->add('error', sprintf("Could not find the %s", $name));
64
				}
65
			}
66
67
			if($this->getUser()->getTenants()->count() > 1) {
68
				$tenant_namefield = 'tenantedFullname';