AppController::isAuthorized()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 8
ccs 0
cts 4
cp 0
crap 12
rs 10
1
<?php
0 ignored issues
show
Coding Style introduced by
The PHP open tag does not have a corresponding PHP close tag
Loading history...
Coding Style introduced by
This file is missing a doc comment.
Loading history...
Coding Style introduced by
Class found in ".php" file; use ".inc" extension instead
Loading history...
Coding Style introduced by
Filename "AppController.php" doesn't match the expected filename "appcontroller.php"
Loading history...
2
3
declare(strict_types=1);
0 ignored issues
show
Coding Style introduced by
Header blocks must be separated by a single blank line
Loading history...
4
/**
0 ignored issues
show
Coding Style introduced by
The file-level docblock must follow the opening PHP tag in the file header
Loading history...
Coding Style introduced by
Inline doc block comments are not allowed; use "/* Comment */" or "// Comment" instead
Loading history...
Coding Style introduced by
Block comments must be started with /*
Loading history...
5
 * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
6
 * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
0 ignored issues
show
introduced by
Doc comment short description must be on a single line, further text should be a separate paragraph
Loading history...
7
 *
8
 * Licensed under The MIT License
9
 * For full copyright and license information, please see the LICENSE.txt
10
 * Redistributions of files must retain the above copyright notice.
11
 *
12
 * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
13
 * @link      https://cakephp.org CakePHP(tm) Project
0 ignored issues
show
introduced by
Tag value indented incorrectly; expected 1 space but found 6
Loading history...
Coding Style introduced by
The tag in position 2 should be the @license tag
Loading history...
14
 * @since     0.2.9
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @link tag
Loading history...
introduced by
Tag value indented incorrectly; expected 1 space but found 5
Loading history...
15
 * @license   https://opensource.org/licenses/mit-license.php MIT License
0 ignored issues
show
introduced by
Tag value indented incorrectly; expected 1 space but found 3
Loading history...
Coding Style introduced by
The tag in position 4 should be the @since tag
Loading history...
16
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
PHP version not specified
Loading history...
17
18
namespace App\Controller;
19
20
use Cake\Controller\Controller;
21
use Cake\Event\EventInterface;
22
23
/**
24
 * Application Controller
25
 *
26
 * Add your application-wide methods in the class below, your controllers
27
 * will inherit them.
28
 *
29
 * @link https://book.cakephp.org/4/en/controllers.html#the-app-controller
30
 */
0 ignored issues
show
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @category tag in class comment
Loading history...
31
class AppController extends Controller {
0 ignored issues
show
Coding Style introduced by
Opening brace of a class must be on the line after the definition
Loading history...
32
33
    /**
34
     * Initialization hook method.
35
     *
36
     * Use this method to add common initialization code like loading components.
0 ignored issues
show
introduced by
Line exceeds 80 characters; contains 81 characters
Loading history...
37
     *
38
     * e.g. `$this->loadComponent('FormProtection');`
39
     *
40
     * @return void
0 ignored issues
show
introduced by
If there is no return value for a function, there must not be a @return tag.
Loading history...
41
     */
42 19
    public function initialize(): void {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on a new line
Loading history...
43 19
        parent::initialize();
44
45 19
        $this->loadComponent('RequestHandler');
46 19
        $this->loadComponent('Flash');
47 19
        $this->loadComponent('Security');
48 19
        $this->loadComponent('Authentication.Authentication');
49 19
        $this->Authentication->allowUnauthenticated(['login', 'logout']);
50 19
    }
51
52
    public function isAuthorized($user) {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function isAuthorized()
Loading history...
introduced by
Missing function doc comment
Loading history...
Coding Style introduced by
Opening brace should be on a new line
Loading history...
53
        // Admin can access every action
0 ignored issues
show
introduced by
Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
Loading history...
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
54
        if (isset($user['role']) && $user['role'] === 'admin') {
55
            return true;
56
        }
57
58
        // Default permit
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
introduced by
Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
Loading history...
59
        return true;
60
    }
61
62
    /**
63
     * Before render callback.
64
     *
65
     * @param \Cake\Event\Event $event The beforeRender event.
0 ignored issues
show
introduced by
Parameter comment must be on the next line
Loading history...
66
     * @return \Cake\Network\Response|null|void
0 ignored issues
show
introduced by
@return doc comment specified, but function has no return statement
Loading history...
introduced by
Separate the @param and @return sections by a blank line.
Loading history...
67
     */
68 15
    public function beforeRender(EventInterface $event) {
0 ignored issues
show
Coding Style introduced by
The method parameter $event is never used
Loading history...
introduced by
Expected type hint "Event"; found "EventInterface" for $event
Loading history...
Coding Style introduced by
Opening brace should be on a new line
Loading history...
69 15
        if (!array_key_exists('_serialize', $this->viewBuilder()->getVars()) &&
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
Coding Style introduced by
The first expression of a multi-line control structure must be on the line after the opening parenthesis
Loading history...
70 15
                in_array($this->response->getType(), ['application/json', 'application/xml'])
0 ignored issues
show
Coding Style introduced by
Multi-line IF statement not indented correctly; expected 12 spaces but found 16
Loading history...
Coding Style introduced by
Each line in a multi-line IF statement must begin with a boolean operator
Loading history...
71
        ) {
72
            $this->set('_serialize', true);
73
        }
74 15
    }
75
76
}
77