Test Failed
Push — master ( 741545...e25e21 )
by Julien
11:23
created

AuthController   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 26
c 1
b 0
f 0
dl 0
loc 57
ccs 0
cts 24
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B getAction() 0 33 8
A indexAction() 0 3 1
A destroyAction() 0 2 1
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 Zemit\Modules\Api\Controller;
14
use Zemit\Mvc\Controller\Identity;
15
16
/**
17
 * Class AuthController
18
 *
19
 * @author Julien Turbide <[email protected]>
20
 * @copyright Zemit Team <[email protected]>
21
 *
22
 * @since 1.0
23
 * @version 1.0
24
 *
25
 * @package Zemit\Modules\Api\Controllers
26
 */
27
class AuthController extends Controller
28
{
29
    use Identity;
0 ignored issues
show
introduced by
The trait Zemit\Mvc\Controller\Identity requires some properties which are not provided by Zemit\Modules\Api\Controllers\AuthController: $loggedIn, $saved, $stored, $reset, $loggedInAs
Loading history...
30
31
    public function indexAction($id = null)
32
    {
33
        return $this->getAction();
34
    }
35
36
    /**
37
     *
38
     */
39
    public function destroyAction() {
40
        return $this->session->destroy();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->session->destroy() targeting Phalcon\Session\ManagerInterface::destroy() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
41
    }
42
43
    /**
44
     * Create a refresh a session
45
     *
46
     * @param bool $refresh
47
     *
48
     * @return bool
49
     * @throws \Phalcon\Security\Exception
50
     */
51
    public function getAction($request = null)
52
    {
53
        $this->view->setVars($this->identity->getJwt($request === true));
0 ignored issues
show
Bug introduced by
The method setVars() does not exist on Phalcon\Mvc\ViewInterface. Did you maybe mean setVar()? ( Ignorable by Annotation )

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

53
        $this->view->/** @scrutinizer ignore-call */ 
54
                     setVars($this->identity->getJwt($request === true));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
        $this->view->setVars($this->identity->getIdentity());
55
56
        $indexLabelExpose = [false, 'email', 'label', 'labelFr', 'labelEn', 'addressId'];
57
        $expose = [
58
            'User' => [false, 'email', 'firstName', 'lastName', 'category', 'addressId', 'id', 'companyId'],
59
            'Role' => $indexLabelExpose,
60
            'Group' => $indexLabelExpose,
61
            'Type' => $indexLabelExpose,
62
        ];
63
64
        $permissions = $this->config->permissions->roles->toArray() ?? [];
0 ignored issues
show
Bug Best Practice introduced by
The property permissions does not exist on Zemit\Bootstrap\Config. Since you implemented __get, consider adding a @property annotation.
Loading history...
65
        $permissionList = ['everyone' => $permissions['everyone']['frontend'] ?? null];
66
        $vars = [];
67
        foreach (['user', 'userAs', 'roleList', 'groupList', 'typeList'] as $var) {
68
            if (is_array($this->view->$var)) {
69
                foreach ($this->view->$var as $key => $role) {
70
                    if ($role) {
71
                        $vars[$var][$key] = $role->expose($expose);
72
                        $permissionList[$key] = $permissions[$key]['frontend'] ?? null;
73
                    }
74
                }
75
            } else if ($this->view->$var) {
76
                $vars[$var] = $this->view->$var->expose($expose);
77
            }
78
        }
79
        $this->view->setVars($vars);
80
81
        $this->view->permissionList = $permissionList;
82
83
        return $this->view->saved && $this->view->stored && $this->view->validated;
84
    }
85
}
86