Completed
Push — master ( 5afb5d...6dae66 )
by dima
05:53
created

IndexController::add()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
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 26
rs 8.8571
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
11
class IndexController
12
{
13
14
    /**
15
     * @var Twig_Environment
16
     */
17
    private $twig;
18
19
    /**
20
     *
21
     * @var \Models\User\UserRepository $UserRepository
22
     */
23
    protected $UserRepository;
24
25
	
26
	protected $debugbar;
27
28
29
	/**
30
     * IndexController, constructed by container
31
     *
32
     * @param Twig_Environment $twig
33
     */
34
    public function __construct(
35
			Twig_Environment $twig, 
36
			UserRepository $UserRepository,
37
			StandardDebugBar $debugbar
38
			)
39
    {
40
        $this->twig = $twig;
41
        $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...
42
		$this->debugbar = $debugbar;
43
    }
44
45
    /**
46
     * Return index page (/)
47
     *
48
     * @param array $args
49
     * @return Response
50
     */
51
    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...
52
    {
53
		$debugbarRenderer = $this->debugbar->getJavascriptRenderer("/assets/debug_bar");
54
55
		$this->debugbar["messages"]->addMessage("hello world!");
56
		
57
        $Users = $this->UserRepository->findMany();
58
59
        $table = \Donquixote\Cellbrush\Table\Table::create();
60
        $table->addColNames([0, 1, 2]);
61
        $table->addClass('table table-striped');
62
        $table->thead()
63
                ->addRowName('head row')
64
                ->th('head row', 0, 'Id')
65
                ->th('head row', 1, 'Имя')
66
                ->th('head row', 2, 'Email');
67
        $i = 0;
68
        foreach ($Users as $User) {
69
            $table->addRow($i)->tdMultiple([
70
                $User->getId(),
71
                $User->getName(),
72
                $User->getEmail()]);
73
            $i++;
74
        }
75
76
        return new Response($this->twig->render('pages/index.html.twig', [
77
                    "table"			=> $table->render(),
78
					"debugbar_Head"	=>	$debugbarRenderer->renderHead(),
79
					"debugbar_Body"	=>	$debugbarRenderer->render()
80
        ]));
81
    }
82
83
    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...
84
    {
85
86
	
87
		
88
       // $User = $this->UserRepository->build();
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
89
        //$User->setEmail('email.ru');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
90
        //VarDumper::dump($User);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
91
92
        try {
93
            //$this->UserRepository->save($User);
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
94
			
95
			//Faker
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
96
//			$generator = \Faker\Factory::create();
97
//			$populator = new \Faker\ORM\Propel2\Populator($generator);
98
//			$populator->addEntity('Core\Models\User\User', 5);
99
//			$insertedPKs = $populator->execute();				
100
			
101
			
102
			
103
			
104
            return new Response("success create!");
105
        } catch(\Exception $ex) {
106
            return new Response("system error:" . $ex->getMessage());
107
        }
108
    }
109
}
110