Passed
Push — master ( bba5a4...181b61 )
by Tom
03:44
created

StepServices::parseServices()   A

Complexity

Conditions 5
Paths 10

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 5
eloc 8
c 1
b 0
f 1
nc 10
nop 1
dl 0
loc 16
ccs 9
cts 9
cp 1
crap 5
rs 9.6111
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\File;
6
7
/**
8
 * Class StepServices
9
 *
10
 * Services entry in a step
11
 *
12
 * @package Ktomk\Pipelines\File\File
13
 */
14
class StepServices
15
{
16
    /**
17
     * @var Step
18
     */
19
    private $step;
20
21
    /**
22
     * @var array
23
     */
24
    private $services;
25
26 4
    public function __construct(Step $step, $services)
27
    {
28
        // quick validation: script
29 4
        $parsed = $this->parseServices($services);
30
31 2
        $this->step = $step;
32 2
        $this->services = array_flip($parsed);
33 2
    }
34
35
    /**
36
     * @param string $service
37
     * @return bool
38
     */
39 1
    public function has($service)
40
    {
41 1
        return is_string($service) ? isset($this->services[$service]) : false;
0 ignored issues
show
introduced by
The condition is_string($service) is always true.
Loading history...
42
    }
43
44 4
    private function parseServices($services)
45
    {
46 4
        if (!is_array($services)) {
47 1
            ParseException::__("'services' requires a list of services");
48
        }
49
50 3
        $reservoir = array();
51 3
        foreach ($services as $service) {
52 2
            if (!is_string($service)) {
53 1
                ParseException::__("'services' service name string expected");
54
            }
55
56 2
            '' === ($service = trim($service)) || $reservoir[] = $service;
57
         }
58
59 2
        return $reservoir;
60
    }
61
}
62