Completed
Push — master ( e43ea6...048027 )
by Adam
03:04
created

EntityContainer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 1
cbo 2
dl 37
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A addContainer() 7 7 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
 * EntityContainer.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        http://www.ipublikuj.eu
7
 * @author         Adam Kadlec http://www.ipublikuj.eu
8
 * @package        iPublikuj:Forms!
9
 * @subpackage     Forms
10
 * @since          1.0.0
11
 *
12
 * @date           10.01.16
13
 */
14
15
declare(strict_types = 1);
16
17
namespace IPub\Forms\Forms;
18
19
use Doctrine\ORM;
20
21
use Nette;
22
use Nette\Forms;
23
24
/**
25
 * Form container with entity support
26
 *
27
 * @package        iPublikuj:Forms!
28
 * @subpackage     Forms
29
 *
30
 * @author         Adam Kadlec <[email protected]>
31
 */
32 View Code Duplication
class EntityContainer extends Forms\Container
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...
33
{
34
	/**
35
	 * Implement entity handling in form
36
	 */
37
	use TEntityContainer;
38
39
	/**
40
	 * @var ORM\EntityManager
41
	 */
42
	private $entityManager;
43
44
	/**
45
	 * @param ORM\EntityManager $entityManager
46
	 */
47
	public function __construct(ORM\EntityManager $entityManager)
48
	{
49
		parent::__construct();
50
51
		$this->entityManager = $entityManager;
52
	}
53
54
	/**
55
	 * Adds naming container to the form
56
	 *
57
	 * @param string $name
58
	 *
59
	 * @return EntityContainer
60
	 */
61
	public function addContainer($name) : EntityContainer
62
	{
63
		$control = new self($this->entityManager);
64
		$control->setCurrentGroup($this->currentGroup);
65
66
		return $this[$name] = $control;
67
	}
68
}
69