Passed
Push — master ( 565c26...461f06 )
by Aleksei
02:34
created

State   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 17
c 1
b 0
f 0
dl 0
loc 90
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getTimeCreated() 0 3 1
A withStatus() 0 7 1
A getTimeExecuted() 0 3 1
A __construct() 0 10 1
A getStatus() 0 3 1
A getName() 0 3 1
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license MIT
7
 * @author  Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Cycle\Migrations\Migration;
13
14
/**
15
 * Migration meta information specific to current environment.
16
 *
17
 * @psalm-import-type StatusEnum from Status
18
 *
19
 * @internal State is an internal library class, please do not use it in your code.
20
 * @psalm-internal Cycle\Migrations
21
 */
22
class State
23
{
24
    /**
25
     * @var non-empty-string
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
26
     */
27
    private $name;
28
29
    /**
30
     * @var StatusEnum
0 ignored issues
show
Bug introduced by
The type Cycle\Migrations\Migration\StatusEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
     */
32
    private $status;
33
34
    /**
35
     * @var \DateTimeInterface
36
     */
37
    private $createdAt;
38
39
    /**
40
     * @var \DateTimeInterface|null
41
     */
42
    private $executedAt;
43
44
    /**
45
     * @param non-empty-string $name
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
46
     * @param \DateTimeInterface $createdAt
47
     * @param StatusEnum $status
48
     * @param \DateTimeInterface|null $executedAt
49
     */
50
    public function __construct(
51
        string $name,
52
        \DateTimeInterface $createdAt,
53
        int $status = Status::STATUS_UNDEFINED,
54
        \DateTimeInterface $executedAt = null
55
    ) {
56
        $this->name = $name;
57
        $this->status = $status;
0 ignored issues
show
Documentation Bug introduced by
It seems like $status can also be of type integer. However, the property $status is declared as type Cycle\Migrations\Migration\StatusEnum. 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...
58
        $this->createdAt = $createdAt;
59
        $this->executedAt = $executedAt;
60
    }
61
62
    /**
63
     * @return string
64
     */
65
    public function getName(): string
66
    {
67
        return $this->name;
68
    }
69
70
    /**
71
     * Migration status.
72
     *
73
     * @return int
74
     */
75
    public function getStatus(): int
76
    {
77
        return $this->status;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->status returns the type Cycle\Migrations\Migration\StatusEnum which is incompatible with the type-hinted return integer.
Loading history...
78
    }
79
80
    /**
81
     * Get migration creation time.
82
     *
83
     * @return \DateTimeInterface
84
     */
85
    public function getTimeCreated(): \DateTimeInterface
86
    {
87
        return $this->createdAt;
88
    }
89
90
    /**
91
     * Get migration execution time if any.
92
     *
93
     * @return \DateTimeInterface|null
94
     */
95
    public function getTimeExecuted(): ?\DateTimeInterface
96
    {
97
        return $this->executedAt;
98
    }
99
100
    /**
101
     * @param StatusEnum $status
102
     * @param \DateTimeInterface|null $executedAt
103
     * @return State
104
     */
105
    public function withStatus(int $status, \DateTimeInterface $executedAt = null): State
106
    {
107
        $state = clone $this;
108
        $state->status = $status;
0 ignored issues
show
Documentation Bug introduced by
It seems like $status of type integer is incompatible with the declared type Cycle\Migrations\Migration\StatusEnum of property $status.

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...
109
        $state->executedAt = $executedAt;
110
111
        return $state;
112
    }
113
}
114