Passed
Pull Request — develop (#2)
by AD
01:29
created

ForbiddenException   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
eloc 7
dl 0
loc 39
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setResult() 0 5 1
A getResult() 0 3 1
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
5
 * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
6
 *
7
 * Licensed under The MIT License
8
 * For full copyright and license information, please see the LICENSE.txt
9
 * Redistributions of files must retain the above copyright notice.
10
 *
11
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
12
 * @link          https://cakephp.org CakePHP(tm) Project
13
 * @since         1.0.0
14
 * @license       https://opensource.org/licenses/mit-license.php MIT License
15
 */
16
17
namespace Phauthentic\Authorization\Exception;
18
19
use Phauthentic\Authorization\Policy\ResultInterface;
20
21
/**
22
 * Forbidden Exception
23
 */
24
class ForbiddenException extends Exception
25
{
26
    /**
27
     * {@inheritDoc}
28
     */
29
    protected $code = 403;
30
31
    /**
32
     * {@inheritDoc}
33
     */
34
    protected $messageTemplate = 'Identity is not authorized to perform `%s` on `%s`.';
35
    /**
36
     * Policy check result.
37
     *
38
     * @var \ Phauthentic\Authorization\Policy\ResultInterface|null
39
     */
40
    protected $result;
41
42
    /**
43
     * Returns policy check result if passed to the exception.
44
     *
45
     * @param \Phauthentic\Authorization\Policy\ResultInterface|null $result Result
46
     * @return $this
47
     */
48
    public function setResult(?ResultInterface $result)
49
    {
50
        $this->result = $result;
0 ignored issues
show
Documentation Bug introduced by
It seems like $result can also be of type Phauthentic\Authorization\Policy\ResultInterface. However, the property $result is declared as type . Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
51
52
        return $this;
53
    }
54
55
    /**
56
     * Returns policy check result if passed to the exception.
57
     *
58
     * @return \Phauthentic\Authorization\Policy\ResultInterface|null
59
     */
60
    public function getResult(): ?ResultInterface
61
    {
62
        return $this->result;
63
    }
64
}
65