Context   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 46
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A has() 0 4 2
A get() 0 8 2
A getRequest() 0 4 1
1
<?php declare(strict_types=1);
2
3
namespace Limoncello\Auth\Authorization\PolicyInformation;
4
5
/**
6
 * Copyright 2015-2019 [email protected]
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
use Limoncello\Auth\Contracts\Authorization\PolicyInformation\ContextInterface;
22
use Limoncello\Auth\Contracts\Authorization\PolicyEnforcement\RequestInterface;
23
use Limoncello\Container\Container;
24
25
/**
26
 * @package Limoncello\Auth
27
 */
28
class Context extends Container implements ContextInterface
29
{
30
    /**
31
     * @var RequestInterface
32
     */
33
    private $request;
34
35
    /**
36
     * @param RequestInterface $request
37 33
     * @param array            $contextDefinitions
38
     */
39 33
    public function __construct(RequestInterface $request, array $contextDefinitions = [])
40
    {
41 33
        parent::__construct([RequestInterface::class => $request] + $contextDefinitions);
42
43
        $this->request = $request;
44
    }
45
46
    /**
47 26
     * @inheritdoc
48
     */
49 26
    public function has($key): bool
50
    {
51
        return parent::has($key) === true || $this->getRequest()->has($key) === true;
52
    }
53
54
    /**
55 24
     * @inheritdoc
56
     */
57 24
    public function get($key)
58 11
    {
59
        if (parent::has($key) === true) {
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (has() instead of get()). Are you sure this is correct? If so, you might want to change this to $this->has().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
60
            return parent::get($key);
61 21
        }
62
63
        return $this->getRequest()->get($key);
64
    }
65
66
    /**
67 24
     * @return RequestInterface
68
     */
69 24
    public function getRequest(): RequestInterface
70
    {
71
        return $this->request;
72
    }
73
}
74