Passed
Push — master ( 750b2b...2c58c8 )
by Julien
05:58
created

AuthController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 2 Features 0
Metric Value
wmc 6
eloc 22
dl 0
loc 44
ccs 0
cts 21
cp 0
rs 10
c 2
b 2
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getAction() 0 31 6
1
<?php
2
/**
3
 * This file is part of the Zemit Framework.
4
 *
5
 * (c) Zemit Team <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE.txt
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Zemit\Modules\Api\Controllers;
12
13
use Phalcon\Http\ResponseInterface;
14
use Zemit\Mvc\Controller\Identity;
15
16
class AuthController extends AbstractController
17
{
18
    use Identity {
19
        getAction as traitGetAction;
20
    }
21
    
22
    /**
23
     * Create a refresh a session
24
     *
25
     * @param bool $refresh
26
     *
27
     * @return bool
28
     */
29
    public function getAction($refresh = false): ResponseInterface
30
    {
31
        $ret = $this->traitGetAction($refresh);
32
        
33
        $indexLabelExpose = [false, 'email', 'label'];
34
        $expose = [
35
            'User' => [false, 'id', 'email', 'firstName', 'lastName'],
36
            'Role' => $indexLabelExpose,
37
            'Group' => $indexLabelExpose,
38
            'Type' => $indexLabelExpose,
39
        ];
40
        
41
        // @todo review this
42
        $permissions = $this->config->path('permissions.roles', []);
43
        $view = ['permissionList' => ['everyone' => $permissions['everyone']['frontend'] ?? null]];
44
        foreach (['user', 'userAs', 'roleList', 'groupList', 'typeList'] as $var) {
45
            if (is_array($this->view->$var)) {
46
                foreach ($this->view->$var as $key => $role) {
47
                    if ($role) {
48
                        $view[$var][$key] = $role->expose($expose);
49
                        $view['permissionList'][$key] = $permissions[$key]['frontend'] ?? null;
50
                    }
51
                }
52
            }
53
            else if ($this->view->$var) {
54
                $view[$var] = $this->view->$var->expose($expose);
55
            }
56
        }
57
        $this->view->setVars($view);
58
        
59
        return $ret;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $ret returns the type boolean which is incompatible with the type-hinted return Phalcon\Http\ResponseInterface.
Loading history...
60
    }
61
}
62
63