Completed
Push — master ( b6e961...8692a9 )
by Abdelrahman
15:05 queued 12:57
created

GenericException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 3
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Fort\Exceptions;
6
7
use Exception;
8
9
class GenericException extends Exception
10
{
11
    /**
12
     * The exception inputs.
13
     *
14
     * @var array
15
     */
16
    protected $inputs;
17
18
    /**
19
     * The exception redirection.
20
     *
21
     * @var string
22
     */
23
    protected $redirection;
24
25
    /**
26
     * Create a new authorization exception.
27
     *
28
     * @param string $message
29
     * @param array  $redirection
0 ignored issues
show
Documentation introduced by
Should the type for parameter $redirection not be array|null? Also, consider making the array more specific, something like array<String>, or String[].

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive. In addition it looks for parameters that have the generic type array and suggests a stricter type like array<String>.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
30
     */
31
    public function __construct($message = 'This action is unauthorized.', $redirection = null, array $inputs = null)
32
    {
33
        parent::__construct($message);
34
35
        $this->inputs = $inputs;
0 ignored issues
show
Documentation Bug introduced by
It seems like $inputs can be null. However, the property $inputs is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
36
        $this->redirection = $redirection;
0 ignored issues
show
Documentation Bug introduced by
It seems like $redirection can also be of type array. However, the property $redirection is declared as type string. 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...
37
    }
38
39
    /**
40
     * Gets the Exception redirection.
41
     *
42
     * @return string
43
     */
44
    final public function getRedirection()
45
    {
46
        return $this->redirection;
47
    }
48
49
    /**
50
     * Gets the Exception inputs.
51
     *
52
     * @return array
53
     */
54
    final public function getInputs()
55
    {
56
        return $this->inputs;
57
    }
58
}
59