Evenement::getDate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace SDIS62\Core\Ops\Entity;
4
5
use Datetime;
6
use SDIS62\Core\Common\Entity\IdentityTrait;
7
8
class Evenement
9
{
10
    use IdentityTrait;
11
12
    /**
13
     * Date de l'évenement.
14
     *
15
     * @var Datetime|null
16
     */
17
    protected $date;
18
19
    /**
20
     * Description de l'évenement.
21
     *
22
     * @var string
23
     */
24
    protected $description;
25
26
    /**
27
     * Ajout d'un evenement à une intervention.
28
     *
29
     * @param SDIS62\Core\Ops\Entity\Intervention $intervention
0 ignored issues
show
Bug introduced by
There is no parameter named $intervention. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
30
     * @param string                              $description
31
     * @param Datetime|string|null                $date         Optionnel
32
     */
33
    public function __construct($description, $date = null)
34
    {
35
        if ($date instanceof Datetime) {
36
            $this->date = $date;
37
        } elseif ($date === null) {
38
            $this->date = new Datetime('NOW');
39
        } else {
40
            $this->date = DateTime::createFromFormat('d-m-Y H:i:s', (string) $date);
0 ignored issues
show
Documentation Bug introduced by
It seems like \Datetime::createFromFor...H:i:s', (string) $date) can also be of type false. However, the property $date is declared as type object<DateTime>|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...
41
        }
42
43
        $this->description = $description;
44
    }
45
46
    /**
47
     * Get the value of Date de l'évenement.
48
     *
49
     * @return Datetime|null
50
     */
51
    public function getDate()
52
    {
53
        return $this->date;
54
    }
55
56
    /**
57
     * Get the value of Description de l'évenement.
58
     *
59
     * @return string
60
     */
61
    public function getDescription()
62
    {
63
        return $this->description;
64
    }
65
}
66