Website   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 7
eloc 18
c 3
b 0
f 0
dl 0
loc 64
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A error() 0 4 1
A __construct() 0 3 1
A home() 0 5 1
A login() 0 26 4
1
<?php
2
3
namespace Controllers;
4
5
use CoffeeCode\Router\Router;
6
7
/**
8
 * Factory Router | Class Website [ EXAMPLE ]
9
 *
10
 * @category Examples\Controllers
11
 * @package  FactoryRouter\Examples\Controllers
12
 * @author   Thalles D. koester <[email protected]>
13
 * @license  https://choosealicense.com/licenses/mit/ MIT
14
 * @link     https://github.com/thallesdella/factory-router
15
 */
16
class Website extends Controller
17
{
18
    /**
19
     * main constructor.
20
     *
21
     * @param Router $router
22
     */
23
    public function __construct(Router $router)
24
    {
25
        parent::__construct($router);
26
    }
27
    
28
    /**
29
     * @return void
30
     */
31
    public function home(?array $data): void
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

31
    public function home(/** @scrutinizer ignore-unused */ ?array $data): void

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

Loading history...
32
    {
33
        $action = $this->router->route('website.login');
34
        $html = "<a title='Fazer Login' href='{$action}'>Fazer Login</a>";
35
        echo $html;
36
    }
37
    
38
    /**
39
     * @param array|null $data
40
     *
41
     * @return void
42
     */
43
    public function login(?array $data): void
44
    {
45
        if (isset($_SESSION['login']) && $_SESSION['login'] == true) {
46
            $this->router->redirect('app.home');
47
        }
48
    
49
        $html = '';
50
        if (!empty($data['msg'])) {
51
            $cleanMsg = filter_var(
52
                base64_decode($data['msg']),
53
                FILTER_SANITIZE_STRIPPED
54
            );
55
            $html .= "{$cleanMsg}<br><br>";
56
        }
57
        
58
        $action = $this->router->route('auth.login');
59
        $html .= "<form action='{$action}' method='post'>
60
            <label>
61
                <span>User:</span><input type='text' name='user' required>
62
            </label><br>
63
            <label>
64
                <span>Pass:</span><input type='password' name='pass' required>
65
            </label><br>
66
            <button>Submit</button></form>";
67
        
68
        echo $html;
69
    }
70
    
71
    /**
72
     * @param array $data
73
     *
74
     * @return void
75
     */
76
    public function error(array $data): void
77
    {
78
        $html = "Erro {$data['code']}";
79
        echo $html;
80
    }
81
}