Completed
Push — master ( b4fb45...fd4491 )
by dima
02:45
created

IndexController::add()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace Frameworkless\Controllers;
4
5
use Symfony\Component\HttpFoundation\Response;
6
use Twig_Environment;
7
use Core\Models\User\UserRepository;
8
use DebugBar\StandardDebugBar;
9
use Frameworkless\Helpers\Debug;
10
use Monolog\Logger;
11
12
class IndexController
13
{
14
15
	/**
16
	 * @var Twig_Environment
17
	 */
18
	private $twig;
19
20
	/**
21
	 *
22
	 * @var \Models\User\UserRepository $UserRepository
23
	 */
24
	protected $UserRepository;
25
26
	protected $debugbar;
27
28
	/**
29
	 * IndexController, constructed by container
30
	 *
31
	 * @param Twig_Environment $twig
32
	 */
33
	public function __construct(
34
	Twig_Environment $twig, UserRepository $UserRepository, StandardDebugBar $debugbar, Logger $logger
35
	)
36
	{
37
		$this->twig = $twig;
38
		$this->UserRepository = $UserRepository;
0 ignored issues
show
Documentation Bug introduced by
It seems like $UserRepository of type object<Core\Models\User\UserRepository> is incompatible with the declared type object<Models\User\UserRepository> of property $UserRepository.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
39
		$this->debugbar = $debugbar;
40
41
		$logger->addDebug('start work', [1, 2, 'test']);
42
	}
43
44
	/**
45
	 * Return index page (/)
46
	 *
47
	 * @param array $args
48
	 * @return Response
49
	 */
50
	public function get($args)
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
51
	{
52
		$debugbarRenderer = $this->debugbar->getJavascriptRenderer("/assets/debug_bar");
53
54
		$Users = $this->UserRepository->findMany();
55
56
		$table = \Donquixote\Cellbrush\Table\Table::create();
57
		$table->addColNames([0, 1, 2]);
58
		$table->addClass('table table-striped');
59
		$table->thead()
60
				->addRowName('head row')
61
				->th('head row', 0, 'Id')
62
				->th('head row', 1, 'Имя')
63
				->th('head row', 2, 'Email');
64
		$i = 0;
65
		foreach ($Users as $User) {
66
			$table->addRow($i)->tdMultiple([
67
				$User->getId(),
68
				$User->getName(),
69
				$User->getEmail()]);
70
			$i++;
71
		}
72
73
		return new Response($this->twig->render('pages/index.html.twig', [
74
					"table"			 => $table->render(),
75
					"debugbar_Head"	 => $debugbarRenderer->renderHead(),
76
					"debugbar_Body"	 => $debugbarRenderer->render()
77
		]));
78
	}
79
80
	public function add($args)
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
81
	{
82
83
84
		try {
85
86
87
88
89
			return new Response("success create!");
90
			
91
		} catch(\Exception $ex) {
92
			return new Response("system error:" . $ex->getMessage());
93
		}
94
	}
95
}
96