ItemDetailForm   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
wmc 13
c 0
b 0
f 0
lcom 2
cbo 0
dl 0
loc 97
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A attached() 0 10 2
B loadHttpData() 0 12 6
A getHttpData() 0 10 2
A offsetGet() 0 4 1
A getComponent() 0 8 1
1
<?php
2
3
/**
4
 * @copyright   Copyright (c) 2015 ublaboo <[email protected]>
5
 * @author      Pavel Janda <[email protected]>
6
 * @package     Ublaboo
7
 */
8
9
namespace Ublaboo\DataGrid\Utils;
10
11
use Nette;
12
use Nette\Forms\Container;
13
14
final class ItemDetailForm extends Container
15
{
16
17
	/**
18
	 * @var callable
19
	 */
20
	private $callable_set_container;
21
22
	/**
23
	 * @var array
24
	 */
25
	private $http_post;
26
27
28
	/**
29
	 * @param callable $callable_set_container
30
	 */
31
	public function __construct(callable $callable_set_container)
32
	{
33
		parent::__construct();
34
35
		$this->monitor('Nette\Application\UI\Presenter');
36
37
		$this->callable_set_container = $callable_set_container;
38
	}
39
40
41
	/**
42
	 * @param \Nette\ComponentModel\IContainer
43
	 */
44
	protected function attached($presenter)
45
	{
46
		parent::attached($presenter);
47
48
		if (!$presenter instanceof Nette\Application\UI\Presenter) {
0 ignored issues
show
Bug introduced by
The class Nette\Application\UI\Presenter does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
49
			return;
50
		}
51
52
		$this->loadHttpData();
53
	}
54
55
56
	/**
57
	 * @return void
58
	 */
59
	public function loadHttpData()
60
	{
61
		if (!$this->getForm()->isSubmitted()) {
62
			return;
63
		}
64
65
		foreach ((array) $this->getHttpData() as $name => $value) {
66
			if ((is_array($value) || $value instanceof \Traversable) && !$this->getComponent($name, false)) {
67
				$this->getComponent($name);
68
			}
69
		}
70
	}
71
72
73
	/**
74
	 * @return mixed|NULL
75
	 */
76
	private function getHttpData()
77
	{
78
		if ($this->http_post === null) {
79
			$path = explode(self::NAME_SEPARATOR, $this->lookupPath('Nette\Forms\Form'));
80
81
			$this->http_post = Nette\Utils\Arrays::get($this->getForm()->getHttpData(), $path, null);
82
		}
83
84
		return $this->http_post;
85
	}
86
87
88
	/**
89
	 * @param  string $name
90
	 * @return Container
91
	 */
92
	public function offsetGet($name)
93
	{
94
		return $this->getComponent($name);
95
	}
96
97
98
	/**
99
	 * @param  string $name
100
	 * @return Container
101
	 */
102
	public function getComponent($name)
103
	{
104
		$container = $this->addContainer($name);
105
106
		call_user_func($this->callable_set_container, $container);
107
108
		return $container;
109
	}
110
}
111