Completed
Pull Request — master (#133)
by Damian
20:49 queued 18:16
created

MigrationDefinition::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 8
cts 8
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 6
crap 2
1
<?php
2
3
namespace Kaliop\eZMigrationBundle\API\Value;
4
5
use Kaliop\eZMigrationBundle\API\Collection\MigrationStepsCollection;
6
7
/**
8
 * @property-read string $name
9
 * @property-read string $path
10
 * @property-read string $rawDefinition
11
 * @property-read integer $status
12
 * @property-read MigrationStepsCollection $steps
13
 * @property-read string $parsingError
14
 */
15
class MigrationDefinition extends AbstractValue
16
{
17
    const STATUS_TO_PARSE = 0;
18
    const STATUS_PARSED = 1;
19
    const STATUS_INVALID = 2;
20
21
    protected $name;
22
    protected $path;
23
    protected $rawDefinition;
24
    protected $status = 0;
25
    protected $steps;
26
    protected $parsingError;
27
28
    /**
29
     * @param string $name
30
     * @param string $path
31
     * @param string $rawDefinition
32
     * @param int $status
33
     * @param MigrationStep[]|MigrationStepsCollection $steps
34
     * @param string $parsingError
35
     */
36 70
    public function __construct($name, $path, $rawDefinition, $status = 0, $steps = array(), $parsingError = null)
37
    {
38 70
        $this->name = $name;
39 70
        $this->path = $path;
40 70
        $this->rawDefinition = $rawDefinition;
41 70
        $this->status = $status;
42 70
        $this->steps = ($steps instanceof MigrationStepsCollection) ? $steps : new MigrationStepsCollection($steps);
43 70
        $this->parsingError = $parsingError;
44 70
    }
45
46
    /**
47
     * Allow the class to be serialized to php using var_export
48
     * @param array $data
49
     * @return static
50
     */
51
    public static function __set_state(array $data)
52
    {
53
        return new static(
54
            $data['name'],
55
            $data['path'],
56
            $data['rawDefinition'],
57
            $data['status'],
58
            $data['steps'],
59
            $data['parsingError']
60
        );
61
    }
62
}
63