Completed
Push — ezp26352-skip_csrf_check_on_re... ( 19f37a )
by
unknown
36:29
created

ResourceRouteReference   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 1
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
1
<?php
2
/**
3
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
4
 * @license For full copyright and license information view LICENSE file distributed with this source code.
5
 */
6
namespace eZ\Publish\Core\REST\Server\Values;
7
8
use eZ\Publish\API\Repository\Values\ValueObject;
9
10
/**
11
 * A reference to a REST resource route.
12
 *
13
 * @property string $route
14
 * @property array $loadParameters
15
 * @property string $mediaTypeName
16
 */
17
class ResourceRouteReference extends ValueObject
18
{
19
    /**
20
     * @var string
21
     */
22
    protected $route;
23
24
    /**
25
     * @var array
26
     */
27
    protected $loadParameters;
28
29
    /**
30
     * The media-type name (ContentInfo, Location) of the resource. If null, the default will be used.
31
     * @var null
32
     */
33
    protected $mediaTypeName;
34
35
    /**
36
     * ResourceRouteReference constructor.
37
     * @param array $route
38
     * @param $loadParameters
39
     * @param string $mediaType The media-type name (ContentInfo, Location) of the resource. If null, the default will be used.
40
     */
41
    public function __construct($route, $loadParameters, $mediaType = null)
42
    {
43
        $this->route = $route;
0 ignored issues
show
Documentation Bug introduced by
It seems like $route of type array is incompatible with the declared type string of property $route.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

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

Loading history...
44
        $this->loadParameters = $loadParameters;
45
        $this->mediaTypeName = $mediaType;
0 ignored issues
show
Documentation Bug introduced by
It seems like $mediaType can also be of type string. However, the property $mediaTypeName is declared as type null. 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...
46
    }
47
}
48