Passed
Push — master ( 4feda1...7cf784 )
by Fran
07:47
created

Admin::staticAdminLogon()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 6.7968

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 14
nc 3
nop 1
dl 0
loc 19
ccs 3
cts 12
cp 0.25
crap 6.7968
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace PSFS\controller\base;
4
5
use PSFS\base\config\Config;
6
use PSFS\base\config\LoginForm;
7
use PSFS\base\Router;
8
use PSFS\base\Template;
9
use PSFS\base\types\AuthAdminController;
10
use PSFS\controller\UserController;
11
use PSFS\services\AdminServices;
12
13
/**
14
 * Class Admin
15
 * @package PSFS\controller
16
 * @domain ROOT
17
 */
18
abstract class Admin extends AuthAdminController
19
{
20
21
    const DOMAIN = 'ROOT';
22
23
    /**
24
     * @Inyectable
25
     * @var \PSFS\base\config\Config Configuration service
26
     */
27
    protected $config;
28
    /**
29
     * @Inyectable
30
     * @var \PSFS\services\AdminServices Admin service
31
     */
32
    protected $srv;
33
34
    /**
35
     * Wrapper de asignación de los menus
36
     * @return array
37
     */
38
    protected function getMenu()
39
    {
40
        return Router::getInstance()->getAdminRoutes();
41
    }
42
43
    /**
44
     * Método estático de login de administrador
45
     * @param string $route
0 ignored issues
show
Documentation introduced by
Should the type for parameter $route not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
46
     * @return string HTML
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
47
     * @throws \PSFS\base\exception\FormException
48
     */
49 1
    public static function staticAdminLogon($route = null)
50
    {
51 1
        if (file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json')) {
52
            if ('login' !== Config::getInstance()->get('admin_login')) {
53
                return AdminServices::getInstance()->setAdminHeaders();
54
            } else {
55
                $form = new LoginForm();
56
                $form->setData(array("route" => $route));
57
                $form->build();
58
                $tpl = Template::getInstance();
59
                $tpl->setPublicZone(true);
60
                return $tpl->render("login.html.twig", array(
61
                    'form' => $form,
62
                ));
63
            }
64
        } else {
65 1
            return UserController::showAdminManager();
66
        }
67
    }
68
69
    /**
70
     * Método que gestiona el menú de administración
71
     * @GET
72
     * @route /admin
73
     * @visible false
74
     * @return string|null
75
     */
76
    public function index()
77
    {
78
        return $this->render("index.html.twig");
79
    }
80
81
}
82