EntityExample::getBoo()   A
last analyzed

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
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * Copyright (C) 2018 Gerrit Addiks.
4
 * This package (including this file) was released under the terms of the GPL-3.0.
5
 * You should have received a copy of the GNU General Public License along with this program.
6
 * If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy.
7
 * @license GPL-3.0
8
 * @author Gerrit Addiks <[email protected]>
9
 */
10
11
namespace Addiks\RDMBundle\Tests\Hydration;
12
13
use Addiks\RDMBundle\Tests\Hydration\ServiceExample;
14
use Addiks\RDMBundle\Tests\ValueObjectExample;
15
16
class EntityExample
17
{
18
19
    /**
20
     * @var string
21
     */
22
    public $id;
23
24
    /**
25
     * @var string
26
     */
27
    private $secondId;
28
29
    /**
30
     * @var ServiceExample
31
     */
32
    public $foo;
33
34
    /**
35
     * @var ServiceExample
36
     */
37
    public $bar;
38
39
    /**
40
     * @var string
41
     */
42
    public $baz;
43
44
    /**
45
     * @var string
46
     */
47
    private $faz;
48
49
    /**
50
     * @var null|ValueObjectExample
51
     */
52
    public $boo;
53
54
    /**
55
     * @var null|mixed
56
     */
57
    public $abc;
58
59
    /**
60
     * @var null|mixed
61
     */
62
    public $def;
63
64
    /**
65
     * @var null|array
66
     */
67
    public $arr;
68
69
    public function __construct(
70
        ServiceExample $foo = null,
71
        ServiceExample $bar = null,
72
        ServiceExample $baz = null,
73
        ServiceExample $faz = null,
74
        ValueObjectExample $boo = null,
75
        string $secondId = null
76
    ) {
77
        $this->foo = $foo;
78
        $this->bar = $bar;
79
        $this->baz = $baz;
0 ignored issues
show
Documentation Bug introduced by
It seems like $baz can also be of type Addiks\RDMBundle\Tests\Hydration\ServiceExample. However, the property $baz 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...
80
        $this->faz = $faz;
0 ignored issues
show
Documentation Bug introduced by
It seems like $faz can also be of type Addiks\RDMBundle\Tests\Hydration\ServiceExample. However, the property $faz 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...
81
        $this->boo = $boo;
82
        $this->secondId = $secondId;
83
    }
84
85
    public static $staticMetadata;
86
87
    public static function loadRDMMetadata()
88
    {
89
        return self::$staticMetadata;
90
    }
91
92
    public function getFaz(): ?ServiceExample
93
    {
94
        return $this->faz;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->faz returns the type string which is incompatible with the type-hinted return Addiks\RDMBundle\Tests\H...ion\ServiceExample|null.
Loading history...
95
    }
96
97
    public function getBoo()
98
    {
99
        return $this->boo;
100
    }
101
102
}
103