Passed
Push — test ( 1f6f72...276f1a )
by Tom
02:41
created

Service::parse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 4
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 10
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\File\Definitions;
6
7
use Ktomk\Pipelines\File\Image;
8
use Ktomk\Pipelines\File\ParseException;
9
10
class Service
11
{
12
    /**
13
     * @var array
14
     */
15
    private $array;
16
17
    /**
18
     * @var string
19
     */
20
    private $name;
21
22
    /**
23
     * @var Image
24
     */
25
    private $image;
26
27
    /**
28
     * Service constructor.
29
     *
30
     * @param string $name
31
     * @param array $array
32
     */
33 2
    public function __construct($name, array $array)
34
    {
35 2
        $this->name = (string)$name;
36 2
        $this->parse($array);
37 1
        $this->array = $array;
38 1
    }
39
40
    /**
41
     * @return Image
42
     */
43 1
    public function getImage()
44
    {
45 1
        return $this->image;
46
    }
47
48
    /**
49
     * @return string
50
     */
51 1
    public function getName()
52
    {
53 1
        return $this->name;
54
    }
55
56 2
    private function parse(array $array)
57
    {
58 2
        if (!isset($array['image'])) {
59 1
            throw new ParseException("'image' required in service definition");
60
        }
61 1
        Image::validate($array);
62
63 1
        $this->image = new Image($array['image']);
64 1
    }
65
}
66