Passed
Push — steps ( 2bf0cd...c7b5f4 )
by Tom
04:13
created

Pipeline::step()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\File;
6
7
use Ktomk\Pipelines\File\Pipeline\Step;
8
use Ktomk\Pipelines\File\Pipeline\Steps;
9
10
class Pipeline
11
{
12
    /**
13
     * @var File
14
     */
15
    private $file;
16
17
    /**
18
     * @var Steps
19
     */
20
    private $steps;
21
22
    /**
23
     * Pipeline constructor.
24
     * @param File $file
25
     * @param array $definition
26
     * @throws \Ktomk\Pipelines\File\ParseException
27
     */
28 5
    public function __construct(File $file, array $definition)
29
    {
30
        // quick validation
31 5
        if (!isset($definition[0])) {
32 1
            ParseException::__('Pipeline requires a list of steps');
33
        }
34
35 5
        $this->file = $file;
36 5
        $this->steps = new Steps($this, $definition);
37 4
    }
38
39
    /**
40
     * @return File
41
     */
42 2
    public function getFile()
43
    {
44 2
        return $this->file;
45
    }
46
47
    /**
48
     * get id of pipeline within the corresponding file object
49
     *
50
     * @return null|string id, can be null in fake/test conditions
51
     */
52 1
    public function getId()
53
    {
54 1
        return $this->file->getIdFrom($this);
55
    }
56
57
    /**
58
     * @return Step[]|Steps
59
     */
60 1
    public function getSteps()
61
    {
62 1
        return $this->steps;
63
    }
64
65
    /**
66
     * Specify data which should be serialized to JSON
67
     *
68
     * @return array
69
     * @since 5.4.0
70
     */
71 1
    public function jsonSerialize()
72
    {
73 1
        return $this->steps->jsonSerialize();
74
    }
75
}
76