Test Failed
Push — develop ( 50f9bb...e90cf2 )
by nguereza
02:33
created

HomeAction   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 14 2
A __construct() 0 18 1
1
<?php
2
3
namespace Platine\Framework\Demo\Action;
4
5
use Platine\Cache\CacheInterface;
6
use Platine\Config\Config;
7
use Platine\Cookie\CookieManagerInterface;
8
use Platine\Framework\App\Application;
9
use Platine\Framework\Demo\Repository\UserRepository;
10
use Platine\Framework\Demo\Response\RedirectResponse;
11
use Platine\Framework\Demo\Response\TemplateResponse;
12
use Platine\Http\Handler\RequestHandlerInterface;
13
use Platine\Http\ResponseInterface;
14
use Platine\Http\ServerRequestInterface;
15
use Platine\Logger\LoggerInterface;
16
use Platine\Session\Session;
17
use Platine\Template\Template;
18
19
/**
20
 * Description of HomeAction
21
 *
22
 * @author tony
23
 */
24
class HomeAction implements RequestHandlerInterface
25
{
26
27
    protected LoggerInterface $logger;
28
    protected Application $app;
29
    protected Config $config;
30
    protected Session $session;
31
    protected UserRepository $userRepository;
32
    protected Template $template;
33
    protected CookieManagerInterface $cookieManager;
34
    protected CacheInterface $cache;
35
36
37
    public function __construct(
38
        LoggerInterface $logger,
39
        Application $app,
40
        Config $config,
41
        Session $session,
42
        Template $template,
43
        UserRepository $userRepository,
44
        CookieManagerInterface $cookieManager,
45
        CacheInterface $cache
46
    ) {
47
        $this->logger = $logger;
48
        $this->app = $app;
49
        $this->config = $config;
50
        $this->session = $session;
51
        $this->userRepository = $userRepository;
52
        $this->template = $template;
53
        $this->cookieManager = $cookieManager;
54
        $this->cache = $cache;
55
    }
56
57
    public function handle(ServerRequestInterface $request): ResponseInterface
58
    {
59
        $user = $this->session->get('user');
60
        if (!$user) {
61
            $this->logger->info('User not yet login');
62
63
            return (new RedirectResponse('login'))->redirect();
64
        }
65
66
        return new TemplateResponse(
67
            $this->template,
68
            'home',
69
            [
70
                'user' => $user,
71
            ]
72
        );
73
    }
74
}
75