TwoFactorAuthComponent   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 1
cbo 5
dl 0
loc 29
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A isAuthorized() 0 19 2
1
<?php
2
namespace App\Controller\Component;
3
4
use Cake\Controller\Component;
5
use Cake\ORM\TableRegistry;
6
7
class TwoFactorAuthComponent extends Component
8
{
9
    /**
10
     * Check if the current user session is the same as the saved session.
11
     *
12
     * @param int $user The user id.
13
     *
14
     * @return bool
15
     */
16
    public function isAuthorized($user)
17
    {
18
        $session = $this->request->clientIp() . $this->request->header('User-Agent') . gethostbyaddr($this->request->clientIp());
0 ignored issues
show
Deprecated Code introduced by
The property Cake\Controller\Component::$request has been deprecated with message: 3.4.0 Storing references to the request is deprecated. Use Component::getController() or callback $event->getSubject() to access the controller & request instead.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
Deprecated Code introduced by
The method Cake\Http\ServerRequest::header() has been deprecated with message: 4.0.0 The automatic fallback to env() will be removed in 4.0.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
19
20
        $this->UsersTwoFactorAuth = TableRegistry::get('UsersTwoFactorAuth');
0 ignored issues
show
Bug introduced by
The property UsersTwoFactorAuth does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
21
22
        $tfa = $this->UsersTwoFactorAuth
23
            ->find()
24
            ->where([
25
                'user_id' => $user
26
            ])
27
            ->first();
28
29
        if (is_null($tfa)) {
30
            return false;
31
        }
32
33
        return $tfa->session === $session;
34
    }
35
}
36