Completed
Pull Request — master (#6)
by steef
08:13
created

LiberationDay   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 13 2
1
<?php
2
3
namespace Stefanius\SpecialDates\CommonDates;
4
5
use Stefanius\SpecialDates\SDK\AbstractSpecialDate;
6
7
class LiberationDay extends AbstractSpecialDate
8
{
9
    protected function generate()
10
    {
11
        $this->description = 'Bevrijdingsdag';
12
13
        if ($this->year > 1945) {
14
            $this->startDate   = \DateTime::createFromFormat('Y-m-d', $this->year . '-5-5');
0 ignored issues
show
Documentation Bug introduced by
It seems like \DateTime::createFromFor..., $this->year . '-5-5') can also be of type false. However, the property $startDate is declared as type object<DateTime>. 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...
15
            $this->endDate     = \DateTime::createFromFormat('Y-m-d', $this->year . '-5-5');
0 ignored issues
show
Documentation Bug introduced by
It seems like \DateTime::createFromFor..., $this->year . '-5-5') can also be of type false. However, the property $endDate is declared as type object<DateTime>. 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...
16
            $this->totalLength = 1;
17
            $this->valid = true;
18
        } else {
19
            $this->valid = false;
20
        }
21
    }
22
}
23