Passed
Branch master (74ff72)
by Charles
02:25
created

YRC::getUserClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace yrc\components;
4
5
use Yii;
0 ignored issues
show
Bug introduced by
The type Yii 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...
6
use yii\base\BaseObject;
0 ignored issues
show
Bug introduced by
The type yii\base\BaseObject 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...
7
8
/**
9
 * Yii2 Rest Component 
10
 * @class YRC
11
 */
12
class YRC extends BaseObject
13
{
14
    /**
15
     * The access header
16
     * If set access to controller actions is granted if and only if the HTTP header value
17
     * identified by this parameters equals the $accessHeaderSecret property
18
     * @return mixed
19
     */
20
    public $accessHeader;
21
22
    /**
23
     * The access header secret value
24
     * @return mixed
25
     */
26
    public $accessHeaderSecret;
27
28
    /**
29
     * Helper method to check the access header
30
     * @return boolean
31
     */
32
    public function checkAccessHeader($request)
33
    {
34
        // Both the access header and access header secret must be set for this check to validate
35
        if ($this->accessHeader === null || $this->accessHeaderSecret === null) {
36
            return true;
37
        }
38
39
        // Fetch the access header from the request
40
        $header = $request->getHeaders()->get($this->accessHeader);
41
42
        // Allow if the header values match
43
        if (\hash_equals($this->accessHeaderSecret, $header)) {
44
            return true;
45
        }
46
        
47
        // Deny by default
48
        return false;
49
    }
50
}
51