EntityForm   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 4
dl 48
loc 48
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A injectEntityManager() 4 4 1
A addContainer() 7 7 1
A getEntityManager() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * EntityForm.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        https://www.ipublikuj.eu
7
 * @author         Adam Kadlec <[email protected]>
8
 * @package        iPublikuj:Forms!
9
 * @subpackage     Forms
10
 * @since          1.0.0
11
 *
12
 * @date           26.05.13
13
 */
14
15
declare(strict_types = 1);
16
17
namespace IPub\Forms\Forms;
18
19
use Doctrine\ORM;
20
21
use Nette\Application;
22
23
/**
24
 * Form with entity support
25
 *
26
 * @package        iPublikuj:Forms!
27
 * @subpackage     Forms
28
 *
29
 * @author         Adam Kadlec <[email protected]>
30
 */
31 View Code Duplication
class EntityForm extends Application\UI\Form
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
{
33
	/**
34
	 * Implement entity handling in form
35
	 */
36
	use TEntityContainer;
37
38
	/**
39
	 * Implement form methods
40
	 */
41
	use TForm;
42
43
	/**
44
	 * @var ORM\EntityManager
45
	 */
46
	private $entityManager;
47
48
	/**
49
	 * @param ORM\EntityManager $entityManager
50
	 */
51
	public function injectEntityManager(ORM\EntityManager $entityManager) : void
52
	{
53
		$this->entityManager = $entityManager;
54
	}
55
56
	/**
57
	 * Adds naming container to the form
58
	 *
59
	 * @param string $name
60
	 *
61
	 * @return EntityContainer
62
	 */
63
	public function addContainer($name) : EntityContainer
64
	{
65
		$control = new EntityContainer($this->entityManager);
66
		$control->setCurrentGroup($this->currentGroup);
67
68
		return $this[$name] = $control;
69
	}
70
71
	/**
72
	 * @return ORM\EntityManager
73
	 */
74
	protected function getEntityManager() : ORM\EntityManager
75
	{
76
		return $this->entityManager;
77
	}
78
}
79