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

AuthController::indexAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 1
c 1
b 1
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
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