Passed
Push — master ( c5ae54...f38dde )
by Fran
02:16
created

AdminServices::parseLogLine()   B

Complexity

Conditions 10
Paths 135

Size

Total Lines 40
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 110

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 10
eloc 29
c 3
b 0
f 0
nc 135
nop 2
dl 0
loc 40
ccs 0
cts 28
cp 0
crap 110
rs 7.375

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace PSFS\services;
4
5
use PSFS\base\config\Config;
6
use PSFS\base\Security;
7
use PSFS\base\Service;
8
9
class AdminServices extends Service
10
{
11
12
    /**
13
     * @Injectable
14
     * @var \PSFS\base\config\Config Servicio de configuración
15
     */
16
    protected $config;
17
    /**
18
     * @Injectable
19
     * @var \PSFS\base\Security Servicio de autenticación
20
     */
21
    protected $security;
22
    /**
23
     * @Injectable
24
     * @var \PSFS\base\Template Servicio de gestión de plantillas
25
     */
26
    protected $tpl;
27
28
    /**
29
     * Servicio que devuelve las cabeceras de autenticación
30
     * @return string HTML
31
     */
32
    public function setAdminHeaders()
33
    {
34
        $platform = trim(Config::getInstance()->get('platform.name'));
35
        header('HTTP/1.1 401 Unauthorized');
36
        header('WWW-Authenticate: Basic Realm="' . $platform . '"');
37
        echo t('Zona restringida');
38
        exit();
39
    }
40
41
    /**
42
     * Servicio que devuelve los administradores de la plataforma
43
     * @return array|mixed
44
     */
45 1
    public function getAdmins()
46
    {
47 1
        $admins = $this->security->getAdmins();
48 1
        if (!empty($admins)) {
49
            if (!$this->security->checkAdmin()) {
50
                $this->setAdminHeaders();
51
            }
52
        }
53 1
        $this->parseAdmins($admins);
54 1
        return $admins;
55
    }
56
57
    /**
58
     * Servicio que parsea los administradores para mostrarlos en la gestión de usuarios
59
     * @param array $admins
60
     */
61 1
    private function parseAdmins(&$admins)
62
    {
63 1
        if (!empty($admins)) {
64
            foreach ($admins as &$admin) {
65
                if (isset($admin['profile'])) {
66
                    switch ($admin['profile']) {
67
                        case Security::MANAGER_ID_TOKEN:
68
                            $admin['class'] = 'warning';
69
                            break;
70
                        case Security::ADMIN_ID_TOKEN:
71
                            $admin['class'] = 'info';
72
                            break;
73
                        default:
74
                        case Security::USER_ID_TOKEN:
75
                            $admin['class'] = 'primary';
76
                            break;
77
                    }
78
                } else {
79
                    $admin['class'] = 'primary';
80
                }
81
            }
82
        }
83 1
    }
84
85
}
86