Test Failed
Push — main ( 2b582c...894963 )
by Rafael
05:38
created

ApiController::getSecurityKey()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 16
rs 9.9666
c 1
b 0
f 0
cc 4
nc 4
nop 0
1
<?php
2
3
/* Copyright (C) 2024      Rafael San José      <[email protected]>
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 3 of the License, or
8
 * any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
namespace Alxarafe\Base\Controller;
20
21
use Alxarafe\Base\Config;
22
use CoreModules\Admin\Model\User;
23
use Firebase\JWT\JWT;
24
use Luracast\Restler\RestException;
25
26
/**
27
 * Class ApiController. The generic API controller contains what is necessary for any API controller
28
 *
29
 * @package Alxarafe\Base
30
 */
31
abstract class ApiController
32
{
33
    private static $security_key=null;
34
35
    protected static function getSecurityKey()
36
    {
37
        if (self::$security_key !== null) {
38
            return self::$security_key;
39
        }
40
41
        $config = Config::getConfig();
42
        if (!isset($config->security->jwt_secret_key)) {
43
            $config->security->jwt_secret_key = bin2hex(random_bytes(20));
44
            if (!Config::setConfig($config)) {
45
                static::badApiCall();
46
            }
47
        }
48
49
        self::$security_key = $config->security->jwt_secret_key;
50
        return self::$security_key;
51
    }
52
53
    public static function badApiCall()
54
    {
55
56
    }
57
58
    public static function jsonResponse($response, $httpCode = 200) {
0 ignored issues
show
Unused Code introduced by
The parameter $httpCode is not used and could be removed. ( Ignorable by Annotation )

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

58
    public static function jsonResponse($response, /** @scrutinizer ignore-unused */ $httpCode = 200) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $response is not used and could be removed. ( Ignorable by Annotation )

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

58
    public static function jsonResponse(/** @scrutinizer ignore-unused */ $response, $httpCode = 200) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
59
60
    }
61
}
62