Completed
Push — master ( ec69f1...484704 )
by dima
02:53
created

IndexController::add()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 2
eloc 8
nc 3
nop 1
1
<?php
2
3
namespace Frameworkless\Controllers;
4
5
use Symfony\Component\HttpFoundation\Response;
6
use Twig_Environment;
7
use Models\User\Base\UserQuery;
8
use Symfony\Component\VarDumper\VarDumper;
9
10
use Models\User\UserRepo;
11
12
class IndexController
13
{
14
15
    /**
16
     * @var Twig_Environment
17
     */
18
    private $twig;
19
20
    /**
21
     *
22
     * @var \Models\User\UserRepo $UserRepo
23
     */
24
    protected $UserRepo;
25
    
26
    /**
27
     * IndexController, constructed by container
28
     *
29
     * @param Twig_Environment $twig
30
     */
31
    public function __construct(Twig_Environment $twig, UserRepo $UserRepo)
32
    {
33
        $this->twig     = $twig;
34
        $this->UserRepo = $UserRepo;
35
    }
36
37
    /**
38
     * Return index page (/)
39
     *
40
     * @param array $args
41
     * @return Response
42
     */
43
    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...
44
    {
45
46
        $Users = $this->UserRepo->findMany();
47
48
        $table = \Donquixote\Cellbrush\Table\Table::create();
49
        $table->addColNames([0, 1, 2]);
50
        $table->addClass('table table-striped');
51
        $table->thead()
52
                ->addRowName('head row')
53
                ->th('head row', 0, 'Id')
54
                ->th('head row', 1, 'Имя')
55
                ->th('head row', 2, 'Email');
56
        $i = 0;
57
        foreach ($Users as $User) {
58
            $table->addRow($i)->tdMultiple([
59
                $User->getId(),
60
                $User->getName(),
61
                $User->getEmail()]);
62
            $i++;
63
        }
64
65
        return new Response($this->twig->render('pages/index.html.twig',[
66
            "table" => $table->render()
67
        ]));
68
    }
69
    
70
    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...
71
        
72
        $User = $this->UserRepo->build();
73
        $User->setEmail('email.ru');
74
        //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...
75
        
76
        try{
77
            $this->UserRepo->save($User);
78
            return new Response("success create!");
79
        } catch (\Exception $ex) {
80
            return new Response("system error:" . $ex->getMessage());
81
        }
82
        
83
        
84
    }
85
}
86