Completed
Push — master ( f496a8...4f1947 )
by Sebastien
03:00 queued 01:27
created

Car::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace Khepin\Fixture\Document;
4
5
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
6
7
/**
8
 * @ODM\Document
9
 */
10
class Car
11
{
12
    /**
13
     * @ODM\Id
14
     */
15
    private $id;
16
17
    /**
18
     * @ODM\String
19
     */
20
    private $name;
21
22
    /**
23
     * @ODM\Date
24
     * @var type
25
     */
26
    private $date_purchased;
27
28
    /**
29
     * @param string $name
30
     * @param \DateTime $date_purchased
31
     */
32
    public function __construct($name = null, \DateTime $date_purchased = null)
33
    {
34
        $this->name = $name;
35
        $this->date_purchased = $date_purchased;
0 ignored issues
show
Documentation Bug introduced by
It seems like $date_purchased can also be of type object<DateTime>. However, the property $date_purchased is declared as type object<Khepin\Fixture\Document\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...
36
    }
37
38
    public function getId()
39
    {
40
        return $this->id;
41
    }
42
43
    public function getName()
44
    {
45
        return $this->name;
46
    }
47
48
    public function setName($name)
49
    {
50
        $this->name = $name;
51
    }
52
53
    public function getDatePurchased()
54
    {
55
        return $this->date_purchased;
56
    }
57
58
    public function setDatePurchased(\DateTime $date_purchased)
59
    {
60
        $this->date_purchased = $date_purchased;
0 ignored issues
show
Documentation Bug introduced by
It seems like $date_purchased of type object<DateTime> is incompatible with the declared type object<Khepin\Fixture\Document\type> of property $date_purchased.

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...
61
    }
62
}
63