AnonymousMiddleware   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 14
c 3
b 0
f 0
dl 0
loc 34
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A call() 0 25 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas\Middleware;
6
7
use Phalcon\Mvc\Micro;
0 ignored issues
show
Bug introduced by
The type Phalcon\Mvc\Micro was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
/**
10
 * Class AuthenticationMiddleware.
11
 *
12
 * @package Canvas\Middleware
13
 */
14
class AnonymousMiddleware extends AuthenticationMiddleware
15
{
16
    /**
17
     * Call me.
18
     *
19
     * @param Micro $api
20
     * @todo need to check section for auth here
21
     * @return bool
22
     */
23
    public function call(Micro $api)
24
    {
25
        $config = $api->getService('config');
26
        $request = $api->getService('request');
27
28
        $anonymousUser = false;
29
        $token = null;
30
31
        /**
32
         * This is where we will find if the user exists based on
33
         * the token passed using Bearer Authentication.
34
         */
35
        if (!empty($request->getBearerTokenFromHeader())) {
36
            $token = $this->getToken($request->getBearerTokenFromHeader());
37
        } else {
38
            $anonymousUser = true;
39
        }
40
41
        if (!$anonymousUser) {
42
            $this->sessionUser($api, $config, $token, $request);
0 ignored issues
show
Bug introduced by
It seems like $token can also be of type null; however, parameter $token of Canvas\Middleware\Authen...ddleware::sessionUser() does only seem to accept object, maybe add an additional type check? ( Ignorable by Annotation )

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

42
            $this->sessionUser($api, $config, /** @scrutinizer ignore-type */ $token, $request);
Loading history...
43
        } else {
44
            $this->anonymousUser($api, $config, $token, $request);
45
        }
46
47
        return true;
48
    }
49
}
50