Passed
Push — master ( bda737...e0ed8e )
by Nils
09:32
created

Operation::verifyJwt()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 16
rs 9.9666
1
<?php
2
/**
3
 * Teampass - a collaborative passwords manager.
4
 * ---
5
 * This library is distributed in the hope that it will be useful,
6
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8
 * ---
9
 *
10
 * @project   Teampass API
11
 *
12
 * @file      Operation.php
13
 * ---
14
 *
15
 * @author    Nils Laumaillé ([email protected])
16
 *
17
 * @copyright 2009-2022 Teampass.net
18
 *
19
 * @license   https://spdx.org/licenses/GPL-3.0-only.html#licenseText GPL-3.0
20
 * ---
21
 *
22
 * @see       https://www.teampass.net
23
 */
24
25
class Operation
26
{
27
    public function verifyJwt($jwt)
28
    {
29
        include_once PROJECT_ROOT_PATH . '/../includes/libraries/Firebase/JWT/JWT.php';
30
        $JWT = new Firebase\JWT\JWT();
31
32
        try {
33
            $decoded = $JWT->decode($jwt, DB_PASSWD, array('HS256'));
0 ignored issues
show
Unused Code introduced by
The assignment to $decoded is dead and can be removed.
Loading history...
Unused Code introduced by
The call to Firebase\JWT\JWT::decode() has too many arguments starting with array('HS256'). ( Ignorable by Annotation )

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

33
            /** @scrutinizer ignore-call */ 
34
            $decoded = $JWT->decode($jwt, DB_PASSWD, array('HS256'));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
34
    
35
            // Access is granted.    
36
            return array(
37
                "message" => "Access granted:",
38
                "error" => $e->getMessage()
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $e seems to be never defined.
Loading history...
39
            );
40
    
41
        }catch (Exception $e) {    
42
            return false;
43
        }
44
    }
45
}